wechatPaymentService.js
3.66 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
angular.module('myApp.services')
.service('wechatPayment',['$http', '$q', '$rootScope',function($http, $q, $rootScope) {
//var host = 'http://finance.api.dingdachuxing.com/service';
var host = 'http://finance.dy.dingdatech.com/service';
var h5wxhost = 'http://lsz1.28ms.com/service/balance/';
var h5alipayhost = 'http://lsz1.28ms.com/service/balance/';
//调用微信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);
window.location.href = sign.mwebUrl;
}
var callUnifiedOrderApi = function(url, data){
var q = $q.defer();
$http.post(url, data)
.success(function (data) {
if(data.meta.code == 200) {
// alert('支付签名返回:' + JSON.stringify(data));
wxh5ApiCall(data.data.wechatDto, q);
}else{
layer.open({
content:'支付失败:code '+data.meta.code+","+ data.meta.message,
time:1
});
q.reject(data.meta.message)
}
})
return q.promise;
}
return {
/**
* 租车付款
*/
callRentPay: function (orderId, amount) {
return callUnifiedOrderApi(host + '/bill/wx/' + orderId, {
amount : amount,
body : "租车租金",
type : 101
});
},
/**
* 保证金充值
* @param amount
*/
callDepositPay : function(amount){
return callUnifiedOrderApi(host + "/bail/wx", {
amount : amount,
body : "保证金充值",
type : 101
});
},
/**
* 钱包充值
* @param amount
*/
callBalanceRecharge : function(amount,way){
var host = (way == 100 ? h5alipayhost+ "alipay/h5" : h5wxhost+ "wx/h5");
return callUnifiedOrderApi(host, {
amount : amount,
body : "钱包充值",
type : parseInt(way)
});
}
}
}]);