96 lines
2.9 KiB
PHP
96 lines
2.9 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021.06.23
|
|
* Time: 14:08
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
class User extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array('get_ukey');//登录白名单
|
|
$this->majia_white = array('get_ukey', 'get');//超级管理员披上马甲可操作权限
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg =array();//授权微信信息
|
|
|
|
}
|
|
|
|
/**
|
|
* 获取ukey
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function get_ukey(){
|
|
$code = $this->input_param('code');
|
|
$mobile = $this->input_param('mobile');
|
|
$sms_code = $this->input_param('sms_code');
|
|
|
|
if(!$code||!$mobile||!$sms_code){
|
|
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
//判断验证码
|
|
$mc = &load_cache();
|
|
$key = "licheb_login_code_".$mobile;
|
|
$cache_code = $mc->get($key);
|
|
if($sms_code!=$cache_code){
|
|
throw new Exception('验证码错误', API_CODE_FAIL);
|
|
}
|
|
$user = $this->app_user_model->get(['mobile'=>$mobile,'status>'=> -1]);
|
|
if(!$user){
|
|
throw new Exception('用户不存在', API_CODE_FAIL);
|
|
}
|
|
if(!$user['status']){
|
|
throw new Exception('该账号已停用', API_CODE_FAIL);
|
|
}
|
|
$session = $this->wx_session($code);
|
|
//print_r($session);
|
|
if(!$session['session_key']){
|
|
throw new Exception('登录失败', API_CODE_FAIL);
|
|
}
|
|
|
|
$uid = $user['id'];
|
|
if(!$user['openid']){ //未绑定微信
|
|
$upd = [
|
|
'openid' => $session['openid']
|
|
];
|
|
$session['unionid'] && $upd['unionid'] = $session['unionid'];
|
|
$ret = $this->app_user_model->update($upd, array('id' => $uid));
|
|
if(!$ret){
|
|
debug_log("[error]# code:{$code}; ".$this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
throw new Exception('授权用户信息失败', API_CODE_FAIL);
|
|
}
|
|
}
|
|
|
|
$udata = array('uid' => $uid, 'session_key' => $session['session_key']);
|
|
$ukey = $this->refresh_login($udata);
|
|
|
|
return array('ukey' => $ukey);
|
|
}
|
|
|
|
/**
|
|
* 用户信息
|
|
* @return array
|
|
*/
|
|
protected function get(){
|
|
$uid = $this->session['uid'];
|
|
|
|
$user = $this->app_user_model->get(array('id' => $uid));
|
|
|
|
$data = array(
|
|
'uid' => $uid,
|
|
'uname' => $user['uname'],
|
|
'mobile' => $user['mobile'],
|
|
'group_id' => $user['group_id']
|
|
);
|
|
|
|
return $data;
|
|
}
|
|
|
|
}
|