...
|
...
|
@@ -151,15 +151,18 @@ class Wechat extends Api |
|
|
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
|
|
|
2.2 由微信回跳后,获取code 和 state 参数,由前端post code给后台
|
|
|
返回 token 前端存储 每次请求 放在header里
|
|
|
2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3
|
|
|
假设 首页地址有参数 store_id activity_id,则表示分销首页,因此
|
|
|
2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 store_id activity_id
|
|
|
2.3.2 已登录 有获取token,再发送请求 store_id activity_id
|
|
|
2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
|
|
|
假设 首页地址有参数 share_id store_id activity_id,则表示分销首页,因此
|
|
|
2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 share_id store_id activity_id
|
|
|
2.3.2 已登录 有获取token,再发送请求 share_id store_id activity_id
|
|
|
无地址参数则不发送请求
|
|
|
*/
|
|
|
|
|
|
public function get_user_info_by_code (){
|
|
|
$user_id = 0;
|
|
|
if(empty(request()->param('code'))){
|
|
|
return $this->error('非法操作');
|
|
|
}
|
|
|
try{
|
|
|
$app = WehcatModule::getInstance()->initWechat();
|
|
|
$oauth = $app->oauth;
|
...
|
...
|
@@ -183,12 +186,10 @@ class Wechat extends Api |
|
|
}else{
|
|
|
Db::name('user')->where($w)->update($save);
|
|
|
}
|
|
|
|
|
|
//设置同域下的登录缓存
|
|
|
$user = Db::name('user')->where($w)->find();
|
|
|
//登录成功 存储服务器本地
|
|
|
$res=$this->auth->direct($user['id']);
|
|
|
|
|
|
//返回给前端
|
|
|
$user_id = $user['id'];
|
|
|
}catch(\Exception $e){
|
...
|
...
|
@@ -207,6 +208,38 @@ class Wechat extends Api |
|
|
|
|
|
|
|
|
|
|
|
/**注册 分销关系 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
|
|
|
* store_id,activity_id
|
|
|
* 关系 user表 id 和 pid
|
|
|
*/
|
|
|
public function register_relation(){
|
|
|
//参数
|
|
|
$param = request()->param();
|
|
|
if(empty($param['share_id'])){return $this->error('信息错误');}
|
|
|
if(empty($param['store_id'])){return $this->error('门店信息错误');}
|
|
|
if(empty($param['activity_id'])){return $this->error('活动信息错误');}
|
|
|
$my_user_id = $this->auth->id;
|
|
|
if(empty($my_user_id)){return $this->error('用户信息错误');}
|
|
|
//检测是存在关系
|
|
|
$w['id'] = $my_user_id;
|
|
|
$myInfo = Db::name('user')->where($w)->find();
|
|
|
if(empty($myInfo['pid'])){
|
|
|
//更新分销关系
|
|
|
Db::name('user')->where($w)->update(['id'=>$myInfo['pid']]);
|
|
|
return $this->success('更新关系');
|
|
|
}else{
|
|
|
if($myInfo['pid'] == $param['share_id']){
|
|
|
//是我的上线
|
|
|
return $this->success('是我的上线');
|
|
|
}else{
|
|
|
//不是我的上线
|
|
|
return $this->success('不是我的上线');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
...
|
...
|
|