· 6 years ago · Apr 23, 2020, 12:34 PM
1<?php
2if(isset($_POST['no']) && isset($_POST['isi'])){
3$msisdn = ($_POST['no']);
4$unicode_msg = 'aaa';
5}
6$username = '123popok456';
7$password = 'bayu999xx';
8//$msisdn = '+6281275547155';
9$url = 'http://bulksms.vsms.net/eapi/submission/send_sms/2/2.0';
10$port = 80;
11//$unicode_msg = 'aaa';
12$eight_bit_msg = '0605040B8423F0DC0601AE02056a0045c60d0362756c6b736d732e636f6d00010356697369742042756c6b534d532e636f6d20686f6d6570616765000101';
13$transient_errors = array(
1440 => 1
15);
16$post_body = unicode_sms( $username, $password, $unicode_msg, $msisdn );
17$result = send_message( $post_body, $url, $port );
18if( $result['success'] ) {
19 print_ln( formatted_server_response( $result ) );
20}
21else {
22 print_ln( formatted_server_response( $result ) );
23}
24function print_ln($content) {
25 if (isset($_SERVER["SERVER_NAME"])) {
26 print $content."<br />";
27 }
28 else {
29 print $content."\n";
30 }
31}
32
33function formatted_server_response( $result ) {
34 $this_result = "";
35
36 if ($result['success']) {
37 $this_result .= "Success: batch ID " .$result['api_batch_id']. "API message: ".$result['api_message']. "\nFull details " .$result['details'];
38 }
39 else {
40 $this_result .= "Fatal error: HTTP status " .$result['http_status_code']. ", API status " .$result['api_status_code']. " API message " .$result['api_message']. " full details " .$result['details'];
41
42 if ($result['transient_error']) {
43 $this_result .= "This is a transient error - you should retry it in a production environment";
44 }
45 }
46 return $this_result;
47}
48
49function send_message ( $post_body, $url, $port ) {
50
51 $ch = curl_init( );
52 curl_setopt ( $ch, CURLOPT_URL, $url );
53 curl_setopt ( $ch, CURLOPT_PORT, $port );
54 curl_setopt ( $ch, CURLOPT_POST, 1 );
55 curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
56 curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
57 curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
58 curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 20 );
59
60 $response_string = curl_exec( $ch );
61 $curl_info = curl_getinfo( $ch );
62
63 $sms_result = array();
64 $sms_result['success'] = 0;
65 $sms_result['details'] = '';
66 $sms_result['transient_error'] = 0;
67 $sms_result['http_status_code'] = $curl_info['http_code'];
68 $sms_result['api_status_code'] = '';
69 $sms_result['api_message'] = '';
70 $sms_result['api_batch_id'] = '';
71
72 if ( $response_string == FALSE ) {
73 $sms_result['details'] .= "cURL error: " . curl_error( $ch ) . "\n";
74 } elseif ( $curl_info[ 'http_code' ] != 200 ) {
75 $sms_result['transient_error'] = 1;
76 $sms_result['details'] .= "Error: non-200 HTTP status code: " . $curl_info[ 'http_code' ] . "\n";
77 }
78 else {
79 $sms_result['details'] .= "Response from server: $response_string\n";
80 $api_result = explode( '|', $response_string );
81 $status_code = $api_result[0];
82 $sms_result['api_status_code'] = $status_code;
83 $sms_result['api_message'] = $api_result[1];
84 if ( count( $api_result ) != 3 ) {
85 $sms_result['details'] .= "Error: could not parse valid return data from server.\n" . count( $api_result );
86 } else {
87 if ($status_code == '0') {
88 $sms_result['success'] = 1;
89 $sms_result['api_batch_id'] = $api_result[2];
90 $sms_result['details'] .= "Message sent - batch ID $api_result[2]\n";
91 }
92 else if ($status_code == '1') {
93 $sms_result['success'] = 1;
94 $sms_result['api_batch_id'] = $api_result[2];
95 }
96 else {
97 $sms_result['details'] .= "Error sending: status code [$api_result[0]] description [$api_result[1]]\n";
98 }
99
100
101
102
103
104 }
105 }
106 curl_close( $ch );
107
108 return $sms_result;
109}
110
111
112function unicode_sms ( $username, $password, $message, $msisdn ) {
113 $post_fields = array (
114 'username' => $username,
115 'password' => $password,
116 'message' => string_to_utf16_hex( $message ),
117 'msisdn' => $msisdn,
118 'dca' => '16bit'
119 );
120
121 return make_post_body($post_fields);
122}
123
124function make_post_body($post_fields) {
125 $stop_dup_id = make_stop_dup_id();
126 if ($stop_dup_id > 0) {
127 $post_fields['stop_dup_id'] = make_stop_dup_id();
128 }
129 $post_body = '';
130 foreach( $post_fields as $key => $value ) {
131 $post_body .= urlencode( $key ).'='.urlencode( $value ).'&';
132 }
133 $post_body = rtrim( $post_body,'&' );
134
135 return $post_body;
136}
137
138function character_resolve($body) {
139 $special_chrs = array(
140 'Δ'=>'0xD0', 'Φ'=>'0xDE', 'Γ'=>'0xAC', 'Λ'=>'0xC2', 'Ω'=>'0xDB',
141 'Π'=>'0xBA', 'Ψ'=>'0xDD', 'Σ'=>'0xCA', 'Θ'=>'0xD4', 'Ξ'=>'0xB1',
142 '¡'=>'0xA1', '£'=>'0xA3', '¤'=>'0xA4', '¥'=>'0xA5', '§'=>'0xA7',
143 '¿'=>'0xBF', 'Ä'=>'0xC4', 'Å'=>'0xC5', 'Æ'=>'0xC6', 'Ç'=>'0xC7',
144 'É'=>'0xC9', 'Ñ'=>'0xD1', 'Ö'=>'0xD6', 'Ø'=>'0xD8', 'Ü'=>'0xDC',
145 'ß'=>'0xDF', 'à'=>'0xE0', 'ä'=>'0xE4', 'å'=>'0xE5', 'æ'=>'0xE6',
146 'è'=>'0xE8', 'é'=>'0xE9', 'ì'=>'0xEC', 'ñ'=>'0xF1', 'ò'=>'0xF2',
147 'ö'=>'0xF6', 'ø'=>'0xF8', 'ù'=>'0xF9', 'ü'=>'0xFC',
148 );
149
150 $ret_msg = '';
151 if( mb_detect_encoding($body, 'UTF-8') != 'UTF-8' ) {
152 $body = utf8_encode($body);
153 }
154 for ( $i = 0; $i < mb_strlen( $body, 'UTF-8' ); $i++ ) {
155 $c = mb_substr( $body, $i, 1, 'UTF-8' );
156 if( isset( $special_chrs[ $c ] ) ) {
157 $ret_msg .= chr( $special_chrs[ $c ] );
158 }
159 else {
160 $ret_msg .= $c;
161 }
162 }
163 return $ret_msg;
164}
165
166function make_stop_dup_id() {
167 return 0;
168}
169
170function string_to_utf16_hex( $string ) {
171 return bin2hex(mb_convert_encoding($string, "UTF-16", "UTF-8"));
172}
173
174function xml_to_wbxml( $msg_body ) {
175
176 $wbxmlfile = 'xml2wbxml_'.md5(uniqid(time())).'.wbxml';
177 $xmlfile = 'xml2wbxml_'.md5(uniqid(time())).'.xml';
178
179 $fp = fopen($xmlfile, 'w+');
180
181 fwrite($fp, $msg_body);
182 fclose($fp);
183
184 exec(xml2wbxml.' -v 1.2 -o '.$wbxmlfile.' '.$xmlfile.' 2>/dev/null');
185 if(!file_exists($wbxmlfile)) {
186 print_ln('Fatal error: xml2wbxml conversion failed');
187 return false;
188 }
189
190 $wbxml = trim(file_get_contents($wbxmlfile));
191
192 unlink($xmlfile);
193 unlink($wbxmlfile);
194 return $wbxml;
195}
196
197?>