创蓝短信PHP发送demo(改了域名)

冬冬466 2016-10-08 04:16:26


<?php
header('Content-Type:text/html;charset=utf-8');



function http_request($url,$data = null){

if(function_exists('curl_init')){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);

if (!empty($data)){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);//http 使用curl发起https请求
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); //
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);


$result=preg_split("/[,\r\n]/",$output);
print_r($result);
if(isset($result[1]) && $result[1]==0){
return "短信服务启用成功";
}else{
return "短信服务启用失败".$result[1];
}
}elseif(function_exists('file_get_contents')){

$output=file_get_contents($url.$data);
$result=preg_split("/[,\r\n]/",$output);

if($result[1]==0){
return "success";
}else{
return "error".$result[1];
}


}else{
return false;
}

}

session_start();

$code = rand(100000,999999);
$data ="您好,您的验证码是".$code." , 请不要告诉别人!【创蓝文化】";
$_SESSION['code'] = $code;
$post_data = array();
$post_data['account'] ="API账号";
$post_data['pswd'] = "API密码";

$phone=$_POST["Tel"];//获取手机号码
if(!preg_match('/^[0-9]{11,13}$/',$phone))
{
print("error");
exit();
}

$post_data['mobile'] =$phone;
$post_data['msg']="$data";
$post_data['needstatus']='true';
$url='https://zapi.253.com/msg/HttpBatchSendSM?';
$res=http_request($url,http_build_query($post_data,' ','&')); //密码无法读取的时候使用
var_dump($res);


...全文
843 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_31188743 2017-04-19
  • 打赏
  • 举报
回复
前段时间刚刚写过类似的。
素材火 2017-03-18
  • 打赏
  • 举报
回复
谢谢分享,已经整合到短信中:http://www.sucaihuo.com/php/1314.html

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧