From 81708abe839652b8199e32ac489bf6045ac45615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=96=E5=8F=AB?= <392494244@qq.com> Date: Fri, 8 Dec 2023 10:47:13 +0800 Subject: [PATCH] 1 --- app/api/controller/food/Controller.php | 32 ++++++++++++++++++-------- app/api/controller/food/User.php | 17 +++++++++++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/app/api/controller/food/Controller.php b/app/api/controller/food/Controller.php index 51f21a4..ad93cf0 100644 --- a/app/api/controller/food/Controller.php +++ b/app/api/controller/food/Controller.php @@ -1,8 +1,11 @@ getApplet(); //初始化应用数据 } + /** * 初始化应用数据 */ private function getApplet() { - if (!$applet_id = $this->request->param('applet_id')) { - die(hema_json(['code' => 0, 'msg' => '缺少必要的参数:applet_id'])); - } - if($mp = $this->request->param('mp')){ +// if (!$applet_id = $this->request->param('applet_id')) { +// die(hema_json(['code' => 0, 'msg' => '缺少必要的参数:applet_id'])); +// } + if ($mp = $this->request->param('mp')) { $this->mp = $mp; - }else{ + } else { $this->mp = 'weixin'; } - $this->applet_id = (int)$applet_id; + $this->applet_id = (int)10001; $this->user_id = (int)$this->request->param('user_id'); $this->shop_id = (int)$this->request->param('shop_id'); $this->location = (string)$this->request->param('location'); } + /** * 获取当前用户信息 */ @@ -53,6 +59,7 @@ class Controller extends BaseController } return $user; } + /** * 返回封装后的 API 数据到客户端 */ @@ -60,6 +67,7 @@ class Controller extends BaseController { return json(compact('code', 'msg', 'data')); } + /** * 返回操作成功json - 有返回值 */ @@ -67,13 +75,15 @@ class Controller extends BaseController { return $this->renderJson(self::JSON_SUCCESS_STATUS, $msg, $data); } - /** + + /** * 返回操作成功json - 无返回值 */ protected function renderMsg($msg = 'success') { return $this->renderJson(self::JSON_SUCCESS_STATUS, $msg); } + /** * 返回操作失败json */ @@ -81,6 +91,7 @@ class Controller extends BaseController { return $this->renderJson(self::JSON_ERROR_STATUS, $msg, $data); } + /** * 获取post数据 (数组) */ @@ -88,6 +99,7 @@ class Controller extends BaseController { return $this->request->post(is_null($key) ? '' : $key . '/a'); } + /** * 获取post数据 (数组) * @param $key @@ -96,5 +108,5 @@ class Controller extends BaseController protected function postForm($key = 'form') { return $this->postData($key); - } + } } \ No newline at end of file diff --git a/app/api/controller/food/User.php b/app/api/controller/food/User.php index 2d6f8db..8b3f37a 100644 --- a/app/api/controller/food/User.php +++ b/app/api/controller/food/User.php @@ -171,16 +171,27 @@ class User extends Controller return $this->renderSuccess($data, '成功'); } + public function wxCode() + { + $appid = 'wx89c12dd426a55a2e'; + $app_secret = '33e66bcf944f9810abbb5ddd7825403d'; + $redirect_uri=$this->request->host().'api/food.user/getWxUserCoupon'; + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; + + + } + + public function wxLogin() { - $post = $this->request->post(); - if (empty($post['code'])) { + $get = $this->request->get(); + if (empty($get['code'])) { return $this->renderError('授权失败'); } $appid = 'wx89c12dd426a55a2e'; $app_secret = '33e66bcf944f9810abbb5ddd7825403d'; - $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$app_secret&code={$post['code']}&grant_type=authorization_code"; + $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$app_secret&code={$get['code']}&grant_type=authorization_code"; $result = json_decode(Http::get($url), true); if (isset($result['access_token'])) { $access_token = $result['access_token'];