|
@@ -151,15 +151,18 @@ class Wechat extends Api |
|
@@ -151,15 +151,18 @@ class Wechat extends Api |
151
|
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
|
151
|
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
|
152
|
2.2 由微信回跳后,获取code 和 state 参数,由前端post code给后台
|
152
|
2.2 由微信回跳后,获取code 和 state 参数,由前端post code给后台
|
153
|
返回 token 前端存储 每次请求 放在header里
|
153
|
返回 token 前端存储 每次请求 放在header里
|
154
|
- 2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3
|
|
|
155
|
- 假设 首页地址有参数 store_id activity_id,则表示分销首页,因此
|
|
|
156
|
- 2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 store_id activity_id
|
|
|
157
|
- 2.3.2 已登录 有获取token,再发送请求 store_id activity_id
|
154
|
+ 2.3 分销地址 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
|
|
|
155
|
+ 假设 首页地址有参数 share_id store_id activity_id,则表示分销首页,因此
|
|
|
156
|
+ 2.3.1 未登录 则跳转官方,需要携带分销参数 登录成功后 获取token,再发送请求 share_id store_id activity_id
|
|
|
157
|
+ 2.3.2 已登录 有获取token,再发送请求 share_id store_id activity_id
|
158
|
无地址参数则不发送请求
|
158
|
无地址参数则不发送请求
|
159
|
*/
|
159
|
*/
|
160
|
|
160
|
|
161
|
public function get_user_info_by_code (){
|
161
|
public function get_user_info_by_code (){
|
162
|
$user_id = 0;
|
162
|
$user_id = 0;
|
|
|
163
|
+ if(empty(request()->param('code'))){
|
|
|
164
|
+ return $this->error('非法操作');
|
|
|
165
|
+ }
|
163
|
try{
|
166
|
try{
|
164
|
$app = WehcatModule::getInstance()->initWechat();
|
167
|
$app = WehcatModule::getInstance()->initWechat();
|
165
|
$oauth = $app->oauth;
|
168
|
$oauth = $app->oauth;
|
|
@@ -183,12 +186,10 @@ class Wechat extends Api |
|
@@ -183,12 +186,10 @@ class Wechat extends Api |
183
|
}else{
|
186
|
}else{
|
184
|
Db::name('user')->where($w)->update($save);
|
187
|
Db::name('user')->where($w)->update($save);
|
185
|
}
|
188
|
}
|
186
|
-
|
|
|
187
|
//设置同域下的登录缓存
|
189
|
//设置同域下的登录缓存
|
188
|
$user = Db::name('user')->where($w)->find();
|
190
|
$user = Db::name('user')->where($w)->find();
|
189
|
//登录成功 存储服务器本地
|
191
|
//登录成功 存储服务器本地
|
190
|
$res=$this->auth->direct($user['id']);
|
192
|
$res=$this->auth->direct($user['id']);
|
191
|
-
|
|
|
192
|
//返回给前端
|
193
|
//返回给前端
|
193
|
$user_id = $user['id'];
|
194
|
$user_id = $user['id'];
|
194
|
}catch(\Exception $e){
|
195
|
}catch(\Exception $e){
|
|
@@ -205,7 +206,37 @@ class Wechat extends Api |
|
@@ -205,7 +206,37 @@ class Wechat extends Api |
205
|
}
|
206
|
}
|
206
|
|
207
|
|
207
|
|
208
|
|
208
|
-
|
209
|
+ /**注册 分销关系 如 https://coupon.xp.yn.cn?store_id=1&activity_id=3&share_id=2
|
|
|
210
|
+ * store_id,activity_id
|
|
|
211
|
+ * 关系 user表 id 和 pid
|
|
|
212
|
+ */
|
|
|
213
|
+ public function register_relation(){
|
|
|
214
|
+ //参数
|
|
|
215
|
+ $param = request()->param();
|
|
|
216
|
+ if(empty($param['share_id'])){return $this->error('信息错误');}
|
|
|
217
|
+ if(empty($param['store_id'])){return $this->error('门店信息错误');}
|
|
|
218
|
+ if(empty($param['activity_id'])){return $this->error('活动信息错误');}
|
|
|
219
|
+ $my_user_id = $this->auth->id;
|
|
|
220
|
+ if(empty($my_user_id)){return $this->error('用户信息错误');}
|
|
|
221
|
+ //检测是存在关系
|
|
|
222
|
+ $w['id'] = $my_user_id;
|
|
|
223
|
+ $myInfo = Db::name('user')->where($w)->find();
|
|
|
224
|
+ if(empty($myInfo['pid'])){
|
|
|
225
|
+ //更新分销关系
|
|
|
226
|
+ Db::name('user')->where($w)->update(['id'=>$myInfo['pid']]);
|
|
|
227
|
+ return $this->success('更新关系');
|
|
|
228
|
+ }else{
|
|
|
229
|
+ if($myInfo['pid'] == $param['share_id']){
|
|
|
230
|
+ //是我的上线
|
|
|
231
|
+ return $this->success('是我的上线');
|
|
|
232
|
+ }else{
|
|
|
233
|
+ //不是我的上线
|
|
|
234
|
+ return $this->success('不是我的上线');
|
|
|
235
|
+ }
|
|
|
236
|
+ }
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+
|
209
|
|
240
|
|
210
|
|
241
|
|
211
|
/*
|
242
|
/*
|