chinabank.js
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @author: xiaoxiao.hao<xiaoxiao.hao@yoho.cn>
* @date: 2017/3/23
*/
'use strict';
const helpers = global.yoho.helpers;
const md5 = require('md5');
const PAY_URL = 'https://pay3.chinabank.com.cn/PayGate';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
pay(user, order, param, protocol) {
let payParams = JSON.parse(param.payParams);
let extraParam = JSON.stringify({
sign_id_ext: user.uid
});
let params = {
v_mid: payParams.merchant_id, // 商户号
v_oid: order.order_code, // 商户订单号
v_amount: order.payment_amount, // 总金额 以元为单位
v_moneytype: 'CNY', // 以人民币为单位
v_url: protocol + ':' + helpers.urlFormat('/shopping/newpay/callback/chinabank'), // 同步地址
v_md5info: '', // 签名
remark1: extraParam
};
params.v_md5info = md5(
`${params.v_amount}${params.v_moneytype}${params.v_oid}` +
`${params.v_mid}${params.v_url}${payParams.merchant_key}`
).toUpperCase();
return {
code: 200,
data: Object.assign({reqType: PAY_URL}, params)
};
}
notify(data, param) {
let payParams = JSON.parse(param.payParams || '{}');
let orderCode = parseInt(data.v_oid, 10);
if (!this.checkResponse(data, payParams)) {
return {payResult: -1};
}
return {
bankName: '',
orderCode: orderCode,
payResult: 200,
totalFee: data.v_amount,
tradeNo: '',
bankBillNo: ''
};
}
// 验证验证
checkResponse(data, payParams) {
let signText;
if (parseInt(data.v_pstatus, 10) !== 20) {
return false;
}
signText = md5(
`${data.v_oid}${data.v_pstatus}${data.v_amount}${data.v_moneytype}${payParams.merchant_key}`
).toUpperCase();
return data.v_md5str === signText;
}
};