From 385c0144cccdbe046f403ed279751e2e74886542 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 16 Sep 2022 14:14:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=94=A8=E6=88=B7=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Wechat.php | 16 +++++++++++++--- app/model/AppUserRelation.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 app/model/AppUserRelation.php diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 1a4265b..b600643 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -3,6 +3,7 @@ namespace app\controller; use app\model\AppUser; +use app\model\AppUserRelation; use app\model\Payment; use EasyWeChat\Factory; use EasyWeChat\OfficialAccount\Application; @@ -36,15 +37,16 @@ class Wechat */ public function url(): Json { - $url = $GLOBALS['data']['data']['url']; + $url = $GLOBALS['data']['data']['url']; /// 来源用户, - $fromUid = $GLOBALS['data']['data']['from_uid'] ?? null; + $fromUid = $GLOBALS['data']['data']['from_uid'] ?? 0; if ($fromUid) { AppUser::where('id', $fromUid)->inc('share_times')->update(); } - $redirect = Route::buildUrl('wechat/code', ['callback' => $url]) + $redirect = Route::buildUrl('wechat/code') + ->vars(['callback' => $url, 'parent_id' => $fromUid]) ->suffix(false) ->domain(true); $this->initWechat(); @@ -62,6 +64,7 @@ class Wechat { $this->initWechat(); $code = Request::get('code'); + $parent_id = Request::get('parent_id'); $wechatUser = $this->app->oauth->userFromCode($code); $callback = Request::get('callback'); @@ -74,7 +77,14 @@ class Wechat 'identity' => 0, 'openid' => $wechatUser->getId(), ]); + + AppUserRelation::create([ + 'parent_id' => $parent_id, + 'user_id' => $user->id, + ]); } + + $tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)]; $token = authcode(json_encode($tokenData), 'ENCODE'); $sep = str_contains($callback, '?') ? '&' : '?'; diff --git a/app/model/AppUserRelation.php b/app/model/AppUserRelation.php new file mode 100644 index 0000000..ca0867f --- /dev/null +++ b/app/model/AppUserRelation.php @@ -0,0 +1,14 @@ +