wechatPaymentService.js
7.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
angular.module('myApp.services')
.service('wechatPayment',['$http', '$q', '$rootScope','$location','$state',function($http, $q, $rootScope,$location, $state) {
// var host = 'http://finance.api.dingdachuxing.com/service';
// var host = 'http://finance.dy.dingdatech.com/service';
// var host = 'http://lsz1.28ms.com/service'
// var host = 'http://47.99.81.49:50413/service'
var host = 'https://finance.dy.dingdatech.com/service'
var h5wxhost = 'http://h5api.dy.dingdachuxing.com/service/balance/';
var h5alipayhost = 'http://h5api.dy.dingdachuxing.com/service/balance/';
console.log('search:',$location.search());
//调用微信JS api 支付
var jsApiCall = function (sign, q) {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId : sign.appId,
timeStamp : sign.timeStamp,
nonceStr : sign.nonceStr,
package : sign.packageStr,
signType : sign.signType,
paySign : sign.paySign
},
function (res) {
if (res.err_msg == 'get_brand_wcpay_request:ok') {
layer.open({
content: '支付成功!',
time:1
});
q.resolve(res.err_msg);
return;
} else if (res.err_msg == 'get_brand_wcpay_request:fail') {
alert("支付失败:" + JSON.stringify(res))
layer.open({
content: '支付失败!',
time:1
});
} else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
layer.open({
content: '支付取消!',
time:1
});
} else {
layer.open({
content: '支付异常,'+res.err_msg,
time:1
});
}
q.reject(res.err_msg);
// WeixinJSBridge.log(res.err_msg);
// console.error(res.err_msg);
}
);
}
var wxh5ApiCall = function (sign, q) {
// console.log('sign', sign);
// $state.go('bond');
var redirect_url= ''
if(isiOS){
redirect_url = "&redirect_url=dcxing.com://" + window.location.origin + window.location.pathname + '#/wxPayReturn/' + q
}
window.location.href = sign.mwebUrl + redirect_url;
}
var callOrderApi = function(url, data, type){
var q = $q.defer();
$http.post(url, data)
.success(function (data) {
if(data.meta.code == 200) {
// alert('支付签名返回:' + JSON.stringify(data));
wxh5ApiCall(data.data.wechatDto, type);
}else{
layer.open({
content:'支付失败:code '+data.meta.code+","+ data.meta.message,
time:1
});
q.reject(data.meta.message)
}
})
return q.promise;
}
var callUnifiedOrderApiAliPay = function(msg){
var q = $q.defer();
q.reject(msg)
return q.promise;
}
return {
/**
* 租车付款
*/
callRentPay: function (orderId, amount) {
var param = Object.assign($location.search(),{
amount : amount,
body : "租车租金",
type : 101
});
return callUnifiedOrderApi(host + '/bill/wx/' + orderId, param);
},
/**
* 租车付款
*/
callRentTypePay: function (orderId, amount, type) {
var user = JSON.parse(localStorage.getItem("ls.user"))
if(user){
var token = user.token
}
switch (type) {
case 100:
var html = ' <form action="'+ host + '/h5/alipay/bill/'+ orderId + '/'+ token
+'" method="post">' +
' <input type="text" name="amount" value="'+amount+'" />' +
' <input type="text" name="body" value="租车租金"/>' +
' <input type="text" name="type" value="100" />' +
' <input type="submit" id="ok">' +
' </input>' +
' </form>'
var form = document.createElement('div')
form.innerHTML = html
// form.querySelector('#ok').click()
document.body.appendChild(form)
document.querySelector('#ok').click()
return callUnifiedOrderApiAliPay('支付')
case 101:
var param = Object.assign($location.search(),{
amount : amount,
body : "租车租git金",
type : 101
});
return callOrderApi(host + "/bill/wx/h5/" + orderId, param, 'order');
default:
return null
}
},
/**
* 保证金充值
* @param amount
*/
callDepositPay : function(amount){
var param = Object.assign($location.search(),{
amount : amount,
body : "保证金充值",
type : 101
});
return callOrderApi(host + "/bail/wx", param);
}, /**
* 保证金充值
* @param amount
*/
callDepositTypePay : function(amount, type){
var user = JSON.parse(localStorage.getItem("ls.user"))
if(user){
var token = user.token
}
switch (type) {
case 100:
// $http.post(host + '/bill/alipay/h5',{
// 'amout': amount,
// 'body': '保证金充值',
// 'type': 100,
// }).success(function (res) {
// console.log(res)
// })
var html = ' <form action="'+ host + '/h5/alipay/bail/'+token
+'" method="post">' +
' <input type="text" name="amount" value="'+amount+'" />' +
' <input type="text" name="body" value="保证金充值"/>' +
' <input type="text" name="type" value="100" />' +
' <input type="submit" id="ok">\n' +
' 余额充值\n' +
' </input>\n' +
' </form>'
var form = document.createElement('div')
form.innerHTML = html
// form.querySelector('#ok').click()
document.body.appendChild(form)
document.querySelector('#ok').click()
return callUnifiedOrderApiAliPay('支付')
case 101:
var param = Object.assign($location.search(),{
amount : amount,
body : "保证金充值",
type : type
});
return callOrderApi(host + "/bail/wx/h5", param, 'bond');
default:
return null
}
},
/**
* 钱包充值
* @param amount
*/
callBalanceRecharge : function(amount,way){
var host = (way == 100 ? h5alipayhost+ "alipay/h5" : h5wxhost+ "wx/h5");
var param = Object.assign($location.search(),{
amount : amount,
body : "钱包充值",
type : parseInt(way)
});
return callOrderApi(host, param);
}
}
}]);