|
@@ -10,39 +10,78 @@ const config = global.yoho.config; |
|
@@ -10,39 +10,78 @@ const config = global.yoho.config; |
10
|
const helpers = global.yoho.helpers;
|
10
|
const helpers = global.yoho.helpers;
|
11
|
const sign = require('./sign');
|
11
|
const sign = require('./sign');
|
12
|
const md5 = require('yoho-md5');
|
12
|
const md5 = require('yoho-md5');
|
13
|
-const moment = require('moment');
|
13
|
+const _ = require('lodash');
|
|
|
14
|
+
|
|
|
15
|
+// const moment = require('moment');
|
14
|
const logger = global.yoho.logger;
|
16
|
const logger = global.yoho.logger;
|
15
|
const AlipayConfig = config.alipayConfig;
|
17
|
const AlipayConfig = config.alipayConfig;
|
16
|
|
18
|
|
17
|
-const Alipay = {
|
|
|
18
|
|
19
|
|
19
|
- pay(user, order, param, protocol) {
|
|
|
20
|
- let params = {
|
|
|
21
|
- service: AlipayConfig.service,
|
|
|
22
|
- partner: AlipayConfig.partner,
|
|
|
23
|
- _input_charset: AlipayConfig.inputCharset,
|
|
|
24
|
- notify_url: AlipayConfig.notifyUrl,
|
20
|
+class PaySign extends global.yoho.BaseModel {
|
|
|
21
|
+ constructor(ctx) {
|
|
|
22
|
+ super(ctx);
|
|
|
23
|
+ }
|
|
|
24
|
+ getPayData(order, param, protocol) {
|
|
|
25
|
+ let options = {
|
|
|
26
|
+ uid: _.get(this.ctx, 'req.user.uid'),
|
|
|
27
|
+ order_code: order.order_code,
|
|
|
28
|
+ payment_code: param.paymentCode,
|
25
|
return_url: protocol + ':' + helpers.urlFormat(AlipayConfig.returnUrl),
|
29
|
return_url: protocol + ':' + helpers.urlFormat(AlipayConfig.returnUrl),
|
26
|
- subject: '有货订单号:' + order.order_code,
|
|
|
27
|
- out_trade_no: order.order_code,
|
|
|
28
|
- it_b_pay: moment(order.pay_expire).format('YYYY-MM-DD HH:mm'),
|
|
|
29
|
- total_fee: parseFloat(order.payment_amount),
|
|
|
30
|
- seller_id: AlipayConfig.partner,
|
|
|
31
|
- payment_type: '1',
|
|
|
32
|
show_url: protocol + ':' + helpers.urlFormat('/home/orderdetail', { order_code: order.order_code })
|
30
|
show_url: protocol + ':' + helpers.urlFormat('/home/orderdetail', { order_code: order.order_code })
|
33
|
};
|
31
|
};
|
34
|
|
32
|
|
35
|
- // TODO 防钓鱼配置,参考php
|
33
|
+ return this.post({
|
|
|
34
|
+ api: global.yoho.ServiceAPI,
|
|
|
35
|
+ url: '/payment/alipay_data',
|
|
|
36
|
+ data: options
|
|
|
37
|
+ }).then(result => {
|
|
|
38
|
+ if (result.code === 200) {
|
|
|
39
|
+ console.log(result);
|
|
|
40
|
+ return {
|
|
|
41
|
+ code: 200,
|
|
|
42
|
+ data: {
|
|
|
43
|
+ href: AlipayConfig.payUrl + '?' + _.get(result, 'data.payParams', '')
|
|
|
44
|
+ }
|
|
|
45
|
+ };
|
|
|
46
|
+ }
|
36
|
|
47
|
|
37
|
- let signStr = md5(sign.raw(params) + AlipayConfig.alipayKey);
|
|
|
38
|
- let body = sign.rawUncode(params) + '&sign=' + signStr + '&sign_type=MD5';
|
48
|
+ return result;
|
|
|
49
|
+ });
|
|
|
50
|
+ }
|
|
|
51
|
+}
|
39
|
|
52
|
|
40
|
- return {
|
|
|
41
|
- code: 200,
|
|
|
42
|
- data: {
|
|
|
43
|
- href: AlipayConfig.payUrl + '?' + body
|
|
|
44
|
- }
|
|
|
45
|
- };
|
53
|
+const Alipay = {
|
|
|
54
|
+ // // 原node生成预支付订单
|
|
|
55
|
+ // _pay(user, order, param, protocol) {
|
|
|
56
|
+ // let params = {
|
|
|
57
|
+ // service: AlipayConfig.service,
|
|
|
58
|
+ // partner: AlipayConfig.partner,
|
|
|
59
|
+ // _input_charset: AlipayConfig.inputCharset,
|
|
|
60
|
+ // notify_url: AlipayConfig.notifyUrl,
|
|
|
61
|
+ // return_url: protocol + ':' + helpers.urlFormat(AlipayConfig.returnUrl),
|
|
|
62
|
+ // subject: '有货订单号:' + order.order_code,
|
|
|
63
|
+ // out_trade_no: order.order_code,
|
|
|
64
|
+ // it_b_pay: moment(order.pay_expire).format('YYYY-MM-DD HH:mm'),
|
|
|
65
|
+ // total_fee: parseFloat(order.payment_amount),
|
|
|
66
|
+ // seller_id: AlipayConfig.partner,
|
|
|
67
|
+ // payment_type: '1',
|
|
|
68
|
+ // show_url: protocol + ':' + helpers.urlFormat('/home/orderdetail', { order_code: order.order_code })
|
|
|
69
|
+ // };
|
|
|
70
|
+
|
|
|
71
|
+ // // TODO 防钓鱼配置,参考php
|
|
|
72
|
+
|
|
|
73
|
+ // let signStr = md5(sign.raw(params) + AlipayConfig.alipayKey);
|
|
|
74
|
+ // let body = sign.rawUncode(params) + '&sign=' + signStr + '&sign_type=MD5';
|
|
|
75
|
+
|
|
|
76
|
+ // return {
|
|
|
77
|
+ // code: 200,
|
|
|
78
|
+ // data: {
|
|
|
79
|
+ // href: AlipayConfig.payUrl + '?' + body
|
|
|
80
|
+ // }
|
|
|
81
|
+ // };
|
|
|
82
|
+ // },
|
|
|
83
|
+ pay(ctx, order, param, protocol) {
|
|
|
84
|
+ return new PaySign(ctx).getPayData(order, param, protocol);
|
46
|
},
|
85
|
},
|
47
|
notify(data, param) {
|
86
|
notify(data, param) {
|
48
|
let payParams = JSON.parse(param.payParams);
|
87
|
let payParams = JSON.parse(param.payParams);
|