payUtil.js
4.95 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import api from '../common/api.js';
import config from '../config';
import tt from "./tt";
// import {
// logEvent
// } from '../../libs/analytics.js'
let app = getApp();
function pay(data, payParam) {
let orderCode = data.order_code;
let order_amount = data.order_amount;
let param = {
order_code: orderCode,
payment_code: config.payment_code,
openid: app.globalData.openID,
}
api.get({data: param,url:"/payment/alipay_data"})
.then(json=>{
let jsonData = json.data;
console.log('====================================');
console.log(json);
console.log('====================================');
if(jsonData){
let payParams = jsonData.payParams;
// ttPayment(payParams, data);
let paymentData = JSON.parse(payParams);
let timestampStr = paymentData.timestamp+"";
let total_amount = parseFloat(paymentData.total_amount);
//头条需要该字段为String
paymentData.timestamp = timestampStr;
//头条需要该字段为数字
paymentData.total_amount = total_amount;
tt.requestPayment({
data:paymentData,
success (res) {
let app = getApp()
//上报formID
let prepareID = paymentData.package
if (prepareID && prepareID.length > 10) {
prepareID = prepareID.slice(10)
let formIdParams = {
uid: app.getUid(),
order_code: orderCode,
openId: app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','wxpay'),
miniapp_type: app.globalData.miniapp_type,
formId: prepareID,
method: 'wechat.formId.add',
formType: 'pay',
}
api.get({data:formIdParams})
.then((data) => {
// console.log('responsedata', data)
})
.catch(error => {
})
}
// let params = {
// ORDER_AMOUNT: order_amount,
// PAY_TYPE: 1,
// PAY_RES: 1,
// ORD_NUM: orderCode,
// };
// logEvent(YB_SC_PAY_RES, params);
payConfirm(orderCode);
//支付成功以后跳转到支付成功页
if (orderCode && paymentData.fromPage == 'groupPurchaseDetail'){
tt.navigateTo({
url: "/pages/groupPurchase/groupPurchaseResult?activity_id=" + payParam.activity_id + '&group_no=' + payParam.group_no + '&page_name=' + 'statements' + '&page_param=' + ''
});
}else {
tt.navigateTo({
url: "/pages/paymentSuccessed/paymentSuccessed?orderCode=" + orderCode + '&hasSuc=true' + '&price=' + parseInt(order_amount).toFixed(2) + '&isVirtual=' + 'false'
});
}
},
fail (res) {
console.log("pay fail: " + res.errMsg);
// let params = {
// ORDER_AMOUNT: order_amount,
// PAY_TYPE: 1,
// PAY_RES: 0,
// ORD_NUM: order_code,
// };
// logEvent(YB_SC_PAY_RES, params);
if (res.errMsg=='requestPayment:fail cancel') {
tt.redirectTo({
url: '/pages/orders/orders'
})
}else{
tt.showModal({
content: res.errMsg,
showCancel: false,
confirmText: "确定",
complete: function(res) {
tt.redirectTo({
url: '/pages/orders/orders'
})
}
})
}
}
})
}
})
}
//支付确认接口
function payConfirm(orderCode){
if(!orderCode||orderCode==0){
return
}
let param = {
method:'app.SpaceOrders.payConfirm',
order_code:orderCode,
payment_id:45
}
api.get({data: param})
.then(json=>{
})
}
module.exports = {
aliPay: pay,
}