You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.2 KiB
60 lines
1.2 KiB
<?php
|
|
|
|
namespace app\model;
|
|
|
|
use think\Model;
|
|
|
|
class WechatSms extends Model
|
|
{
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public static function getCode($wechat_user_id)
|
|
{
|
|
$code = rand(000000,999999);
|
|
|
|
$result = self::getValidCode($code,$wechat_user_id);
|
|
if ($result) {
|
|
return self::getCode($wechat_user_id);
|
|
}
|
|
|
|
return $code;
|
|
}
|
|
|
|
public static function getValidCode($code,$wechat_user_id)
|
|
{
|
|
$where = [
|
|
['code', '=', $code],
|
|
['wechat_user_id', '=', $wechat_user_id],
|
|
['create_time', '>=', time() - (10*60)],
|
|
];
|
|
|
|
return (new self())->where($where)->value('wechat_user_id');
|
|
}
|
|
|
|
|
|
public static function getValidUser($wechat_user_id)
|
|
{
|
|
$where = [
|
|
['wechat_user_id', '=', $wechat_user_id],
|
|
['create_time', '>=', time() - 60],
|
|
];
|
|
|
|
return (new self())->where($where)->value('create_time');
|
|
}
|
|
|
|
public static function addSmsCode($wechat_user_id,$code): bool
|
|
{
|
|
|
|
$data = [
|
|
'wechat_user_id' => $wechat_user_id,
|
|
'code' => $code,
|
|
'create_time' => time()
|
|
];
|
|
|
|
return (new self())->save($data);
|
|
}
|
|
|
|
|
|
}
|