国庆节作为中国重要的法定节假日之一,不仅是全民欢庆的时刻,也是商家们进行促销活动的黄金时期。发送营销短信成为许多商家吸引顾客、提高销量的重要手段。
支持免费对接试用乐讯通PaaS平台 找好用的短信平台,选择乐讯通,短信群发|短信平台|群发短信软件|群发短信平台|乐讯通PaaS平台http://yun.loktong.com/login/register/0c61bafb77
<?php
header("Content-type: text/html; charset=utf-8");
/*
文字短信发送demo
视频短信、弹屏闪信、语音短信、国际短信模板发送与文字短信类似
*/
$action='sendtemplate';
$url = 'http://www.lokapi.cn/smsUTF8.aspx';
$username = '******';
$password =strtoupper(md5('*****'));
$token = '*******';
$templateid = '******';
$param = '17712345678|张三|1230';
$timestamp = getMillisecond();
$sign = strtoupper(md5('action='.$action.'&username='.$username.'&password='.$password.'&token='.$token.'×tamp='.$timestamp));
$postData = array
(
'action'=>$action,
'username'=>$username,
'password'=>$password,
'token'=>$token,
'timestamp'=>$timestamp,
'sign'=>$sign,
'rece'=>'json',
'templateid'=>$templateid,
'param'=>$param
);
$result= postSMS($url,$postData);
echo $result;
function postSMS($url,$postData)
{
$row = parse_url($url);
$host = $row['host'];
$port = isset($row['port']) ? $row['port']:80;
$file = $row['path'];
$post = "";
while (list($k,$v) = each($postData))
{
$post .= rawurlencode($k)."=".rawurlencode($v)."&";
}
$post = substr( $post , 0 , -1 );
$len = strlen($post);
$fp = @fsockopen( $host ,$port, $errno, $errstr, 10);
if (!$fp) {
return "$errstr ($errno)\n";
} else {
$receive = '';
$out = "POST $file HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: $len\r\n\r\n";
$out .= $post;
fwrite($fp, $out);
while (!feof($fp)) {
$receive .= fgets($fp, 128);
}
fclose($fp);
$receive = explode("\r\n\r\n",$receive);
unset($receive[0]);
return implode("",$receive);
}
}
function getMillisecond() {
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
}
?>