Przeglądaj źródła

change: 优化openapi接口逻辑

max 7 miesięcy temu
rodzic
commit
e99515da34

+ 7 - 7
src/config/config.max.ts

@@ -9,14 +9,14 @@ export default {
     dataSource: {
       default: {
         type: 'mysql',
-        host: '192.168.2.101',
-        port: 6806,
-        username: 'root',
-        password: 'admin',
-        // host: '127.0.0.1',
-        // port: 3306,
+        // host: '192.168.2.101',
+        // port: 6806,
         // username: 'root',
-        // password: '12345678',
+        // password: 'admin',
+        host: '127.0.0.1',
+        port: 3306,
+        username: 'root',
+        password: '12345678',
         database: 'va',
         // 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
         synchronize: true,

+ 1 - 1
src/modules/api/config.ts

@@ -12,7 +12,7 @@ export default () => {
     // 模块描述
     description: '所有对外露出的接口',
     // 中间件
-    // TODO globalMiddlewares: [BaseAuthorityMiddleware],
+    globalMiddlewares: [BaseAuthorityMiddleware],
     // 模块加载顺序,默认为0,值越大越优先加载
     order: 0,
     // app参数配置允许读取的key

+ 20 - 34
src/modules/api/controller/associateBankAccount.ts

@@ -36,21 +36,14 @@ export class AssociateBankAccountController extends BaseController {
     // 数据落库
     // 回调
     console.log('AssociateBankAccountRequiredFieldsAsync-=-=-',currency);
-    return this.ok(await this.associateBankAccount.associateBankAccountRequiredFieldsAsync(currency));
+    return await this.associateBankAccount.associateBankAccountRequiredFieldsAsync(currency);
   }
   /**
    * 关联银行账户
    */
   @Post('/AssociateBankAccount', { summary: '关联银行账户' })
   async AssociateBankAccount(@Body(ALL) business: BusinessEntity) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log('associateBankAccount-=-=',business);
-    return this.ok(await this.associateBankAccount.associateBankAccount(business));
+    return await this.associateBankAccount.associateBankAccount(business);
   }
   /**
    * 获取银行账户信息
@@ -61,34 +54,27 @@ export class AssociateBankAccountController extends BaseController {
     @Query('currency') currency: string,
     @Query('customer_id') customer_id: string,
   ) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
     const business = {
       currency: currency,
       customer_id: customer_id,
     }
-    console.log('GetAssociateBankAccounts-=-=-=',business);
-    return this.ok(await this.associateBankAccount.getAssociateBankAccounts(business));
-  }
-  /**
-   * TODO 关联银行账户回调通知
-   *
-   */
-  @Put('/AssociateBankAccounts/callback', {
-    summary: '关联银行账户回调通知',
-  })
-  async createCustomerCallback(@Body(ALL) business: BusinessEntity) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    return await this.associateBankAccount.getAssociateBankAccounts(business);
   }
+  // /**
+  //  * TODO 关联银行账户回调通知
+  //  *
+  //  */
+  // @Put('/AssociateBankAccounts/callback', {
+  //   summary: '关联银行账户回调通知',
+  // })
+  // async createCustomerCallback(@Body(ALL) business: BusinessEntity) {
+  //   // if (!this.allowKeys.includes(key)) {
+  //   //   return this.fail('非法操作');
+  //   // }
+  //   // 关键参数校验
+  //   // 数据落库
+  //   // 回调
+  //   console.log(business);
+  //   return this.ok('hello, cool-admin!!!');
+  // }
 }

+ 1 - 1
src/modules/api/controller/banks.ts

@@ -16,7 +16,7 @@ export class BanksController extends BaseController {
    * /api/v3/Fiat/Banks
    */
   @Get('/Banks', { summary: '获取银行列表' })
-  async getBanks(@Body(ALL) params: any) {
+  async getBanks(@Query(ALL) params: any) {
     return await this.sunPayAdapter.getBanks(params)
   }
 }

+ 5 - 7
src/modules/api/controller/beneficiary.ts

@@ -37,14 +37,14 @@ export class BeneficiaryController extends BaseController {
   @Post('/Beneficiary', { summary: '创建受益人' })
   async createCustomer(@Body(ALL) params: any) {
     this.payeeService.setIsOpenApi(true);
-    return this.ok(await this.payeeService.add(params));
+    return await this.payeeService.add(params);
   }
   /**
    * 获取受益人
    */
   @Get('/Beneficiary/:id', { summary: '获取受益人' })
   async beneficiaryForId(@Param('id') id: string) {
-    return this.ok(this.beneficiaryService.info(id));
+    return await this.beneficiaryService.info(id);
   }
   /**
    * 获取受益人列表
@@ -53,15 +53,14 @@ export class BeneficiaryController extends BaseController {
   @Get('/Beneficiary', { summary: '获取受益人列表' })
   async getBeneficiary(@Query('customer_id') customerId: string,) {
     this.payeeService.setIsOpenApi(true);
-    return this.ok(await this.beneficiaryService.getBeneficiaryList(customerId));
+    return await this.beneficiaryService.getBeneficiaryList(customerId);
   }
   /**
    * 修改受益人
    */
   @Put('/Beneficiary', { summary: '修改受益人' })
   async updateBeneficiary(@Body(ALL) params: BusinessEntity) {
-    this.payeeService.setIsOpenApi(true);
-    return this.ok(await this.payeeService.update(params));
+    return await this.payeeService.update(params);
   }
   /**
    * 删除受益人
@@ -69,7 +68,6 @@ export class BeneficiaryController extends BaseController {
    */
   @Del('/Beneficiary', { summary: '删除受益人' })
   async deleteBeneficiaryForId(@Body(ALL) params: BusinessEntity) {
-    this.payeeService.setIsOpenApi(true);
-    return this.ok(await this.payeeService.delete(params));
+    return await this.payeeService.delete(params);
   }
 }

+ 24 - 36
src/modules/api/controller/beneficiaryAddress.ts

@@ -14,6 +14,7 @@ import {
 import { BusinessEntity } from '../../payment/entity/business';
 import { PayeeAddressService } from '../../payment/service/payee_address';
 import { BeneficiaryAddressService } from '../service/beneficiaryAddress';
+import {SunPayAdapter} from "../../payment/adapter/sunpay.adapter";
 
 /**
  * 受益人地址
@@ -27,50 +28,39 @@ export class BeneficiaryAddressController extends BaseController {
   @Inject()
   beneficiaryAddressService: BeneficiaryAddressService;
 
+  @Inject()
+  sunPayAdapter: SunPayAdapter;
+
   /**
    * 创建受益人地址
    * /api/v3/Fiat/BeneficiaryAddress
    */
   @Post('/BeneficiaryAddress', { summary: '创建受益人地址' })
   async createBeneficiaryAddress(@Body(ALL) params: BusinessEntity) {
-    return this.ok(await this.payeeAddressService.add(params));
+    return await this.payeeAddressService.add(params);
   }
   /**
    * 获取受益人地址必填字段
    * /api/v3/Fiat/BeneficiaryAddressRequiredFields
    */
-  // @Get('/BeneficiaryAddressRequiredFields', {
-  //   summary: '获取受益人地址必填字段',
-  // })
-  // async getBeneficiaryAddressRequiredFields(
-  //   @Body(ALL) business: BusinessEntity
-  // ) {
-  //   // if (!this.allowKeys.includes(key)) {
-  //   //   return this.fail('非法操作');
-  //   // }
-  //   // 关键参数校验
-  //   // 数据落库
-  //   // 回调
-  //   console.log(business);
-  //   return this.ok('hello, cool-admin!!!');
-  // }
+  @Get('/BeneficiaryAddressRequiredFields', {
+    summary: '获取受益人地址必填字段',
+  })
+  async getBeneficiaryAddressRequiredFields(
+    @Query(ALL) params: any
+  ) {
+    return await this.sunPayAdapter.getBeneficiaryAddressRequiredFields(params)
+  }
   /**
    * 验证受益人地址必填字段
    * /api/v3/Fiat/BeneficiaryAddress/Validate
    */
-  // @Post('/BeneficiaryAddress/Validate', {
-  //   summary: '验证受益人地址必填字段',
-  // })
-  // async BeneficiaryAddressValidate(@Body(ALL) business: BusinessEntity) {
-  //   // if (!this.allowKeys.includes(key)) {
-  //   //   return this.fail('非法操作');
-  //   // }
-  //   // 关键参数校验
-  //   // 数据落库
-  //   // 回调
-  //   console.log(business);
-  //   return this.ok('hello, cool-admin!!!');
-  // }
+  @Post('/BeneficiaryAddress/Validate', {
+    summary: '验证受益人地址必填字段',
+  })
+  async BeneficiaryAddressValidate(@Body(ALL) params: any) {
+    return await this.sunPayAdapter.validateBeneficiaryAddress(params)
+  }
   /**
    * 修改受益人地址
    * /api/v3/Fiat/BeneficiaryAddress
@@ -79,7 +69,7 @@ export class BeneficiaryAddressController extends BaseController {
     summary: '修改受益人地址',
   })
   async updateBeneficiaryAddress(@Body(ALL) params: BusinessEntity) {
-    return this.ok(await this.payeeAddressService.update(params));
+    return await this.payeeAddressService.update(params);
   }
   /**
    * 获取受益人地址
@@ -89,7 +79,7 @@ export class BeneficiaryAddressController extends BaseController {
     summary: '获取受益人地址',
   })
   async getBeneficiaryAddressForId(@Param('id') id: string) {
-    return this.ok(await this.beneficiaryAddressService.info(id));
+    return await this.beneficiaryAddressService.info(id);
   }
   /**
    * 获取受益人地址列表
@@ -134,10 +124,8 @@ export class BeneficiaryAddressController extends BaseController {
     summary: '删除受益人地址',
   })
   async deleteBeneficiaryAddressForId(@Body(ALL) business: BusinessEntity) {
-    return this.ok(
-      await this.payeeAddressService.delete({
-        id: business.id,
-      })
-    );
+    return await this.payeeAddressService.delete({
+      id: business.id,
+    });
   }
 }

+ 19 - 18
src/modules/api/controller/customer.ts

@@ -6,12 +6,13 @@ import {
   Inject,
   Post,
   Provide,
-  Put,
+  Put, Query,
 } from '@midwayjs/decorator';
 import { IndividualEntity } from '../../payment/entity/individual';
 import { CustomerService } from '../service/customer';
 import {SunPayAdapter} from "../../payment/adapter/sunpay.adapter";
 import {IndividualService} from "../../payment/service/individual";
+import {CustomerEntity} from "../../payment/entity/customer";
 
 /**
  * 客户管理
@@ -29,29 +30,29 @@ export class CustomerController extends BaseController {
    */
   @Post('/CreateCustomer', { summary: '创建客户' })
   async createCustomer(@Body() params: IndividualEntity) {
-    return this.ok(await this.customerService.createCustomer(params));
+    return await this.customerService.createCustomer(params);
   }
 
 
   @Post('/add-individual', { summary: '创建客户' })
   async addIndividual(@Body() params: IndividualEntity) {
-    return this.ok(await this.customerService.addIndividual(params));
+    return await this.customerService.addIndividual(params);
+  }
+  /**
+   * 获取创建客户必填字段
+   */
+  @Get('/CustomerRequiredFields', { summary: '获取创建客户必填字段' })
+  async getCustomerRequiredFields(@Query(ALL) params: any) {
+    return await this.sunPayAdapter.getCustomerRequiredFields(params);
+  }
+  /**
+   * 验证客户必填字段
+   * /api/v3/Fiat/Customer/Validate
+   */
+  @Post('/Customer/Validate', { summary: '验证客户必填字段' })
+  async param(@Body(ALL) params: any) {
+    return await this.sunPayAdapter.checkCustomerInfo(params);
   }
-  // /**
-  //  * 获取创建客户必填字段
-  //  */
-  // @Get('/CustomerRequiredFields', { summary: '获取创建客户必填字段' })
-  // async getCustomerRequiredFields(@Body(ALL) params: any) {
-  //   return this.ok(await this.sunPayAdapter.validateCustomerInfo(params));
-  // }
-  // /**
-  //  * 验证客户必填字段
-  //  * /api/v3/Fiat/Customer/Validate
-  //  */
-  // @Post('/Customer/Validate', { summary: '验证客户必填字段' })
-  // async param(@Body(ALL) params: any) {
-  //   return this.ok(await this.sunPayAdapter.validateCustomerInfo(params));
-  // }
   /**
    * 修改客户
    * /api/v3/Fiat/Customer

+ 3 - 17
src/modules/api/controller/payIn.ts

@@ -24,7 +24,7 @@ export class PayInController extends BaseController {
     // 数据落库
     // 回调
     console.log('createPayInOrder-=-=payIn-=-=000',business);
-    return this.ok(await this.orderService.recharge(business));
+    return await this.orderService.recharge(business);
   }
   /**
    * 查询订单
@@ -32,14 +32,7 @@ export class PayInController extends BaseController {
    */
   @Get('/PayIn/', { summary: '查询订单' })
   async getPayInForOrderNo(@Query('orderNo') orderNo: string,) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log('getPayInForOrderNo-=-=-=-111',orderNo);
-    return this.ok(await this.orderService.rechargeOrder({ orderNo: orderNo,channel:'SUNPAY'}));
+    return await this.orderService.rechargeOrder({ orderNo: orderNo,channel:'SUNPAY'});
   }
   /**
    * 取消订单
@@ -47,13 +40,6 @@ export class PayInController extends BaseController {
    */
   @Post('/PayIn/:orderNo/Cancel', { summary: '取消订单' })
   async cancelPayInOrderForOrderNo(@Param('orderNo') orderNo: string) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log('cancelPayInOrderForOrderNo-=-=-=111',orderNo);
-    return this.ok(await this.orderService.rechargeOrderCancel({orderNo:orderNo}));
+    return await this.orderService.rechargeOrderCancel({orderNo:orderNo});
   }
 }

+ 4 - 4
src/modules/api/controller/payOut.ts

@@ -18,7 +18,7 @@ export class CustomerController extends BaseController {
    */
   @Post('/PayOut', { summary: '创建订单' })
   async createPayOutOrder(@Body(ALL) paramas: OrderEntity) {
-    return this.ok(await this.orderService.openApiCreatePayOut(paramas));
+    return await this.orderService.openApiCreatePayOut(paramas);
   }
   /**
    * 查询订单
@@ -26,7 +26,7 @@ export class CustomerController extends BaseController {
    */
   @Get('/PayOut/:orderNo', { summary: '查询订单' })
   async PayOutOutForOrderNo(@Param('orderNo') orderNo: string) {
-    return this.ok(await this.orderService.openApiPatOutInfo(orderNo));
+    return await this.orderService.openApiPatOutInfo(orderNo);
   }
   /**
    * 取消订单
@@ -34,7 +34,7 @@ export class CustomerController extends BaseController {
    */
   @Post('/PayOut/:orderNo/Cancel', { summary: '取消订单' })
   async cancelPayOutOrderForOrderNo(@Param('orderNo') orderNo: string) {
-    return this.ok(await this.orderService.openApiCancel(orderNo));
+    return await this.orderService.openApiCancel(orderNo);
   }
   /**
    * 确认订单
@@ -42,6 +42,6 @@ export class CustomerController extends BaseController {
    */
   @Post('/PayOut/:orderNo/Confirm', { summary: '确认订单' })
   async confirmPayOutOrderForOrderNo(@Param('orderNo') orderNo: string) {
-    return this.ok(await this.orderService.openApiConfirm(orderNo));
+    return await this.orderService.openApiConfirm(orderNo);
   }
 }

+ 4 - 40
src/modules/api/controller/wallet.ts

@@ -17,29 +17,7 @@ export class WalletController extends BaseController {
    */
   @Post('/Wallet', { summary: '创建钱包' })
   async createWallet(@Body(ALL) business: BusinessEntity) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log(business);
-    return this.ok(await this.walletService.add(business));
-  }
-  /**
-   * TODO 创建钱包回调通知
-   *
-   */
-  @Post('/wallet/callback', { summary: '创建钱包回调通知' })
-  async createWalletCallback(@Body(ALL) business: BusinessEntity) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log(business);
-    return this.ok('hello, cool-admin!!!');
+    return await this.walletService.add(business);
   }
   /**
    * 获取钱包信息
@@ -47,14 +25,7 @@ export class WalletController extends BaseController {
    */
   @Get('/GetWalletAccounts', { summary: '获取钱包信息' })
   async GetWalletAccounts(@Query('customer_id') customer_id: string,) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log('GetWalletAccounts', customer_id);
-    return this.ok(await this.walletService.getWallet(customer_id));
+    return await this.walletService.getWallet(customer_id);
   }
 
   /**
@@ -64,16 +35,9 @@ export class WalletController extends BaseController {
   async AccountBalance(
     @Query('customer_id') customer_id: string,
     @Query('currency') currency: string,) {
-    // if (!this.allowKeys.includes(key)) {
-    //   return this.fail('非法操作');
-    // }
-    // 关键参数校验
-    // 数据落库
-    // 回调
-    console.log(customer_id,currency);
-    return this.ok(await this.walletService.getWalletBalance({
+    return await this.walletService.getWalletBalance({
       customer_id: customer_id,
       currency: currency
-    }));
+    });
   }
 }

+ 110 - 48
src/modules/api/middleware/authority.ts

@@ -4,15 +4,14 @@ import { NextFunction, Context } from '@midwayjs/koa';
 import {
   IMiddleware,
   IMidwayApplication,
-  Init,
   InjectClient,
 } from '@midwayjs/core';
 import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
-import { SunPayAdapter } from '../../payment/adapter/sunpay.adapter';
 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";
 
 /**
  * 签名验证
@@ -30,6 +29,9 @@ export class BaseAuthorityMiddleware
   @InjectClient(CachingFactory, 'default')
   midwayCache: MidwayCache;
 
+  @InjectEntityModel(CustomerEntity)
+  customerEntity: Repository<CustomerEntity>;
+
   @InjectEntityModel(MerchantEntity)
   merchantEntity: Repository<MerchantEntity>;
 
@@ -44,60 +46,121 @@ export class BaseAuthorityMiddleware
   resolve() {
     return async (ctx: Context, next: NextFunction) => {
       // 签名校验
-      let { header, url } = ctx;
-      const adminUrl = '/api/v1/';
-      // 路由地址为 api/v1 前缀的 需要权限校验
-      if (url.includes(adminUrl)) {
-        const {
-          'va-key': vaKey = '',
-          'va-timestamp': vaTimestamp = '',
-          'va-nonce': vaNonce = '',
-          'va-sign': vaSign = '',
-        } = header;
-        const params =
-          ctx?.req.method === 'GET' ? ctx?.request.query : ctx?.request.body;
-
-        const merchantInfo = await this.merchantEntity.findOne({
-          where: {
-            apiSecret: `${vaKey}`,
-          },
-        });
-
-        // 商户不存在或者说商户被禁用都提示失败
-        if (!merchantInfo || merchantInfo.status != 1) {
-          ctx.status = 401;
-          ctx.body = {
-            code: ctx.status,
-            message: '签名不匹配,认证失败',
-          };
-          return;
+      let { header } = ctx;
+      const {
+        'fusionpay-key': vaKey = '',
+        'fusionpay-timestamp': vaTimestamp = '',
+        'fusionpay-nonce': vaNonce = '',
+        'fusionpay-sign': vaSign = '',
+      } = header;
+      const params =
+        ctx?.req.method === 'GET' ? ctx?.request.query : ctx?.request.body;
+      const merchantInfo = await this.merchantEntity.findOne({
+        where: {
+          apiSecret: `${vaKey}`,
+        },
+      });
+      let customer = await this.customerEntity.findOne({
+        where: {
+          merchantId: merchantInfo.mchId,
+          out_user_id: null
+        },
+      })
+      // TODO 后续在中间件加入对指定用户的权限验证
+      // let merchantCustomer = ''
+
+      // 商户不存在或者说商户被禁用都提示失败
+      if (!merchantInfo || merchantInfo.status != 1 || !vaKey || !customer || customer.status !== 'ACTIVE') {
+        let message = '';
+        if (!vaKey) {
+          message = 'API Secret 不存在!';
+        }
+        if (!merchantInfo && !message) {
+          message = '当前商户不存在';
+        }
+        if (merchantInfo?.status != 1 && !message) {
+          message = '当前商户已锁定';
+        }
+        if (!customer && !message) {
+          message = '当前商户暂无认证';
+        }
+        if (!customer && !message) {
+          message = '当前商户暂无认证';
         }
 
-        // 2. 生成签名
-        const sign = this.generateSignature(
-          `${vaTimestamp}`,
-          `${vaNonce}`,
-          JSON.stringify(params),
-          `${vaKey}`
-        );
-        if (sign !== vaSign) {
-          ctx.status = 401;
-          ctx.body = {
-            code: ctx.status,
-            message: '签名不匹配,认证失败',
-          };
-          return;
+        if (customer?.status === 'PENDDING' && !message) {
+          message = '当前商户认证还在审核中';
         }
-        /*如果说商户没有认证,我们需要提示商户进行认证*/
-        ctx.admin.merchant = merchantInfo
-        ctx.admin.openApi = true
-        await next();
+
+        if (customer?.status === 'FAILED' && !message) {
+          message = '当前商户认证还在审核被驳回';
+        }
+
+        if (customer?.status === 'SUSPENDED' && !message) {
+          message = '当前商户认证资格被冻结';
+        }
+        if (customer?.status === 'CLOSED' && !message) {
+          message = '当前商户认证资格被回收';
+        }
+
+        if (!message) {
+          message = '签名不匹配,认证失败';
+        }
+
+        ctx.status = 401;
+        ctx.body = {
+          code: ctx.status,
+          message: message,
+        };
+        return;
+      }
+
+      // 2. 生成签名
+      const sign = this.generateSignature(
+        `${vaTimestamp}`,
+        `${vaNonce}`,
+        JSON.stringify(params),
+        `${vaKey}`
+      );
+
+      if (`${sign}`.toLocaleUpperCase() !== `${vaSign}`.toLocaleUpperCase()) {
+        ctx.status = 401;
+        ctx.body = {
+          code: ctx.status,
+          message: '签名不匹配,认证失败',
+        };
+        return;
       }
 
+      /*如果说商户没有认证,我们需要提示商户进行认证*/
+      // this.customerEntity
+      /*// TODO 本地测试用
+      const merchantInfo = await this.merchantEntity.findOne({
+        where: {
+          mchId: `ddddd`,
+        },
+      });*/
+
+      ctx.admin = {
+        ...ctx.admin,
+        merchant: merchantInfo,
+        openApi: true,
+      };
       await next();
     };
   }
 
+  match(ctx: Context): boolean {
+    // 下面的匹配到的路由会执行此中间件
+    if (ctx.url.includes('/api/v1/')) {
+      return true;
+    }
+  }
+
+  static getName(): string {
+    return 'openApi';
+  }
+
   /**
    * 生成签名
    * @see https://docs-merchant.sunpay.pro/guide
@@ -109,7 +172,6 @@ export class BaseAuthorityMiddleware
       .update(payload)
       .digest('hex')
       .toUpperCase();
-
     return signature;
   }
 }

+ 6 - 1
src/modules/api/service/customer.ts

@@ -5,6 +5,9 @@ import { BusinessService } from '../../payment/service/business';
 import { SunPayAdapter } from '../../payment/adapter/sunpay.adapter';
 import { IndividualService } from '../../payment/service/individual';
 import {CustomerEntity} from "../../payment/entity/customer";
+import {InjectEntityModel} from "@midwayjs/typeorm";
+import {BusinessEntity} from "../../payment/entity/business";
+import {Repository} from "typeorm";
 
 /**
  * 描述
@@ -13,8 +16,10 @@ import {CustomerEntity} from "../../payment/entity/customer";
 export class CustomerService extends BaseService {
   @Inject()
   sunPayAdapter: SunPayAdapter;
-  @Inject()
+
+  @InjectEntityModel(CustomerEntity)
   customerEntity: CustomerEntity;
+
   @Inject()
   businessService: BusinessService; // 公司
   @Inject()

+ 48 - 9
src/modules/payment/adapter/sunpay.adapter.ts

@@ -122,15 +122,13 @@ export class SunPayAdapter implements ChannelAdapter {
       // 检查响应
       if (response.data.code !== 200) {
         console.log(response.data);
-        // TODO 移除 SunPay API Error1
-        throw new Error(`FusionPay API Error: ${response.data.msg}`);
+        throw new Error(`FusionPay API ${response.data.msg}`);
       }
       return response.data;
     } catch (error) {
-      console.log(error);
+      // console.log(error.response.data);
       if (axios.isAxiosError(error) && error.response) {
-        // TODO 移除 SunPay API Error2
-        throw new Error(`FusionPay API Network Error: ${error.response.data.msg}`);
+        throw new Error(`FusionPay API Network ${error.response.data.msg}`);
       }
       throw error;
     }
@@ -185,18 +183,44 @@ export class SunPayAdapter implements ChannelAdapter {
   }
 
   /**
-   * 获取关联银行账户
+   * 获取关联银行账户必填字段
    * @param params
    * @returns
    */
   async associateBankAccountRequiredFieldsAsync(params: any): Promise<any> {
     console.log('associateBankAccountRequiredFieldsAsync-==-=-',params)
-    const res = await this.request(
+    return await this.request(
       'GET',
       '/Fiat/AssociateBankAccountRequiredFieldsAsync',
       params
     );
-    return res;
+  }
+  /**
+   * 获取受益人地址必填字段
+   * /api/v3/Fiat/BeneficiaryAddressRequiredFields
+   * @param params
+   * @returns
+   */
+  async getBeneficiaryAddressRequiredFields(params: any): Promise<any> {
+    return await this.request(
+      'GET',
+      '/Fiat/BeneficiaryAddressRequiredFields',
+      params
+    );
+  }
+
+  /**
+   * 验证受益人地址必填字段
+   * /api/v3/Fiat/BeneficiaryAddress/Validate
+   * @param params
+   * @returns
+   */
+  async validateBeneficiaryAddress(params: any): Promise<any> {
+    return await this.request(
+      'POST',
+      '/Fiat/BeneficiaryAddress/Validate',
+      params
+    );
   }
 
   /**
@@ -222,9 +246,24 @@ export class SunPayAdapter implements ChannelAdapter {
   async getWallet(params: any): Promise<any> {
     console.log('GetWalletAccounts-=-=-=',params)
     const res = await this.request('GET', '/Fiat/GetWalletAccounts', params);
-    console.log(res);
     return res;
   }
+   /**
+   * 获取创建客户必填字段
+    * /api/v3/Fiat/CustomerRequiredFields
+   * @param params
+   * @returns
+   */
+  async getCustomerRequiredFields(params: any): Promise<any> {
+    return await this.request('GET', '/Fiat/CustomerRequiredFields', params);
+  }
+  /**
+   * 验证用户信息
+   */
+  async checkCustomerInfo(params: CreateUserParams): Promise<void> {
+    return  await this.request('POST', '/Fiat/Customer/Validate', params);
+  }
+
    /**
    * 获取账户钱包币种余额信息
    * @param params

+ 6 - 6
src/modules/payment/service/wallet.ts

@@ -131,7 +131,8 @@ export class WalletService extends BaseService {
    */
   async getWallet(param: any) {
     console.log('getWallet',param)
-    const res = await this.paymentService.setChannel('SUNPAY').getWallet({//TODO setChannel 需要调整为动态的
+      // TODO setChannel 需要调整为动态的
+    const res = await this.paymentService.setChannel('SUNPAY').getWallet({
       customer_id: param,
     });
     return res;
@@ -140,12 +141,11 @@ export class WalletService extends BaseService {
   /**
    * 获取钱包币种余额
    */
-  async getWalletBalance(param: any) {
-    console.log('getWalletBalance',param)
-    const res = await this.paymentService.setChannel('SUNPAY').getWalletBalance({//TODO setChannel 需要调整为动态的
-      customer_id: param,
+  async getWalletBalance(params: any) {
+    // TODO setChannel 需要调整为动态的
+    return  await this.paymentService.setChannel('SUNPAY').getWalletBalance({
+      ...params
     });
-    return res;
   }
 
   async list(params: any, option: any, connectionName?: any) {