列如:融云短信通
1.生成6為的隨機(jī)數(shù)字驗(yàn)證碼: ?數(shù)據(jù)源123467890?
```
$code='';
$charset='1234567890';
$_len= strlen($charset)-1;
for($i=0;$i<6;++$i){
$code.=$charset[mt_rand(0,$_len)];
}
$m3_result=$sendTemplateSMS->sendTemplateSMS($phone,array($code,60),1)
如果返回的狀態(tài) == 0
if($m3_result->status==0){
$tempPhone= TempPhone::where('phone',$phone)->first();
if($tempPhone==null){
$tempPhone=newTempPhone;
}
$tempPhone->phone=$phone;
$tempPhone->code=$code;
$tempPhone->deadline= date('Y-m-d H-i-s', time()+60*60);
$tempPhone->save();
}
存入數(shù)據(jù)庫
return$m3_result->toJson();
類中定義2個公共屬性 ?public $status;public $msg;
$m3_result->$status = 1;
#m3_result->$msg = '發(fā)送失敗';
$m3_result->toJson; (toJson方法就是把這個2個參數(shù)的值 ?以json方式返回)
```