Browse Source

fix:微信小程序

super-yimizi 1 month ago
parent
commit
25058155bf
2 changed files with 37 additions and 19 deletions
  1. 15 14
      application/api/controller/Goods.php
  2. 22 5
      application/common/library/message/Mini.php

+ 15 - 14
application/api/controller/Goods.php

@@ -273,7 +273,7 @@ class Goods extends Base
     public function getWxCode()
     {
         $goods_id = $this->request->post('goods_id');
-        $version = $this->request->post('version', 'release');
+        $version = $this->request->post('version', 'trial');
         if (empty($goods_id)) {
             $this->error('参数错误');
         }
@@ -298,20 +298,21 @@ class Goods extends Base
                 \think\Log::write($e->getMessage());
                 $this->error("获取微信二维码失败!");
             }
-        } else {
-            $config = get_addon_config('shop');
-            if ($config['wxapp']) {
-                $localFile = ROOT_PATH . 'public' . $config['wxapp'];
-                if (is_file($localFile)) {
-                    $resource = file_get_contents($localFile);
-                } else {
-                    $resource = Http::get(cdnurl($config['wxapp'], true));
-                }
-            }
-            if (config('app_debug')) {
-                Log::write($fileStream);
-            }
         }
+        // } else {
+        //     $config = get_addon_config('shop');
+        //     if ($config['wxapp']) {
+        //         $localFile = ROOT_PATH . 'public' . $config['wxapp'];
+        //         if (is_file($localFile)) {
+        //             $resource = file_get_contents($localFile);
+        //         } else {
+        //             $resource = Http::get(cdnurl($config['wxapp'], true));
+        //         }
+        //     }
+        //     if (config('app_debug')) {
+        //         Log::write($fileStream);
+        //     }
+        // }
         if (!$resource) {
             Log::write($fileStream);
             $this->error("获取二维码失败!");

+ 22 - 5
application/common/library/message/Mini.php

@@ -8,18 +8,35 @@ use GuzzleHttp\Psr7\Response;
 use think\Cache;
 use think\Log;
 use think\Config;
-
+use app\common\Service\ShopConfigService;
+use app\common\Enum\ChannelEnum;
 class Mini
 {
     private $appId = '';
     private $appSecret = '';
 
-    public function __construct()
+    public function __construct($platform = ChannelEnum::CHANNEL_WECHAT_MINI_PROGRAM)
     {
-        $config = get_addon_config('shop');
-        $this->appId = $config['wx_appid'];
-        $this->appSecret = $config['wx_app_secret'];
+         // 需要转换   前段穿 DouyinMiniProgram  后端配置是   douyin_mini_program
+        $platformKey = $this->convertPlatformName($platform);
+        $platformConfig = ShopConfigService::getConfigs('shop.platform.' . $platformKey);
+ 
+        $this->appId     = $platformConfig['app_id'] ?? '';
+        $this->appSecret = $platformConfig['secret'] ?? '';
     }
+         /**
+     * 转换平台名称格式
+     * 将前端驼峰命名转换为后端下划线格式
+     *
+     * @param string $platform
+     * @return string
+     */
+    protected function convertPlatformName($platform)
+    {
+        // 将驼峰命名转换为下划线格式
+        return strtolower(preg_replace('/([A-Z])/', '_$1', lcfirst($platform)));
+    }
+
 
     /**
      * 批量并发发送