<?
header("Content-Type: text/html;charset=utf-8");
$user=URLEncode('user');
$key='接口鉴权KEY';
$mobile='13812345678';
//发送短信的内容,签名前置:【珑云】验证码:8888
$content='验证码:8888';
$url='http://api.smslong.cn';
$post='user='.$user.'&key='.$key.'&mobile='.$mobile.'&content='.$content;
$HttpState = curl_request($url,$post);
/*
$HttpState=短信发送提交后的状态回执
建议把$mobile,$content,$HttpState值写入数据库
*/
echo $HttpState; //打印输出短信发送状态回执
function curl_request($url,$post=''){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //有请求的返回值
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); //重定向时
curl_setopt($curl, CURLOPT_NOSIGNAL,1); //以毫秒为超时计时单位一定要设置这个
curl_setopt($curl, CURLOPT_TIMEOUT_MS,2000); //2秒超时PHP 5.2.3起可使用
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);//http接口执行失败
}
curl_close($curl);
return $data; //返回数据
}