fixed
This commit is contained in:
@@ -144,54 +144,37 @@ class Users extends BaseHttpApi
|
||||
*/
|
||||
function login()
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$clientid = input('clientid');
|
||||
if(empty($clientid)){
|
||||
return json(Tools::set_fail('clientid error'));
|
||||
}
|
||||
$code = input('code');
|
||||
if(empty($code)){
|
||||
return json(Tools::set_fail('CODE参数错误'));
|
||||
|
||||
$username = input('username');
|
||||
if(empty($username)){
|
||||
return json(Tools::set_fail('参数错误:1'));
|
||||
}
|
||||
$wxconfig = get_wechat_config();
|
||||
|
||||
Tools::log_to_write_txt(['微信授权,start'=>input(),'$wxconfig'=>$wxconfig]);
|
||||
$res = (new UserAuth($wxconfig))->usrAccessTokenApplet($code);
|
||||
Tools::log_to_write_txt(['微信授权,end'=>$res]);
|
||||
|
||||
|
||||
$openid = $res['openid'];
|
||||
|
||||
$user = Db::table(TabConf::$fa_users)->where('openid',$openid)->find();
|
||||
$password = input('password');
|
||||
if(empty($password)){
|
||||
return json(Tools::set_fail('参数错误:2'));
|
||||
}
|
||||
$user = Db::table(TabConf::$fa_users)
|
||||
->where('phone',$username)
|
||||
->find();
|
||||
if(empty($user)){
|
||||
|
||||
$data = [
|
||||
'openid'=>$openid,
|
||||
'nickname'=>Tools::rand_str(),
|
||||
'headimage'=>'',
|
||||
'hint_num'=>3,
|
||||
'clientid'=>$clientid,
|
||||
'user_type'=>'wechat'
|
||||
];
|
||||
//新增一个用户
|
||||
$id = Db::table(TabConf::$fa_users)
|
||||
->insertGetId($data);
|
||||
$data['id'] = $id;
|
||||
}else{
|
||||
Db::table(TabConf::$fa_users)
|
||||
->where('openid',$openid)
|
||||
->data(['clientid'=>$clientid])//更新登录状态
|
||||
->update();
|
||||
$data = $user;
|
||||
return json(Tools::set_fail('参数错误'));
|
||||
}
|
||||
if($password != $user['password']){
|
||||
return json(Tools::set_fail('密码错误'));
|
||||
}
|
||||
|
||||
session('api_user_info',$data);
|
||||
session('api_user_info',$user);
|
||||
|
||||
Db::commit();
|
||||
return json(Tools::set_ok('ok',$res));
|
||||
unset($user['password']);
|
||||
|
||||
|
||||
return json(Tools::set_ok('ok',$user));
|
||||
}catch (\Exception $e){
|
||||
Db::rollback();
|
||||
Tools::log_to_write_text([
|
||||
'error'=>'微信授权异常。'.$e->getMessage(),
|
||||
'input'=>input(),
|
||||
|
||||
Reference in New Issue
Block a user