20,359
社区成员
发帖
与我相关
我的任务
分享
<?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);