Created
April 23, 2014 18:49
-
-
Save vibbow/11227890 to your computer and use it in GitHub Desktop.
2-WaySMS 调用脚本
This file contains 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 | |
define('SMS_NUMBER', ''); | |
define('SMS_TOKEN', ''); | |
define('SMS_API', 'http://www.2-waysms.com/my/api/sms.php'); | |
$to = ''; | |
$message = ''; | |
$senderid = ''; | |
echo sendsms($to, $message, $senderid); | |
function sendsms($to, $message, $senderid = NULL) { | |
$to = trim($to); | |
$message = trim($message); | |
$senderid = trim($senderid); | |
$to = ltrim($to, '0+'); | |
$message = urlencode($message); | |
$post = array( | |
'token' => SMS_TOKEN, | |
'from' => SMS_NUMBER, | |
'to' => $to, | |
'text' => $message | |
); | |
if (!empty($senderid)) { | |
$post['senderid'] = $senderid; | |
} | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SMS_API); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment