edit-sylive-admin_auth

This commit is contained in:
lccsw
2022-10-11 15:02:49 +08:00
parent 4961848b90
commit 6865016393
4 changed files with 70 additions and 8 deletions
+1 -1
View File
@@ -115,7 +115,7 @@ class Act extends Wx {
//获取最新订阅用户
public function subscribemsg_lists(){
$map_kpi_name = [
'browse' => '进入了直播间', 'subscribe' => '订阅了直播提醒'
'browse' => '进入了直播间', 'subscribe' => '预约了直播通知'
];
$a_id = $this->input->get('a_id');
$live_status = $this->input->get('live_status');
+1 -1
View File
@@ -105,7 +105,7 @@ class Admin extends Common{
public function _remap($method){
try{
if(!in_array($method,$this->white_login_method) && !$this->uid){
$ret = $this->set_auth('',1);
$ret = $this->set_auth();
$openid = $ret['openid'];
$row_wechat = $this->user_model->get(['openid' => $openid,'organizationId>'=>0,'status>='=>0]);
if(!$row_wechat){
+56 -1
View File
@@ -28,7 +28,12 @@ class Login extends CI_Controller{
$_SESSION['market_sylive_session'] = ['uid' => $user['userId'],'org_id'=>$user['organizationId']];
$this->show_json('',200,'登录成功');
}else{
$this->load->view('h5/market/sylive/login');
$wx_info = $_SESSION[self::WX_SESSION];
$data['auth_userinfo'] = false;
if($wx_info['nickname'] || $wx_info['headimgurl']){
$data['auth_userinfo'] = true;
}
$this->load->view('h5/market/sylive/login',$data);
}
}
//绑定微信openid
@@ -87,8 +92,58 @@ class Login extends CI_Controller{
exit(json_encode($data));
}
//获取微信用户信息
public function userinfo(){
$ret = $this->set_auth('',1);
if($ret){
$_SESSION[self::WX_SESSION] = $ret;
$url = http_host_com('home').'/h5/market/sylive/login';
redirect($url);
}
}
public function logout(){
$_SESSION['market_sylive_session'] = '';
$this->show_json('',200, '退出成功');
}
/**
* @param $url 回调url地址
* @param $auth 是否信息授权
* @return void
* @throws Hd_exception
*/
protected function set_auth($url='',$auth=0){
$this->load->helper('url');
$this->load->config('wechat');
$config = $this->config->item('liche');
$code = $this->input->get('code');
!$url && $url = http_host_com('home').$_SERVER['REQUEST_URI'];
$auth && $url = $_SERVER['QUERY_STRING'] ? $url."&auth={$auth}" : $url."?auth={$auth}";
if ($code) {//授权码获取微信信息
$auth_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$config['appid']}&secret={$config['appSecret']}&code={$code}&grant_type=authorization_code";
$res = file_get_contents($auth_url);
$ret = json_decode($res, true);
$access_token = $ret['access_token'];
$openid = $ret['openid'];
$unionid = $ret['unionid'];
if($this->input->get('auth') && $access_token){
$u_info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN";
$u_ret = file_get_contents($u_info_url);
$ret = json_decode($u_ret,true);
}
if(!$openid){
debug_log("[error]# " . $res, __FUNCTION__, $this->log_dir);
throw new Hd_exception('获取用户信息失败', 400);
}
return $ret;
} elseif ($auth) {//信息授权获取用户微信昵称/头像
$redirect_uri = urlencode($url);
$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect&forcePopup=true";
redirect($auth_url);
} elseif (!$this->session) {//静默授权获取用户openid
$redirect_uri = urlencode($url);
$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
redirect($auth_url);
}
}
}
+12 -5
View File
@@ -62,7 +62,7 @@
codeTx:'获取验证码',
isSubmiting: false,
rememberMe: true,
auth_userinfo: <?=$auth_userinfo ? 'true':'false'?>,
},
computed: {
@@ -92,6 +92,10 @@
},
getcode() {
if(!this.auth_userinfo){
this.getUserinfo()
return
}
if (!this.codeState) return;
if (!/^1[3456789]\d{9}$/.test(this.telPhone)) {
//alert('请输入正确手机号')
@@ -115,11 +119,14 @@
},'json')
}
},
getUserinfo(){
window.location = "/h5/market/sylive/login/userinfo"
},
submit() {
console.log(this.rememberMe)
if(!this.auth_userinfo){
this.getUserinfo()
return
}
if (this.isSubmiting) return;
if (!/^1[3456789]\d{9}$/.test(this.telPhone)) {
mDialog.msg({