pay2.js
6.11 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
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 --
pay: function(dd, succ,fail) {
if(this.wx_paying) return false;
this.wx_paying=1;
wx.showLoading();
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; //清理掉,不然签名不通过
wx.openEmbeddedMiniProgram({
appId: 'wxef277996acc166c3',
extraData: p_data,
fail(){
//-- 取消不支付 --
i.wx_paying=0;
"function" == typeof a && a();
}
})
}else {
i.weixinPay(t.data.data, succ, fail);
}
}
}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){
var th=this;
var ob=t.data.data.result;
if(!ob){
this.set_fir();
fail('支付参数错误');
return false;
}
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 {
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);
}
});
}
};