test 10 mēneši atpakaļ
vecāks
revīzija
fdcf53e533

+ 1 - 0
package.json

@@ -22,6 +22,7 @@
     "@midwayjs/upload": "^3.15.2",
     "@midwayjs/validate": "^3.15.2",
     "@midwayjs/view-ejs": "^3.15.2",
+    "@types/uuid": "^10.0.0",
     "alipay-sdk": "^4.11.0",
     "axios": "^1.6.7",
     "cache-manager-ioredis-yet": "^2.0.2",

+ 8 - 0
src/comm/utils.ts

@@ -229,4 +229,12 @@ export class Utils {
     // 生成哈希值
     return hmac.digest('hex');
   }
+
+  signByHmacSha1(data, secretKey) {
+    const hmac = crypto.createHmac('sha1', secretKey);
+    // 更新hash对象与传入的数据
+    hmac.update(data);
+    // 生成哈希值
+    return hmac.digest().toString('base64');
+  }
 }

+ 14 - 12
src/modules/dj/controller/admin/open.ts

@@ -75,24 +75,26 @@ export class PayOpenController extends BaseController {
   }
 
   @CoolTag(TagTypes.IGNORE_TOKEN)
-  @Post('/notifyOrder', { summary: '交易订单回调通知' })
-  public async notifyOrder(@Body(ALL) payload: any) {
-    const headers = this.ctx.req.headers;
-    this.logger.error('收到交易订单回调数据', JSON.stringify(payload), headers);
+  @Post('/SunCard/notifyOrder', { summary: '交易订单回调通知' })
+  public async notifySunCardOrderGet(@Body(ALL) payload: any) {
+    const headers = this.ctx.headers;
+    this.logger.error('SunCard收到交易订单回调数据', JSON.stringify(payload));
     await this.orderService.handleNotify('SunCard', payload, headers);
-    this.ctx.body = 'success';
+    this.ctx.body = {   
+      "is_success": "true",
+      "message": "success"
+    };
   }
 
   @CoolTag(TagTypes.IGNORE_TOKEN)
-  @Get('/SunCard/notifyOrder', { summary: '交易订单回调通知' })
-  public async notifyOrderGet() {
+  @Post('/hambit/notifyOrder', { summary: '交易订单回调通知' })
+  public async hambitNotifyOrderGet(@Body(ALL) payload: any) {
     const headers = this.ctx.req.headers;
-    const payload = this.ctx.query;
-    this.logger.error('收到交易订单回调数据', JSON.stringify(payload));
-    await this.orderService.handleNotify('SunCard', payload, headers);
+    this.logger.error('hambit收到交易订单回调数据', JSON.stringify(payload));
+    await this.orderService.handleNotify('HamBit', payload, headers);
     this.ctx.body = {   
-      "is_success": "true",
-      "message": "success"
+      "code": "200",
+      "success": "true"
     };
   }
 

+ 3 - 0
src/modules/dj/entity/order.ts

@@ -32,6 +32,9 @@ export class OrderEntity extends BaseEntity {
   @Column({ comment: '金额', type: 'decimal', precision: 10, scale: 2 })
   amount: number;
 
+  @Column({ comment: '货币单位' })
+  currency: string;
+  
   @Column({ comment: '通道手续费', type: 'decimal', precision: 10, scale: 2 })
   channelCharge: number;
 

+ 5 - 0
src/modules/dj/service/channels/dispatch.ts

@@ -2,6 +2,7 @@ import { Inject, Provide } from '@midwayjs/decorator';
 import { BaseService } from '@cool-midway/core';
 import { SunPayService } from './sunpay';
 import { ChannelService } from '../channel';
+import { HambitService } from './hambit';
 
 @Provide()
 export class DispatchService extends BaseService {
@@ -10,6 +11,10 @@ export class DispatchService extends BaseService {
 
   @Inject()
   channelService: ChannelService;
+  
+  @Inject()
+  hambitService: HambitService;
+
 
   async order(order, channel) {
     try {

+ 9 - 10
src/modules/dj/service/channels/sunpay.ts

@@ -167,7 +167,7 @@ export class SunPayService extends BaseService {
     const param = {
       out_order_no: payload.orderNo,
       customer_id: payload.customerId,
-      currency: 'USD',
+      currency: payload.currency,
       amount: +payload.amount,
       payment_type: "CARD",
       client_ip: payload.userIp || "127.0.0.0",
@@ -223,7 +223,7 @@ export class SunPayService extends BaseService {
     });
     this.logger.info('查询接口返回', JSON.stringify(res.data));
     const { is_success, msg } = res.data;
-    if (is_success && res.data.data.order_status === 'SUCCESS ') {
+    if (is_success && res.data.data.order_status === 'SUCCESS') {
       return {
         status: 1,
       };
@@ -237,12 +237,13 @@ export class SunPayService extends BaseService {
 
   async handleOrderNotify(payload, headers) {
     const { data } = payload;
-    const sign = headers['SunPay-Sign'];
-    const timestamp = headers['SunPay-Timestamp'];
-    const nonce = headers['SunPay-Nonce'];
-    const key = headers['SunPay-Key'];
-    const str = timestamp + nonce + JSON.stringify(data);
+    const sign = headers['sunpay-sign'];
+    const timestamp = headers['sunpay-timestamp'];
+    const nonce = headers['sunpay-nonce'];
+    const str = timestamp + nonce + JSON.stringify(payload);
     const validSign = this.utils.signBySha256(str, API_SERECT).toUpperCase();
+    console.log(sign, str)
+    console.log(validSign)
     if (sign !== validSign) {
       throw new Error('sign error');
     }
@@ -255,6 +256,4 @@ export class SunPayService extends BaseService {
       traceNo: data.order_no,
     };
   }
-
-
-}
+}

+ 1 - 1
src/modules/dj/service/order.ts

@@ -342,7 +342,7 @@ export class OrderService extends BaseService {
     }
     const sql = `SELECT a.id, a.orderNo, a.outOrderNo, a.payUrl, a.traceNo, a.mchId,  a.code, a.amount,${
       this.utils.isMerchant(roleIds) ? '' : 'a.channelCharge,'
-    } a.charge, a.status, a.notifyStatus, a.userId, a.userIp,  a.date, a.notifyUrl, a.returnUrl, a.remark, a.createTime, a.updateTime FROM dj_order a WHERE 1=1
+    } a.charge, a.status, a.notifyStatus, a.userId, a.userIp, a.currency, a.date, a.notifyUrl, a.returnUrl, a.remark, a.createTime, a.updateTime FROM dj_order a WHERE 1=1
       ${this.setSql(orderNo, 'and a.orderNo like ?', [`%${orderNo}%`])}
       ${this.setSql(outOrderNo, 'and a.outOrderNo like ?', [`%${outOrderNo}%`])}
       ${this.setSql(traceNo, 'and a.traceNo like ?', [`%${traceNo}%`])}

+ 4 - 0
src/modules/dj/service/pay.ts

@@ -97,6 +97,7 @@ export class PayService extends BaseService {
         remark: '',
         userId: payload.userId || '',
         userIp: payload.userIp || '',
+        currency: payload.currency || 'USD'
       };
       await this.orderService.create(order);
       const { isDone = true, payUrl, traceNo } = await this.dispatchService.order(
@@ -146,6 +147,9 @@ export class PayService extends BaseService {
     if (_.isEmpty(payload.userId)) {
       throw new Error('商户平台用户ID【userId】不能为空');
     }
+    if (_.isEmpty(payload.currency)) {
+      throw new Error('货币单位【currency】不能为空');
+    }
     // if (!Number.isInteger(+payload.amount)) {
     //   throw new Error('支付金额【amount】必须为整数');
     // }