Files
heping-api/app/controller/Sms.php
knowpia 96a49d1bd6
2022-09-08 15:23:13 +08:00

44 lines
1.4 KiB
PHP

<?php
namespace app\controller;
use think\facade\Db;
class Sms
{
public function send(){
if(empty($GLOBALS['data']['data']['mobile'])){
return show("手机号不能为空!");
}
$mobileNumber = $GLOBALS['data']['data']['mobile'];
if(!is_mobile_number($mobileNumber)){
return show("手机号不正确!");
}
$timeOut = 60;
$info = Db::name("app_sms")->order("id desc")->where("mobile",$mobileNumber)->find();
if(!empty($info) && (time() - $info['create_time'])<$timeOut){
return show("请在". ($timeOut-(time()-$info['create_time'])) ."后重新发送!");
}
$code = rand(111111,999999);
try {
if(!env("APP_DEBUG")){
$result = \app\tools\Sms::sendmsg($mobileNumber,$code);
if($result['code'] != 1){
return show("运营商接口无法返回!");
}
}else{
$code = "000000";
}
Db::name("app_sms")->insert([
"ipaddress"=>get_client_ip(),
"mobile"=>$mobileNumber,
"code"=>$code,
"create_time"=>time(),
"count"=>0
]);
return show("发送成功!",SUCCESS_CODE);
}catch(\Exception $e){
return show("发送失败,请联系客服人员!");
}
}
}