php发送短信接口

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'];
    }
}

你可能感兴趣的:(php)