Browse Source

fix:授权登录

super-yimizi 4 days ago
parent
commit
3fb9fbe854

+ 3 - 3
application/admin/view/shop/shipper/add.html

@@ -3,13 +3,13 @@
     <div class="form-group">
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
         <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
         <div class="col-xs-12 col-sm-8">
         <div class="col-xs-12 col-sm-8">
-            <input id="c-name" class="form-control" name="row[name]" type="text">
+            <input id="c-name"  data-rule="required" class="form-control" name="row[name]" type="text">
         </div>
         </div>
     </div>
     </div>
     <div class="form-group">
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Shipper_code')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Code')}:</label>
         <div class="col-xs-12 col-sm-8">
         <div class="col-xs-12 col-sm-8">
-            <input id="c-shipper_code" class="form-control" name="row[shipper_code]" type="text">
+            <input id="c-code" data-rule="required" class="form-control" name="row[code]" type="text">
         </div>
         </div>
     </div>
     </div>
     <div class="form-group layer-footer">
     <div class="form-group layer-footer">

+ 2 - 2
application/api/controller/third/Wechat.php

@@ -38,9 +38,9 @@ class Wechat extends Base
         });
         });
 
 
         if ($result) {
         if ($result) {
-            $this->success('登陆成功');
+            $this->success('登陆成功',$result);
         }
         }
-        $this->error('登陆失败');
+        $this->error('登陆失败',$result);
     }
     }
 
 
     // 获取小程序sessionId+自动登录
     // 获取小程序sessionId+自动登录

+ 24 - 9
application/common/Service/Third/Wechat/OpenPlatform.php

@@ -5,31 +5,46 @@ namespace app\common\Service\Third\Wechat;
 use fast\Http;
 use fast\Http;
 use app\common\facade\Wechat;
 use app\common\facade\Wechat;
 use app\common\exception\BusinessException;
 use app\common\exception\BusinessException;
-
+use app\common\Enum\ChannelEnum;
 class OpenPlatform
 class OpenPlatform
 {
 {
     public $wechat;
     public $wechat;
     protected $request;
     protected $request;
     protected $payload;
     protected $payload;
+    protected $platform;
 
 
-    public function __construct($payload)
+    public function __construct($platform,$payload)
     {
     {
         $this->payload = $payload;
         $this->payload = $payload;
         $this->request = request();
         $this->request = request();
-        $this->wechat = Wechat::openPlatform();
+        if($platform == ChannelEnum::CHANNEL_IOS_APP){
+            $this->wechat = Wechat::openIosAppPlatform();
+        }else{
+            $this->wechat = Wechat::openAndroidAppPlatform();
+        }
+        $this->platform = $platform;
+    }
+  /**
+     * 转换平台名称格式
+     * 将前端驼峰命名转换为后端下划线格式
+     *
+     * @param string $platform
+     * @return string
+     */
+    protected function convertPlatformName($platform)
+    {
+        // 将驼峰命名转换为下划线格式
+        return strtolower(preg_replace('/([A-Z])/', '_$1', lcfirst($platform)));
     }
     }
-
     public function login()
     public function login()
     {
     {
         $payload = $this->payload;
         $payload = $this->payload;
         if (empty($payload['code'])) {
         if (empty($payload['code'])) {
             throw new BusinessException('登陆失败');
             throw new BusinessException('登陆失败');
         }
         }
-        $config = shop_config('shop.platform.App');
-        echo "<pre>";
-        print_r($this->wechat);
-        echo "</pre>";
-        exit;
+        // 需要转换   前段穿 DouyinMiniProgram  后端配置是   douyin_mini_program
+        $platformKey = $this->convertPlatformName($this->platform);
+        $config = shop_config('shop.platform.' . $platformKey);
         // 获取accessToken & openid
         // 获取accessToken & openid
         $res = Http::get('https://api.weixin.qq.com/sns/oauth2/access_token', [
         $res = Http::get('https://api.weixin.qq.com/sns/oauth2/access_token', [
             'appid' => $config['app_id'],
             'appid' => $config['app_id'],

+ 7 - 6
application/common/Service/Third/Wechat/Wechat.php

@@ -46,11 +46,12 @@ class Wechat
 
 
         if ($ret) {
         if ($ret) {
             $oauthInfo->login_num += 1;
             $oauthInfo->login_num += 1;
-            return true;
+            $oauthInfo->token = $auth->getToken();
+            return $oauthInfo;
         } else {
         } else {
             $oauthInfo->user_id = 0;
             $oauthInfo->user_id = 0;
             $oauthInfo->save();
             $oauthInfo->save();
-            return false;
+            return $oauthInfo;
         }
         }
     }
     }
 
 
@@ -178,16 +179,16 @@ class Wechat
     {
     {
         switch ($this->platform) {
         switch ($this->platform) {
             case 'officialAccount':
             case 'officialAccount':
-                $service = new OfficialAccount($payload);
+                $service = new OfficialAccount($this->platform,$payload);
                 break;
                 break;
             case 'miniProgram':
             case 'miniProgram':
-                $service = new MiniProgram($payload);
+                $service = new MiniProgram($this->platform,$payload);
                 break;
                 break;
             case ChannelEnum::CHANNEL_IOS_APP:
             case ChannelEnum::CHANNEL_IOS_APP:
-                $service = new OpenPlatform($payload);
+                $service = new OpenPlatform($this->platform,$payload);
                 break;
                 break;
             case ChannelEnum::CHANNEL_ANDROID_APP:
             case ChannelEnum::CHANNEL_ANDROID_APP:
-                $service = new OpenPlatform($payload);
+                $service = new OpenPlatform($this->platform,$payload);
                 break;
                 break;
         }
         }
         if (!isset($service)) throw new BusinessException('平台参数有误');
         if (!isset($service)) throw new BusinessException('平台参数有误');

+ 3 - 1
application/common/library/easywechatPlus/WechatOfficialTemplate.php

@@ -2,6 +2,8 @@
 
 
 namespace app\common\library\easywechatPlus;
 namespace app\common\library\easywechatPlus;
 
 
+use app\common\facade\HttpClient;
+
 /**
 /**
  * 补充 公众号行业模板
  * 补充 公众号行业模板
  */
  */
@@ -26,7 +28,7 @@ class WechatOfficialTemplate extends EasywechatPlus
         $access_token = $this->getAccessToken();
         $access_token = $this->getAccessToken();
 
 
         $add_template_url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template";
         $add_template_url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template";
-        $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
+        $result = HttpClient::request('post', $add_template_url, [
             'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
             'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
             'query' => ["access_token" => $access_token['access_token']],
             'query' => ["access_token" => $access_token['access_token']],
             'headers' => ['Content-Type' => 'application/json']
             'headers' => ['Content-Type' => 'application/json']