-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·92 lines (76 loc) · 2.51 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require('fs');
const request = require('request');
class quickSms{
constructor(){
this.username;
this.password;
this.base_url = 'http://www.quicksms1.com/api/sendsms.php?';
this.end_url = '&report=1&convert=1&route=1';
}
setCredentials(username, password){
this.username = username;
this.password = password;
}
genUrl(sender,message,recipient){
let url = '';
if(typeof recipient !== 'object'){
url = this.base_url+'username='+this.username+'&password='+this.password+'&sender='+sender+"&message="+message+"&recipient="+recipient+this.end_url;
}
else{
url = this.base_url+'username='+this.username+'&password='+this.password+'&sender='+sender+"&message="+message+"&recipient="+recipient.join(',')+this.end_url;
}
return url;
}
sendSms(sender,message,recipient,cb){
if(!this.username && !this.password){
console.log('username or password is incorrect');
cb(err);
return;
}
let url = this.genUrl(sender,message,recipient);
request(url, (err,response,body) => {
if(err) cb(err);
cb(body);
})
}
sendBulk(sender,message,recipientFile,cb){
if(!this.username && !this.password){
console.log('username or password is incorrect');
cb(err);
return;
}
fs.readFile(recipientFile,(err,data) => {
if(err){
cb(err);
return;
}
phoneNumbersArray = data.split(',');
let url = this.genUrl(sender,message,phoneNumbersArray);
request(url, (err,response,body) => {
if(err) cb(err);
cb(body);
})
})
}
getDeliveryReport(msgId,cb){
if(!this.username && !this.password){
conosle.log('jjjj')
let url = "http://www.quicksms1.com/api/getdelivery.php?username="+this.username+"&password="+this.password+"&msgid="+msgId;
console.log(url);
request(url, (err, response,body) => {
if(err) cb(err);
cb(body);
});
}
}
getBalance(cb){
if(!this.username && !this.password){
let url = this.base_url+"username="+this.username+"&password="+this.password+"&balance=1";
request(url, (err,response,body) => {
if(err) cb(err);
cb(body);
});
}
}
}
module.exports = new quickSms