Last active
February 2, 2016 10:08
-
-
Save vihoangson/e89edad45707f7d6e5c1 to your computer and use it in GitHub Desktop.
esms.vn send sms tự động .php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$APIKey = "APIKey"; | |
$SecretKey = "SecretKey"; | |
$YourPhone = "Your phone number"; | |
$Content = "Your content"; | |
// do function | |
send_sms($APIKey,$SecretKey,$YourPhone,$Content); | |
function send_sms($APIKey,$SecretKey,$YourPhone,$Content){ | |
if(!preg_match("/^09\d{8}|01\d{9}$/", $YourPhone)){ | |
echo "Kiem tra khong dung so dien thoai: ".$YourPhone.PHP_EOL; | |
return false; | |
}else{ | |
echo "Kiem tra dung so dien thoai: ".$YourPhone.PHP_EOL; | |
} | |
$ch = curl_init(); | |
$SampleXml = "<RQST>" | |
. "<APIKEY>". $APIKey ."</APIKEY>" | |
. "<SECRETKEY>". $SecretKey ."</SECRETKEY>" | |
. "<ISFLASH>0</ISFLASH>" | |
. "<SMSTYPE>7</SMSTYPE>" | |
. "<CONTENT>"."[No-reply] ". $Content ."</CONTENT>" | |
. "<CONTACTS>" | |
. "<CUSTOMER>" | |
. "<PHONE>". $YourPhone ."</PHONE>" | |
. "</CUSTOMER>" | |
. "</CONTACTS>" | |
. "</RQST>"; | |
curl_setopt($ch, CURLOPT_URL, "http://api.esms.vn/MainService.svc/xml/SendMultipleMessage_V2/" ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt($ch, CURLOPT_POST, 1 ); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $SampleXml ); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); | |
$result=curl_exec ($ch); | |
$xml = simplexml_load_string($result); | |
if ($xml === false) { | |
die('Error parsing XML'); | |
} | |
print_r(compact("YourPhone","Content")); | |
if($xml->CodeResult==100){ | |
echo PHP_EOL."[Da gui thanh cong]".PHP_EOL; | |
return true; | |
} | |
echo PHP_EOL."[Gui khong thanh cong]".PHP_EOL; | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment