<?php/** * 阿里大于短信接口 */namespace Home/Controller;use Think/Controller;class IndexController extends Controller{ //處理數據 public function index(){ $phone = "15222222222"; //傳值:手機號 $number = mt_rand('000000','999999'); //獲取隨機六位驗證碼 $rest = $this->sendsms($phone,$number); $rest_arr = $this->object_to_array($rest); if(!empty($rest_arr['result']) && $rest_arr['result']['err_code'] == '0'){ session('sms_code',$number); echo "1";exit; //success }else{ echo "2"; exit;//fail } } //封裝發送短信api public function sendsms($phone,$number){ require './ThinkPHP/Library/Org/Util/sendsms/To模板發送的內容(阿里大于管理中心配置) $req->setRecNum($phone); //接收短信的號碼 $req->setSmsTemplateCode(""); //上面使用的短信模板id(阿里大于管理中心配置) $resp = $c->execute($req); return $resp; } /** * @todo 將對象轉換成數組 * @param unknown_type $obj * @return unknown */ public function object_to_array($obj){ $_arr = is_object($obj) ? get_object_vars($obj) :$obj; foreach ($_arr as $key=>$val){ $val = (is_array($val) || is_object($val)) ? $this->object_to_array($val):$val; $arr[$key] = $val; } return $arr; }}?>
新聞熱點
疑難解答
圖片精選