您的位置:首页 > 编程语言 > PHP开发

php发送短信接口

2018-01-04 15:14 316 查看
public function sendSelfVerifyCode()
{
 $phonenumber =$_POST('phonenumber');
$type = '';
$code =  rand(100000, 999999);
$result = $this->SendSMS($code, $phonenumber,$type); //type 短信模板
//$code =123456;
//$result=1;
if($result==1){
$_SESSION['code']=$code;    //验证码写入session
$_SESSION['time']=  time()+60*3;   //设定验证码 过期时间
$return_data['status'] = $result;
return $return_data;
 }else{
$return_data['msg'] = $result;
return $return_data;
}
}
}

function SendSMS($code ="", $mobile ="", $type="") {
include ('SmsDemo.php'); // 引入短信类,短信服务商提供api
$ucpass = new \SmsDemo();
switch ($type){
case '1': $Template ="SMS_1";break;
case '2': $Template="SMS_2";break;
case '3': $Template="SMS_3";break;
case '4': $Template="SMS_4";break;
}
$response= $ucpass->sendSms($code , $mobile, $Template);   //发送短信
//初始化 $options必填
$data = json_decode(json_encode($response),true);   //先json 加密 在解密 转为PHP数组
if($data['Code']=="OK"){
return 1;
}else{
return $data['code'];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: