pay2.js
7.7 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
var t = getApp(), n = t.request;
module.exports = {
wx_paying:0,
url: "/api/weshop/plus/create/plus/order",
set_pay_url:function (url){
this.url=url;//让链接地址进行赋值
},
set_fir(){
this.wx_paying=0;
},
//-- createRechargeOrder create/plus/order --
// get_order是通联专用,获取订单号
pay: function(dd, succ,fail,th) {
if(this.wx_paying) return false;
this.wx_paying=1;
wx.showLoading();
getApp().globalData.is_tonglian_pay=0; //是通联支付的时候
var i = this;
n.post(this.url, {
data: dd,
success: function(t) {
wx.hideLoading();
if(t.data.code==0){
if(t.data.data=="升级成功"){
"function" == typeof succ && succ(1);
}else{
var is_pos_pay=t.data.data.is_pos_pay;
if(t.data.data.is_fuioupay){
const plugin = requirePlugin('fuiou-pay')
getApp().globalData.no_clear=1;
getApp().globalData.fuiou_pay=1;
var paramsJson={
reqType:"11",//必填 01-商户模式,11-机构模式
reqData:t.data.data.reqData,//必填 富友加密参数
}
console.log(plugin, plugin.fuioupay)
plugin.fuioupay(parseInt(t.data.data.amt),paramsJson,function (res){
console.log(res);
getApp().globalData.fuiou_pay=0;
i.wx_paying=0;
"function" == typeof succ && succ();
},function (error){
console.log("插件支付错误",error);
//支付失败的时候
//getApp().confirmBox(error.code+error.message);
var msg='取消支付';
getApp().globalData.fuiou_pay=0;
if(error.code){
msg=error.code+":"+error.message;
}
fail(msg)
i.wx_paying=0;
})
}
//-- 通联的支付插件 --
else if(is_pos_pay){
var p_data=t.data.data;
delete p_data.is_pos_pay; //清理掉,不然签名不通过
if(th){
var ordno=p_data.reqsn;
if(ordno.indexOf('_')){
var str_arr=ordno.split('_');
ordno=str_arr[0];
}
th.data.ok_order_sn=ordno;
}
getApp().globalData.is_tonglian_pay=1; //是通联支付的时候
wx.openEmbeddedMiniProgram({
appId: 'wxef277996acc166c3',
extraData: p_data,
fail(){
//-- 取消不支付 --
i.wx_paying=0;
"function" == typeof fail && fail('取消支付');
}
})
}else {
i.weixinPay(t.data.data, succ, fail);
}
}
}
else if(t.data.code==-2 && dd.rechargeType==3){
i.wx_paying=0;
"function" == typeof fail && fail(t.data);
}
else{
i.wx_paying=0;
"function" == typeof fail && fail(t.data.msg);
}
return false;
},
fail: function() {
wx.hideLoading();
i.wx_paying=0;
"function" == typeof fail && fail();
},
failStatus: function() {
wx.hideLoading();
i.wx_paying=0;
"function" == typeof fail && fail();
}
});
},
//-- 这里是专享礼包的调用 --
pay_data:function (t,succ,fail,get_order){
var th=this;
var ob=t.data.data.result;
this.wx_paying=1;
if(!ob){
this.set_fir();
fail('支付参数错误');
return false;
}
getApp().globalData.is_tonglian_pay=1; //是通联支付的时候
if(ob.is_fuioupay){
const plugin = requirePlugin('fuiou-pay')
var paramsJson={
reqType:"11",//必填 01-商户模式,11-机构模式
reqData:ob.reqData,//必填 富友加密参数
}
getApp().globalData.no_clear=1;
getApp().globalData.fuiou_pay=1;
console.log(plugin, plugin.fuioupay)
plugin.fuioupay(parseInt(ob.amt),paramsJson,function (res){
getApp().globalData.fuiou_pay=0;
console.log(res);
th.wx_paying=0;
"function" == typeof succ && succ();
},function (error){
getApp().globalData.fuiou_pay=0;
th.wx_paying=0;
console.log("插件支付错误",error);
//支付失败的时候
//getApp().confirmBox(error.code+error.message);
var msg='取消支付';
if(error && error.code){
msg=error.code+":"+error.message;
}
fail(msg)
})
}
//-- 通联的支付插件 --
else if(ob.is_pos_pay){
var p_data=ob;
delete p_data.is_pos_pay; //清理掉,不然签名不通过
if(get_order){
get_order(p_data.reqsn); //把单号返回
}
getApp().globalData.is_tonglian_pay=1; //是通联支付的时候
wx.openEmbeddedMiniProgram({
appId: 'wxef277996acc166c3',
extraData: p_data,
fail(){
//-- 取消不支付 --
th.wx_paying=0;
"function" == typeof a && a();
}
})
}
else {
this.weixinPay(ob, succ, fail);
}
},
weixinPay: function(n, succ,fail) {
if(!n){
this.set_fir();
return false;
}
var th=this;
getApp().globalData.no_clear=1;
wx.requestPayment({
timeStamp: String(n.timeStamp),
nonceStr: n.nonceStr,
package: n.packageValue,
signType: n.signType,
paySign: n.paySign,
success: function(n) {
th.wx_paying=0;
"function" == typeof succ && succ();
},
fail: function(n) {
th.wx_paying=0;
var msg='';
switch (n.errMsg){
case "requestPayment:fail": msg="支付失败";break;
case "requestPayment:fail cancel": msg="您已取消支付";break;
default: msg="支付失败:" + n.errMsg.substr("requestPayment:fail ".length);
}
console.log(n);
"function" == typeof fail && fail(msg);
}
});
}
};