You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SendMsgCodeController extends Controller
|
|
{
|
|
//创建验证码
|
|
public function SendMsgCode(Request $request)
|
|
{
|
|
$mobile = request('mobile');
|
|
//查找相同手机号1分钟内是否发送过
|
|
$code = DB::table('send_code')->where('mobile', $mobile)->where('created_at', '>=', date('Y-m-d H:i:s', time() - 60))->first();
|
|
if ($code) {
|
|
return \Yz::echoError1("操作太频繁,请稍后再试");
|
|
}
|
|
$code = rand(100000, 999999);
|
|
//获取当前时间5分钟后的日期时间
|
|
$end_time = date('Y-m-d H:i:s', time() + 300);
|
|
$i=DB::table('send_code')->insert([
|
|
'mobile' => $mobile,
|
|
'code' => $code,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'end_time' => $end_time
|
|
]);
|
|
if ($i) {
|
|
$aspnet=new AspNetZhuanController();
|
|
$aspnet::SendYanZhengMaCode(1,$mobile,$code);
|
|
return \Yz::Return(true,"发送成功",[]);
|
|
} else {
|
|
return \Yz::echoError1("发送失败");
|
|
}
|
|
|
|
}
|
|
//验证验证码
|
|
public function CheckMsgCode(){
|
|
$mobile = request('mobile');
|
|
$code = request('code');
|
|
$u = DB::table('send_code')
|
|
->where('mobile', $mobile)
|
|
->where('code', $code)
|
|
->where('end_time', '>=', date('Y-m-d H:i:s'))
|
|
->where(['status' => 1])
|
|
->update(['status' => 2]);
|
|
if($u){
|
|
return \Yz::Return(true,"验证成功",['data'=>$code]);
|
|
}else{
|
|
return \Yz::echoError1("验证码无效");
|
|
}
|
|
}
|
|
}
|