pay2.js
4.41 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
var t = getApp(), n = t.request,wx_paying=0;
module.exports = {
url: "/api/weshop/plus/create/plus/order",
set_pay_url:function (url){
this.url=url;//让链接地址进行赋值
},
//-- createRechargeOrder create/plus/order --
pay: function(dd, succ,fail) {
if(wx_paying) return false;
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{
if(t.data.data.is_fuioupay){
const plugin = requirePlugin('fuiou-pay')
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);
wx_paying=0;
"function" == typeof succ && succ();
},function (error){
console.log("插件支付错误",error);
//支付失败的时候
//getApp().confirmBox(error.code+error.message);
fail(error.code+":"+error.message)
wx_paying=0;
})
}else {
i.weixinPay(t.data.data, succ, fail);
}
}
}else{
wx_paying=0;
"function" == typeof fail && fail(t.data.msg);
}
return false;
},
fail: function() {
wx.hideLoading();
wx_paying=0;
"function" == typeof fail && fail();
},
failStatus: function() {
wx.hideLoading();
wx_paying=0;
"function" == typeof fail && fail();
}
});
},
//-- 这里是专享礼包的调用 --
pay_data:function (t,succ,fail){
var ob=t.data.data.result;
if(!ob){
fail('支付参数错误');
return false;
}
if(ob.is_fuioupay){
const plugin = requirePlugin('fuiou-pay')
var paramsJson={
reqType:"11",//必填 01-商户模式,11-机构模式
reqData:ob.reqData,//必填 富友加密参数
}
console.log(plugin, plugin.fuioupay)
plugin.fuioupay(parseInt(ob.amt),paramsJson,function (res){
console.log(res);
wx_paying=0;
"function" == typeof succ && succ();
},function (error){
console.log("插件支付错误",error);
//支付失败的时候
//getApp().confirmBox(error.code+error.message);
fail(error.code+":"+error.message)
wx_paying=0;
})
}else {
this.weixinPay(ob, succ, fail);
}
},
weixinPay: function(n, succ,fail) {
if(!n) return false;
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) {
wx_paying=0;
"function" == typeof succ && succ();
},
fail: function(n) {
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);
}
});
}
};