|
@@ -5,6 +5,7 @@ import * as moment from 'moment';
|
|
|
import { Utils } from '../../../../comm/utils';
|
|
|
import { HttpService } from '@midwayjs/axios';
|
|
|
import { ILogger } from '@midwayjs/logger';
|
|
|
+import * as forge from 'node-forge';
|
|
|
|
|
|
const HOST = "https://payment.alchemytech.cc";
|
|
|
const MCH_ID = 'AC202299319';
|
|
@@ -117,7 +118,7 @@ export class AchService extends BaseService {
|
|
|
param.payBankCode = extra.payBankCode;
|
|
|
}
|
|
|
const signStr = this.utils.signSort(param);
|
|
|
- param.sign = this.utils.signByMD5WithRSA(signStr, PRIVATE_KEY);
|
|
|
+ param.sign = this.sign(PRIVATE_KEY, signStr);
|
|
|
if (extra.idendifyType) {
|
|
|
param.idendifyType = extra.idendifyType;
|
|
|
}
|
|
@@ -143,6 +144,15 @@ export class AchService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ sign(privateKey: string, text: string): string {
|
|
|
+ const privateKeyPem = `-----BEGIN RSA PRIVATE KEY-----\n${privateKey.match(/.{1,64}/g).join('\n')}\n-----END RSA PRIVATE KEY-----\n`;
|
|
|
+ const privateKeyObj = forge.pki.privateKeyFromPem(privateKeyPem);
|
|
|
+ const md = forge.md.md5.create();
|
|
|
+ md.update(text, 'utf8');
|
|
|
+ const signature = privateKeyObj.sign(md);
|
|
|
+ return forge.util.encode64(signature);
|
|
|
+ }
|
|
|
+
|
|
|
async query(payload) {
|
|
|
const param: any = {
|
|
|
merchantNo: MCH_ID,
|