|
@@ -1,17 +1,13 @@
|
|
import { App, Config, Inject, Middleware } from '@midwayjs/decorator';
|
|
import { App, Config, Inject, Middleware } from '@midwayjs/decorator';
|
|
import { CoolUrlTagData } from '@cool-midway/core';
|
|
import { CoolUrlTagData } from '@cool-midway/core';
|
|
import { NextFunction, Context } from '@midwayjs/koa';
|
|
import { NextFunction, Context } from '@midwayjs/koa';
|
|
-import {
|
|
|
|
- IMiddleware,
|
|
|
|
- IMidwayApplication,
|
|
|
|
- InjectClient,
|
|
|
|
-} from '@midwayjs/core';
|
|
|
|
|
|
+import { IMiddleware, IMidwayApplication, InjectClient } from '@midwayjs/core';
|
|
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
|
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
|
import * as crypto from 'crypto';
|
|
import * as crypto from 'crypto';
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
import { MerchantEntity } from '../../payment/entity/merchant';
|
|
import { MerchantEntity } from '../../payment/entity/merchant';
|
|
import { Repository } from 'typeorm';
|
|
import { Repository } from 'typeorm';
|
|
-import {CustomerEntity} from "../../payment/entity/customer";
|
|
|
|
|
|
+import { CustomerEntity } from '../../payment/entity/customer';
|
|
|
|
|
|
/**
|
|
/**
|
|
* 签名验证
|
|
* 签名验证
|
|
@@ -45,10 +41,10 @@ export class BaseAuthorityMiddleware
|
|
|
|
|
|
resolve() {
|
|
resolve() {
|
|
return async (ctx: Context, next: NextFunction) => {
|
|
return async (ctx: Context, next: NextFunction) => {
|
|
- if(ctx.url.includes('/api/open/')) {
|
|
|
|
- await next();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ // if (ctx.url.includes('/api/open/')) {
|
|
|
|
+ // await next();
|
|
|
|
+ // return;
|
|
|
|
+ // }
|
|
// 签名校验
|
|
// 签名校验
|
|
let { header } = ctx;
|
|
let { header } = ctx;
|
|
const {
|
|
const {
|
|
@@ -57,8 +53,11 @@ export class BaseAuthorityMiddleware
|
|
'fusionpay-nonce': vaNonce = '',
|
|
'fusionpay-nonce': vaNonce = '',
|
|
'fusionpay-sign': vaSign = '',
|
|
'fusionpay-sign': vaSign = '',
|
|
} = header;
|
|
} = header;
|
|
|
|
+
|
|
const params =
|
|
const params =
|
|
- ctx?.req.method === 'GET' ? /* ctx?.request.query */ '' : ctx?.request.body;
|
|
|
|
|
|
+ ctx?.req.method === 'GET'
|
|
|
|
+ ? /* ctx?.request.query */ ''
|
|
|
|
+ : ctx?.request.body;
|
|
const merchantInfo = await this.merchantEntity.findOne({
|
|
const merchantInfo = await this.merchantEntity.findOne({
|
|
where: {
|
|
where: {
|
|
apiSecret: `${vaKey}`,
|
|
apiSecret: `${vaKey}`,
|
|
@@ -67,9 +66,9 @@ export class BaseAuthorityMiddleware
|
|
let customer = await this.customerEntity.findOne({
|
|
let customer = await this.customerEntity.findOne({
|
|
where: {
|
|
where: {
|
|
merchantId: merchantInfo.mchId,
|
|
merchantId: merchantInfo.mchId,
|
|
- out_user_id: null
|
|
|
|
|
|
+ out_user_id: null,
|
|
},
|
|
},
|
|
- })
|
|
|
|
|
|
+ });
|
|
// TODO 后续在中间件加入对指定用户的权限验证
|
|
// TODO 后续在中间件加入对指定用户的权限验证
|
|
// let merchantCustomer = ''
|
|
// let merchantCustomer = ''
|
|
|
|
|
|
@@ -86,7 +85,7 @@ export class BaseAuthorityMiddleware
|
|
if (merchantInfo?.status != 1 && !message) {
|
|
if (merchantInfo?.status != 1 && !message) {
|
|
message = '当前商户已锁定';
|
|
message = '当前商户已锁定';
|
|
}
|
|
}
|
|
- if (!customer && !message) {
|
|
|
|
|
|
+ if (!customer && !message && !ctx.url.includes('/api/open/')) {
|
|
message = '当前商户暂无认证';
|
|
message = '当前商户暂无认证';
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,7 +103,7 @@ export class BaseAuthorityMiddleware
|
|
if (customer?.status === 'CLOSED' && !message) {
|
|
if (customer?.status === 'CLOSED' && !message) {
|
|
message = '当前商户认证资格被回收';
|
|
message = '当前商户认证资格被回收';
|
|
}*/
|
|
}*/
|
|
- if(message) {
|
|
|
|
|
|
+ if (message) {
|
|
ctx.status = 401;
|
|
ctx.status = 401;
|
|
ctx.body = {
|
|
ctx.body = {
|
|
code: ctx.status,
|
|
code: ctx.status,
|