Procházet zdrojové kódy

feat: eaypay代理添加鉴权

max před 5 měsíci
rodič
revize
91baf51a2b
1 změnil soubory, kde provedl 14 přidání a 15 odebrání
  1. 14 15
      src/modules/api/middleware/authority.ts

+ 14 - 15
src/modules/api/middleware/authority.ts

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