Skip to content

Instantly share code, notes, and snippets.

@vibbow
Created April 23, 2014 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vibbow/11227890 to your computer and use it in GitHub Desktop.
Save vibbow/11227890 to your computer and use it in GitHub Desktop.
2-WaySMS 调用脚本
<?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