From 59d104f86e315c389d09430eea17a8f2c10691b8 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 14 Sep 2022 14:14:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Wechat.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 3a04a2d..91b33ef 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -54,7 +54,8 @@ class Wechat public function code() { $this->initWechat(); - $user = $this->app->oauth->user(); + $code = Request::get('code'); + $user = $this->app->oauth->userFromCode($code); $callback = Request::get('callback'); $user = AppUser::where('openid', $user->getId())->find(); @@ -94,9 +95,13 @@ class Wechat $order = \app\model\Order::find($orderId); - if(empty($order)) exit('订单信息不存在'); + if (empty($order)) { + exit('订单信息不存在'); + } - if(\app\model\Order::where(["user_id"=>$order['userid'],"student_id"=>$order['student_id'],"status"=>1])->find()){ + if (\app\model\Order::where([ + "user_id" => $order['userid'], "student_id" => $order['student_id'], "status" => 1 + ])->find()) { exit('已经为该孩子助力过了'); } @@ -147,12 +152,12 @@ class Wechat $order->paid(); //订单支付成功。查询用户信息 - $order_detail = \app\model\Order::where("id",$order->order_id)->find(); + $order_detail = \app\model\Order::where("id", $order->order_id)->find(); //为用户增加助力值 - $zhuLi = env("ZHULI_VALUE")??150; - Db::name("student")->inc("hot",$zhuLi)->where("id",$order_detail->id)->update(); - Db::name("student")->inc("hot_count",1)->where("id",$order_detail->id)->update(); + $zhuLi = env("ZHULI_VALUE") ?? 150; + Db::name("student")->inc("hot", $zhuLi)->where("id", $order_detail->id)->update(); + Db::name("student")->inc("hot_count", 1)->where("id", $order_detail->id)->update(); } else { $fail('Order not exists.'); From 6542c8b817059f6ca463792da91b9e28c9e0af50 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 14 Sep 2022 14:23:10 +0800 Subject: [PATCH 2/4] test --- app/controller/Wechat.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 91b33ef..750e4e6 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -58,6 +58,10 @@ class Wechat $user = $this->app->oauth->userFromCode($code); $callback = Request::get('callback'); + dump($code); + dump($user); + + $user = AppUser::where('openid', $user->getId())->find(); if (! $user) { From 12e8b9c019b0258f92c0d3edc0bc0376261b15bb Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 14 Sep 2022 14:25:04 +0800 Subject: [PATCH 3/4] t --- app/controller/Wechat.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 750e4e6..b836185 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -54,22 +54,18 @@ class Wechat public function code() { $this->initWechat(); - $code = Request::get('code'); - $user = $this->app->oauth->userFromCode($code); - $callback = Request::get('callback'); + $code = Request::get('code'); + $wechatUser = $this->app->oauth->userFromCode($code); + $callback = Request::get('callback'); - dump($code); - dump($user); - - - $user = AppUser::where('openid', $user->getId())->find(); + $user = AppUser::where('openid', $wechatUser->getId())->find(); if (! $user) { $user = AppUser::create([ - 'nickname' => $user->getNickname(), - 'avatar' => $user->getAvatar(), + 'nickname' => $wechatUser->getNickname(), + 'avatar' => $wechatUser->getAvatar(), 'identity' => 1, - 'openid' => $user->getId(), + 'openid' => $wechatUser->getId(), ]); } $tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)]; From c6768229cc86204d374126a0f9e111beb11b2337 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 14 Sep 2022 14:51:51 +0800 Subject: [PATCH 4/4] url --- app/controller/Wechat.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index b836185..8c1a1b0 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -71,7 +71,8 @@ class Wechat $tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)]; $token = authcode(json_encode($tokenData), 'ENCODE'); - return redirect($callback.'?token='.$token); + $spe = str_contains($callback, '?') ? '&' : '?'; + return redirect($callback.$spe.'token='.$token); } /**