1.要拼接接收的手机号和短信
public function ndcode() { $parpm无犯罪记录证明样本 = input(); $valist = $this->validate($parpm, [ 'phone' => 'require|regex:1[3-9]\d{9}' ]); if ($valist !== true) { $res = [ 'code' => 400, 'msg' => $valist ]; return json($res); die; } $timer = cache('register_time_' . $parpm['phone']); if (time() - $timer < 60) { $rs = [ 关雎 'code' => '500', 'msg' => '发送太过频繁' ]; echo json_encode($rs); die; } $co = mt_rand(1000, 9999); $code = '%2里脊肉饼3code%23%3d' . $co; //发送短信验证// $resule=ndmsg($parpm['phone'],$code); $resule = tru迅雷上网加速器e; if ($resule === true) { cache('register_code_' . $parpm['phone'], $co, 180); cache('register_time_' . $parpm['phone'], time(), 180); $re = [ 'code' => 200, 'msg' => '短信发送成功', 'data' => "$code" ]; echo json_encode($re); die; } el { $re = [ 'code' => 400, 'msg' => $resule ]; echo json_encode($re); die; } }
2.拼接要发送短信的要求
if(!function_exists('ndmsg')){ function ndmsg($phone,$code){ $gateway=config('msg.gateway'); $appkey=config('msg.appkey'); $tpl_id=config('msg.tpl_id'); $url=$gateway.'?mobile='.$phone.'&tpl_id='.$tpl_id.'&tpl_value='.$code.'&key='.$appkey; $res=curl_require($url,fal,[],fal); if(!$res){ return '请求失败'; } $arr=json_decode($res,true); if(ist($arr['code'])&&$arr['code']==10000){ return true; }el{ return fal; } }}
3.向第三方发送请求
if(!function_exists('curl_require')){ function curl_require($url,$post=true,$parpm=[],$https=fal){ 热爱作文 $ch=curl_init($url); if($post){ curl_topt($ch,curlopt_port,true); curl_topt($ch,curlopt_postfields,$parpm); } if($https){ curl_topt($ch,curlopt_ssl_verifypeer,fal); } curl_topt($ch,curlopt_returntransfer,true); $res=curl_exec($ch); curl_clo($ch); return $res; }}
本文发布于:2023-04-07 12:19:38,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/9423a436e2766f4ad2749a7bf4e39ef0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP发送短信.doc
本文 PDF 下载地址:PHP发送短信.pdf
留言与评论(共有 0 条评论) |