Commit a4e82693 authored by jianghaiming's avatar jianghaiming

Merge branch 'jiang_fix_20210902' into test

parents 12c63ffe 1ed32725
...@@ -24,5 +24,6 @@ class UserException extends BaseException ...@@ -24,5 +24,6 @@ class UserException extends BaseException
10 => 'mysql 异常', 10 => 'mysql 异常',
11 => '头像昵称更新失败', 11 => '头像昵称更新失败',
12 => '绑定手机号保存失败', 12 => '绑定手机号保存失败',
13 => '请求太频繁,稍后重试',
]; ];
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ use Api\PhpUtils\Redis\RedisUtil; ...@@ -15,6 +15,7 @@ use Api\PhpUtils\Redis\RedisUtil;
use Api\PhpServices\JwUser\JwUser; use Api\PhpServices\JwUser\JwUser;
use App\Services\common\CommonService; use App\Services\common\CommonService;
use Api\PhpUtils\Log\FileLog; use Api\PhpUtils\Log\FileLog;
use Api\PhpUtils\Lock\FrequencyLockUtil;
class UserService class UserService
{ {
...@@ -24,13 +25,22 @@ class UserService ...@@ -24,13 +25,22 @@ class UserService
public static function wechatLogin($params) public static function wechatLogin($params)
{ {
$code = !empty($params['code']) ? $params['code'] : '';//小程序授权code $code = !empty($params['code']) ? $params['code'] : '';//小程序授权code
$openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code $openid = !empty($params['openid']) ? $params['openid'] : '';//小程序授权code
if (empty($code) && empty($openid)) { if (empty($code) && empty($openid)) {
FileLog::error("wechatLogin", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com'); FileLog::error("wechatLogin:获取参数为空", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 0]); throw new UserException(['cus' => 0]);
} }
//频率锁
$key = "wx_wechat_login".$params['code'];
$lock = FrequencyLockUtil::isLocked($key);
if ($lock) {
FileLog::error("wechatLogin:请求频繁", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
throw new UserException(['cus' => 13]);
}
//需要授权微信 //需要授权微信
//if (empty($openid)) { //if (empty($openid)) {
$appid = \Yaf\Registry::get('config')->wechat->appid; $appid = \Yaf\Registry::get('config')->wechat->appid;
...@@ -70,7 +80,10 @@ class UserService ...@@ -70,7 +80,10 @@ class UserService
'create_time' => date("Y-m-d H:i:s") 'create_time' => date("Y-m-d H:i:s")
]; ];
$newWechatId = UserWechatBind::save($insert); $sessionKey = !empty($response['session_key']) ? $response['session_key'] : '';
//$newWechatId = UserWechatBind::save($insert);
$newWechatId =UserWechatBind::insertDuplicate($insert, ['session_key' => $sessionKey,'create_time' => date("Y-m-d H:i:s")]);
if (!$newWechatId) { if (!$newWechatId) {
FileLog::error("wechatLogin:登陆创建用户失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com'); FileLog::error("wechatLogin:登陆创建用户失败", json_encode($params, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
FileLog::error("wechatLogin:登陆创建用户失败--insert", json_encode($insert, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com'); FileLog::error("wechatLogin:登陆创建用户失败--insert", json_encode($insert, JSON_UNESCAPED_UNICODE),'','jianghaiming@yidian-inc.com');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment