-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
76 lines (66 loc) · 1.42 KB
/
index.js
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
var API_LIST = require('./api-list');
angular.module('ngWeixin', [])
.provider('wx', WXProvider);
function WXProvider() {
var debug = true;
var apiList = API_LIST;
var ticketUrl = '/api/token';
var appId;
var httpService;
return {
appId: function(_appId) {
appId = _appId;
return this;
},
debug: function(_debug) {
debug = _debug;
return this;
},
appList: function(_appList) {
appList = _appList;
return this;
},
signUrl: function(_ticketUrl) {
ticketUrl = _ticketUrl;
return this;
},
/**
* @ngInject
*/
$get: function($http) {
httpService = $http;
config();
handleError();
return wx;
}
};
function getUrl() {
return window.location.origin + window.location.pathname;
}
function getTicket() {
console.log('get ticket');
var $http = httpService;
return $http.post(ticketUrl, {
url: getUrl()
}).then(function(results) {
return results.data;
});
}
function handleError() {
console.log('handle error');
wx.error(config);
}
function config() {
console.log('config');
var $http = httpService;
if (!appId) {
throw new Error('appId not set');
}
var ticket = getTicket().then(function(ticket) {
ticket.debug = debug;
ticket.appId = appId;
ticket.jsApiList = apiList;
wx.config(ticket);
});
}
}