wxpay.js
5.97 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
'use strict'
import { API_HOST, SERVICE_HOST, PAYMENT_CODE} from '../libs/config';
import {GET, POST} from '../libs/request';
import { getYHStorageSync } from './util';
import {
logEvent,
YB_SC_PAY_RES,
} from '../libs/analytics.js'
let app = getApp();
let orderCode;
//微信支付action
function wexinPay(data,payParam){
console.log(data.payment_amount);
console.log(data.order_amount);
let wetoast = new app.WeToast();
let order_amount = data.payment_amount ? data.payment_amount : data.order_amount;
let order_code = data.order_code;
let isVirtual = payParam && payParam.isVirtual ? 'true':'false';
if(!data){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,请求参数不完整.',
showCancel: false,
confirmText: "确定",
})
return
}
if(!data.order_code){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,订单号未获取到.',
showCancel: false,
confirmText: "确定",
})
return
}
if(!app.globalData.WXThird_session){
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 0,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
wx.showModal({
content: '支付失败,用户session未获取到.',
showCancel: false,
confirmText: "确定",
})
return
}
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 10000
})
orderCode = data.order_code
let param = {
method:'/payment/qpay_data',
order_code:data.order_code,
payment_code: PAYMENT_CODE,
'3rd_session':app.globalData.WXThird_session,
}
GET(SERVICE_HOST+'/payment/qpay_data', param)
.then(function(data) {
wx.hideToast()
if(data && data.data && data.code == 200){
qq.requestPayment({
'package': data.data.package,
'bargainor_id': `1284612001`,
'success':function(res){
let app = getApp()
// console.log("openID:", app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','wxpay'))
//上报formID
let prepareID = data.data.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',
}
// console.log("prepareID:",formIdParams)
GET(API_HOST, formIdParams)
.then((data) => {
// console.log('responsedata', data)
})
.catch(error => {
})
}
let params = {
ORDER_AMOUNT: order_amount,
PAY_TYPE: 1,
PAY_RES: 1,
ORD_NUM: order_code,
};
logEvent(YB_SC_PAY_RES, params);
payConfirm(orderCode)
// wx.showModal({
// content: '支付成功',
// showCancel: false,
// confirmText: "确定",
// complete: function(res) {
// wx.navigateBack({
// delta: getCurrentPages().length-1
// })
if (payParam && payParam.fromPage == 'groupPurchaseDetail'){
wx.navigateTo({
url: "/pages/groupPurchase/groupPurchaseResult?activity_id=" + payParam.activity_id + '&group_no=' + payParam.group_no + '&page_name=' + 'statements' + '&page_param=' + ''
});
}else {
wx.navigateTo({
url: "/pages/paymentSuccessed/paymentSuccessed?orderCode=" + order_code + '&hasSuc=true' + '&price=' + parseInt(order_amount).toFixed(2) + '&isVirtual=' + isVirtual
});
}
// }})
},
'fail':function(res){
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'){
wx.redirectTo({
url: '/pages/orders/orders'
})
}else{
wx.showModal({
content: res.errMsg,
showCancel: false,
confirmText: "确定",
complete: function(res) {
wx.redirectTo({
url: '/pages/orders/orders'
})
}
})
}
}
})
}else{
wx.hideToast()
wx.showModal({
content: data.code+':'+data.message,
showCancel: false,
confirmText:'确定',
confirmColor:"#000",
complete: function(res) {
wx.redirectTo({
url: '/pages/orders/orders'
})
}
})
}
})
.catch(function(error) {
// console.log(error+'')
});
}
//支付确认接口
function payConfirm(orderCode){
if(!orderCode||orderCode==0){
return
}
let param = {
method:'app.SpaceOrders.payConfirm',
order_code:orderCode,
payment_id:45,
uid:app.globalData.userInfo.uid,
}
GET(API_HOST, param)
}
module.exports = {
wexinPay: wexinPay,
}