短信接口代码接入示例(php)
- 2016-03-10 17:08:19
- roadm
- 3056
- 最后编辑:roadmzhang 于 2016-04-10 13:57:12
* 短信接口文件:
<?
/*--------------------------------
功能: 路幻短信PHP HTTP接口 发送短信
修改日期: 2011-04-08
说明: http://115.28.143.178:8080/sms/Send.do?spId=123&loginName=xxxxx&password=xxxx&content=1233&mobiles=13712345678&subPort=
状态:
1000 发送成功
--------------------------------*/
$uid = '9999'; //用户ID
$userName='test'
$pwd = '9999'; //密码
$mobile = '13912341234,13312341234,13512341234,02122334444'; //号码
$content = '路幻信息PHP HTTP接口'; //内容
$subPort=''
//即时发送
function sendSMS($uid,$userName,$pwd,$mobile,$content,$subPort)
{
$http = 'http://115.28.143.178:8080/sms/Send.do';
$data = array
(
'spId'=>$uid, //用户ID
'loginName'=>$userName, //用户账户名
'password'=>$pwd, //密码
'mobile'=>$mobile, //号码
'content'=>$content, //内容
'subPort'=>$subPort, //子扩展号
);
$re= postSMS($http,$data); //POST方式提交
if( trim($re) == '1000' )
{
return "发送成功!";
}
else
{
return "发送失败! 状态:".$re;
}
}
function postSMS($url,$data='')
{
$row = parse_url($url);
$host = $row['host'];
$port = $row['port'] ? $row['port']:80;
$file = $row['path'];
while (list($k,$v) = each($data))
{
$post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转URL标准码
}
$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);
}
}
?> 发表评论
Update Required
To play the media you will need to either update your browser to a recent version or update your Flash plugin.