From b3a42457812dfe09a8fb6bd031678e62402bf0c2 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 19 May 2023 14:45:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=91=E4=BB=93?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=9F=A5=E8=AF=A2=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/StoreMicro.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index d1a5a940..93476785 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -6,7 +6,7 @@ use crmeb\basic\BaseController; class StoreMicro extends BaseController { - function seach_bar_code($code='',$name='',$mer_id){ + function seach_bar_code($mer_id,$code='',$name=''){ $category_id=Db::name('merchant')->where('mer_id',$mer_id)->value('category_id'); $mer_id=Db::name('merchant')->where('category_id',$category_id)->where('type_id',13)->value('mer_id'); if($code!=''){ From a54235695baac495b651ce7eb1da8ded4d47c2c1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 19 May 2023 17:29:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/StoreMicro.php | 11 +++++++++++ route/api.php | 1 + 2 files changed, 12 insertions(+) diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index 93476785..4b68b53b 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -28,6 +28,17 @@ class StoreMicro extends BaseController return app('json')->success($store_product); } + public function ProductDetails($id){ + $find=Db::name('store_product')->where('product_id',$id) + ->withAttr('attr_value',function ($value,$data){ + return Db::name('store_product_attr_value')->where('product_id',$data['product_id'])->select(); + }) + ->find(); + return app('json')->success(['list'=>$find]); + + + } + public function eadtProduct(){ $product_id = $this->request->param('id', 0); if ($product_id==0) return app('json')->fail('商品id不能为空'); diff --git a/route/api.php b/route/api.php index 0f21917c..8f410d9a 100644 --- a/route/api.php +++ b/route/api.php @@ -26,6 +26,7 @@ Route::group('api/', function () { Route::group('micro', function () { Route::get('seach_bar_code', '/seach_bar_code'); + Route::get('product_details', '/ProductDetails'); Route::post('eadt_product', '/eadtProduct'); })->prefix('api.store.product.StoreMicro'); From 63bee8d493737456e0b9838aeae524f4cbab7e7d Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 19 May 2023 18:22:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 57 +++++++++++++++++++++++++++++++++++++ route/api.php | 2 ++ 2 files changed, 59 insertions(+) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 8eb39a98..a15a9af2 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -309,6 +309,63 @@ class Auth extends BaseController return app('json')->success($userRepository->returnToken($user[1], $tokenInfo)); } + /** + * 手机号用户绑定微信账号 + * @param UserRepository $repository + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function bindMp(UserRepository $repository) + { + list($code, $post_cache_key, $phone) = $this->request->params([ + 'code', + 'cache_key', + 'phone', + ], true); + $userInfoCong = Cache::get('eb_api_code_' . $code); + if (!$code && !$userInfoCong) + return app('json')->fail('授权失败,参数有误'); + $miniProgramService = MiniProgramService::create(); + if ($code && !$userInfoCong) { + try { + $userInfoCong = $miniProgramService->getUserInfo($code); + Cache::set('eb_api_code_' . $code, $userInfoCong, 86400); + } catch (Exception $e) { + return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]); + } + } + $data = $this->request->params([ + ['spread_spid', 0], + ['spread_code', ''], + ['iv', ''], + ['encryptedData', ''], + ]); + try { + //解密获取用户信息 + $userInfo = $miniProgramService->encryptor($userInfoCong['session_key'], $data['iv'], $data['encryptedData']); + } catch (Exception $e) { + if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败'); + throw $e; + } + if (!$userInfo) return app('json')->fail('openid获取失败'); + if (!isset($userInfo['openId'])) $userInfo['openId'] = $userInfoCong['openid'] ?? ''; + $userInfo['unionId'] = $userInfoCong['unionid'] ?? $userInfo['unionId'] ?? ''; + if (!$userInfo['openId']) return app('json')->fail('openid获取失败'); + /** @var WechatUserRepository $make */ + $make = app()->make(WechatUserRepository::class); + $user = $make->syncRoutineUser($userInfo['openId'], $userInfo, false); + if (!$user) { + return app('json')->fail('授权失败'); + } + $userInDb = $repository->accountByUser($phone); + if ($userInDb->save(['wechat_user_id' => $user[0]['wechat_user_id']]) === false) { + return app('json')->fail('授权失败'); + } + return app('json')->success(); + } + public function getCaptcha() { $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4)); diff --git a/route/api.php b/route/api.php index 0f21917c..c6e86628 100644 --- a/route/api.php +++ b/route/api.php @@ -595,6 +595,8 @@ Route::group('api/', function () { Route::get('auth/wechat', 'api.Auth/auth'); //小程序授权 Route::post('auth/mp', 'api.Auth/mpAuth'); + //绑定小程序账号 + Route::post('auth/bindMp', 'api.Auth/bindMp'); //app授权 Route::post('auth/app', 'api.Auth/appAuth'); //apple授权