-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathebulksmsapi.php
147 lines (124 loc) · 5.26 KB
/
ebulksmsapi.php
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//sending welcom sms ebulksms.com
$json_url = "http://api.ebulksms.com:8080/sendsms.json";
$xml_url = "http://api.ebulksms.com:8080/sendsms.xml";
$http_get_url = "http://api.ebulksms.com:8080/sendsms";
$username = '';
$apikey = '';
//Function to connect to SMS sending server using HTTP POST
function doPostRequest($url, $arr_params, $headers = array('Content-Type: application/x-www-form-urlencoded')) {
$response = array();
$final_url_data = $arr_params;
if (is_array($arr_params)) {
$final_url_data = http_build_query($arr_params, '', '&');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $final_url_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response['body'] = curl_exec($ch);
$response['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $response['body'];
}
function useJSON($url, $username, $apikey, $flash, $sendername, $messagetext, $recipients) {
$gsm = array();
$country_code = '234';
$arr_recipient = explode(',', $recipients);
foreach ($arr_recipient as $recipient) {
$mobilenumber = trim($recipient);
if (substr($mobilenumber, 0, 1) == '0'){
$mobilenumber = $country_code . substr($mobilenumber, 1);
}
elseif (substr($mobilenumber, 0, 1) == '+'){
$mobilenumber = substr($mobilenumber, 1);
}
$generated_id = uniqid('int_', false);
$gsm['gsm'][] = array('msidn' => $mobilenumber, 'msgid' => $generated_id);
}
$message = array(
'sender' => $sendername,
'messagetext' => $messagetext,
'flash' => "{$flash}",
);
$request = array('SMS' => array(
'auth' => array(
'username' => $username,
'apikey' => $apikey
),
'message' => $message,
'recipients' => $gsm
));
$json_data = json_encode($request);
if ($json_data) {
$response = doPostRequest($url, $json_data, array('Content-Type: application/json'));
$result = json_decode($response);
return $result->response->status;
} else {
return false;
}
}
if (isset($_POST['email'])) {
$username = "nwudoebuka@gmail.com";
$apikey = "0b4bd019a7292ff97d7b626335afe0176d2a2855";
$sendername = substr($_POST['sender_name'], 0, 11);
$recipients = $phone;
$message = "Good day,$name. your Online details are Accnumber:$accountnumber Username: $usernamet Paswd: $pass Thank you for choosing us.";
$flash = 0;
if (get_magic_quotes_gpc()) {
$message = stripslashes($message);
}
$message = substr($message, 0, 160);
#Use the next line for HTTP POST with JSON
$result = useJSON($json_url, $username, $apikey, $flash, $sendername, $message, $recipients);
// echo $result;
#Uncomment the next line and comment the one above if you want to use HTTP POST with XML
//$result = useXML($xml_url, $username, $apikey, $flash, $sendername, $message, $recipients);
#Uncomment the next line and comment the ones above if you want to use simple HTTP GET
//$result = useHTTPGet($http_get_url, $username, $apikey, $flash, $sendername, $message, $recipients);
}
function useXML($url, $username, $apikey, $flash, $sendername, $messagetext, $recipients) {
$country_code = '234';
$arr_recipient = explode(',', $recipients);
$count = count($arr_recipient);
$msg_ids = array();
$recipients = '';
$xml = new SimpleXMLElement('<SMS></SMS>');
$auth = $xml->addChild('auth');
$auth->addChild('username', $username);
$auth->addChild('apikey', $apikey);
$msg = $xml->addChild('message');
$msg->addChild('sender', $sendername);
$msg->addChild('messagetext', $messagetext);
$msg->addChild('flash', $flash);
$rcpt = $xml->addChild('recipients');
for ($i = 0; $i < $count; $i++) {
$generated_id = uniqid('int_', false);
$generated_id = substr($generated_id, 0, 30);
$mobilenumber = trim($arr_recipient[$i]);
if (substr($mobilenumber, 0, 1) == '0') {
$mobilenumber = $country_code . substr($mobilenumber, 1);
} elseif (substr($mobilenumber, 0, 1) == '+') {
$mobilenumber = substr($mobilenumber, 1);
}
$gsm = $rcpt->addChild('gsm');
$gsm->addchild('msidn', $mobilenumber);
$gsm->addchild('msgid', $generated_id);
}
$xmlrequest = $xml->asXML();
if ($xmlrequest) {
$result = doPostRequest($url, $xmlrequest, array('Content-Type: application/xml'));
$xmlresponse = new SimpleXMLElement($result);
return $xmlresponse->status;
}
return false;
}
function useHTTPGet($url, $username, $apikey, $flash, $sendername, $messagetext, $recipients) {
$query_str = http_build_query(array('username' => $username, 'apikey' => $apikey, 'sender' => $sendername, 'messagetext' => $messagetext, 'flash' => $flash, 'recipients' => $recipients));
return file_get_contents("{$url}?{$query_str}");
}
//welcom sms ends here