-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (78 loc) · 2.16 KB
/
index.js
File metadata and controls
80 lines (78 loc) · 2.16 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
const rp = require('request-promise');
/**
* send sms
* @prarm {string} url - API url
* @param {string} uid - login account
* @param {string} password - login password
* @param {string} subject - message subject only for admin use
* @param {string} msg - message
* @param {string} dest - phone numbers (format: 0910123456,0911123456,...)
* @param {string} time - time to send msg (leave blank for immediate delivery)
* @returns {object} credit,sended numbers,cost,unsend numbers,batch id,error
*/
exports.send = async function(url, uid, password, subject, msg, dest, time) {
try {
const result = await rp({
uri: url || 'https://biz3.every8d.com.tw/prepaid/API21/HTTP/sendSMS.ashx',
method: 'GET',
qs: {
UID: uid,
PWD: password,
SB: subject,
MSG: msg,
DEST: dest,
ST: time,
},
});
const temp = result.split(',');
if (temp.length !== 5) {
return {
error: `return format error: ${result}`,
};
}
return {
credit: temp[0],
sended: temp[1],
cost: temp[2],
unsend: temp[3],
batch: temp[4],
error: null,
};
} catch(e) {
return {
error: e.message,
};
}
};
/**
* get credit
* @prarm {string} url - API url
* @param {string} uid - login account
* @param {string} password - login password
* @returns {object} credit,error
*/
exports.getCredit = async function(url, uid, password) {
try {
const result = await rp({
uri: url || 'https://biz3.every8d.com.tw/prepaid/API21/HTTP/getCredit.ashx',
method: 'GET',
qs: {
UID: uid,
PWD: password,
},
});
if (isNaN(Number(result))) {
return {
error: `return format error: ${result}`,
};
}
return {
credit: result,
error: null,
};
} catch(e) {
return {
error: e.message,
};
}
};