-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.js
64 lines (61 loc) · 1.58 KB
/
api.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
var request = require('request');
module.exports = {
getElemeHongbao: function(data) {
return new Promise(function(resolve, reject) {
request({
url: 'https://restapi.ele.me/marketing/promotion/weixin/' + data.openId,
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
headers: {
'X-Shard': 'eosid=' + parseInt(data['group_sn'], 16)
}
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
var r = JSON.parse(body)
resolve(r);
} else {
console.log(error, response)
}
});
});
},
getPhone: function(data) {
return new Promise(function(resolve, reject) {
request({
url: 'https://restapi.ele.me/v1/weixin/' + data.openId + '/phone?sign=' + data.sign,
method: 'GET'
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
resolve(true);
} else {
console.log(error, response)
}
});
});
},
changePhone: function(data) {
var param = {
sign: data.sign,
phone: data.phone
};
return new Promise(function(resolve, reject) {
request({
url: 'https://restapi.ele.me/v1/weixin/' + data.openId + '/phone',
method: 'PUT',
body: JSON.stringify(param),
credentials: 'include',
headers: {
'X-Shard': 'eosid=' + parseInt(data['group_sn'], 16)
}
}, function(error, response, body) {
if (!error && response.statusCode == 204) {
resolve(data.phone);
} else {
console.log(error, response.statusCode)
}
});
});
}
};