php分流短信服务商,使用第三方短信服务商云片发送短信(php样例)
//智能匹配模版接口發送樣例
$apikey = "---------------------------"; //請用自己的apikey代替
$mobile = "--------------"; //請用自己的手機號代替
$text="【云片網】親愛的doubiyuzai,您的驗證碼是------。有效期為100000000小時,請盡快驗證";
echo send_sms($apikey,$text,$mobile);
/**
* 智能匹配模版接口發短信
* apikey 為云片分配的apikey
* text 為短信內容
* mobile 為接受短信的手機號
*/
function send_sms($apikey, $text, $mobile){
$url="http://yunpian.com/v1/sms/send.json";
$encoded_text = urlencode("$text");
$mobile = urlencode("$mobile");
$post_string="apikey=$apikey&text=$encoded_text&mobile=$mobile";
return sock_post($url, $post_string);
}
/**
* url 為服務的url地址
* query 為請求串
*/
function sock_post($url,$query){
$data = "";
$info=parse_url($url);
$fp=fsockopen($info["host"],80,$errno,$errstr,30);
if(!$fp){
return $data;
}
$head="POST ".$info['path']." HTTP/1.0\r\n";
$head.="Host: ".$info['host']."\r\n";
$head.="Referer: http://".$info['host'].$info['path']."\r\n";
$head.="Content-type: application/x-www-form-urlencoded\r\n";
$head.="Content-Length: ".strlen(trim($query))."\r\n";
$head.="\r\n";
$head.=trim($query);
$write=fputs($fp,$head);
$header = "";
while ($str = trim(fgets($fp,4096))) {
$header.=$str;
}
while (!feof($fp)) {
$data .= fgets($fp,4096);
}
return $data;
}
?>
總結
以上是生活随笔為你收集整理的php分流短信服务商,使用第三方短信服务商云片发送短信(php样例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2016宁波计算机程序复赛,宁波第31届
- 下一篇: Initialization faile