composer阿里云短信服务不支持传参为数值--为2017年短信接口,2018阿里云有更新http://www.cnblogs.com/q1104460935/p/8916096.html
composer 阿里云短信服务使用 xuying/aliyun_mns 更新到2017年初,不再更新
/**
* TODO SMS SERVICE
* @param $tmp
* @param $moblie
* @param $name
* @param int $len
* @return int
*/
private function mns($tmp,$moblie,$name,$len=4)
{
$count=[];
for($i =0;$i<$len; $i++){
$count[] =rand(1, 9);
}
$captcha = (int) implode("",$count);
$data = [
"log_msg"=>$name,
"log_captcha"=>$captcha,
"log_phone"=>$moblie
];
if($this->validate($data,"SmsLogs") !== true){
return 0;
}
$new_mns = new Mns((array) Config::get('mns'));
$statua = $new_mns->run($tmp,[$moblie=>array('code'=>(string) $data['log_captcha'],"product" => $data['log_msg'])]);
if(!method_exists($statua,'isSucceed')){
return 0;
}
try{
SmsLog::create($data);;
return 1;
}catch (Exception $e){
return 0;
}
}
以下为发送成功返回对象
object(AliyunMNS\Responses\PublishMessageResponse)#44 (4) {
["succeed":protected] => bool(true)
["statusCode":protected] => int(201)
["messageId":protected] => string(40) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["messageBodyMD5":protected] => string(32) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
但是并没有短信收到,原因为模板$code字段为数字类型了,
-------------------------分享短信发送代码:--------------------------
//
TODO 短信验证配置=====开启&& 关闭注释=========
if(!$mns = $this->mns("register",$req['member_mobile'],$req['member_name'],4)){
return json(msg_array(0,'请求获取验证码失败',[]),400);
}
return json(msg_array(1,'请求获取验证码成功',[]),200);
--------------------------- ----------------------------------------------------
(string)转换后,成功短信发送了;