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] =&gt; bool(true)
  ["statusCode":protected] =&gt; int(201)
  ["messageId":protected] =&gt; string(40) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  ["messageBodyMD5":protected] =&gt; 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)转换后,成功短信发送了;

posted @   徐锅  阅读(208)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南

点击右上角即可分享
微信分享提示