Browse Source

fix:测试

super-yimizi 1 month ago
parent
commit
63c07aea93

+ 5 - 20
application/api/controller/Goods.php

@@ -297,28 +297,13 @@ class Goods extends Base
             $this->error("获取微信二维码失败!" . ($result['errmsg'] ?? ''));
             $this->error("获取微信二维码失败!" . ($result['errmsg'] ?? ''));
         }
         }
         
         
-        // 如果返回的是二进制流,处理图片
-        $resource = '';
-        try {
-            $img = imagecreatefromstring($result);
-            if ($img === false) {
-                throw new \Exception('图片数据格式错误');
-            }
-            ob_start();
-            imagepng($img);
-            $resource = ob_get_clean();
-            imagedestroy($img);
-        } catch (\Exception $e) {
-            Log::write('处理微信二维码图片失败: ' . $e->getMessage());
-            $this->error("处理微信二维码失败!");
-        }
-        
-        if (!$resource) {
-            Log::write('微信二维码资源为空');
-            $this->error("获取二维码失败!");
+        // 成功时,$result 就是图片的二进制buffer数据,直接进行base64编码
+        if (empty($result) || !is_string($result)) {
+            Log::write('微信小程序码返回数据无效');
+            $this->error("获取微信二维码失败!");
         }
         }
         
         
-        $base64_data = base64_encode($resource);
+        $base64_data = base64_encode($result);
         $base64_file = 'data:image/png;base64,' . $base64_data;
         $base64_file = 'data:image/png;base64,' . $base64_data;
         $this->success('获取成功', $base64_file);
         $this->success('获取成功', $base64_file);
     }
     }

+ 0 - 1
application/api/controller/Login.php

@@ -297,7 +297,6 @@ class Login extends Base
                 if (Service::isBindThird('wechat', $openid)) {
                 if (Service::isBindThird('wechat', $openid)) {
                     $this->error("手机号已经绑定其它账号");
                     $this->error("手机号已经绑定其它账号");
                 }
                 }
-
                 // 在第三方登录表中创建关联
                 // 在第三方登录表中创建关联
                 $values = ['user_id' => $this->auth->id, 'platform' => 'wechat', 'openid' => $openid, 'unionid' => $unionid, 'openname' => '微信用户', 'apptype' => 'miniapp'];
                 $values = ['user_id' => $this->auth->id, 'platform' => 'wechat', 'openid' => $openid, 'unionid' => $unionid, 'openname' => '微信用户', 'apptype' => 'miniapp'];
                 Third::create($values, true);
                 Third::create($values, true);

+ 10 - 1
application/common/library/easywechatPlus/WechatService.php

@@ -35,7 +35,16 @@ class WechatService extends EasywechatPlus
 
 
         $result = $result->getBody()->getContents();
         $result = $result->getBody()->getContents();
         // Log::write('getWxCodeUnlimited:'.$result);
         // Log::write('getWxCodeUnlimited:'.$result);
-        return  json_decode($result,true);
+        
+        // 尝试解析为JSON,如果解析成功说明是错误信息,如果失败说明是图片buffer
+        $jsonResult = json_decode($result, true);
+        if (json_last_error() === JSON_ERROR_NONE) {
+            // JSON解析成功,返回错误信息数组
+            return $jsonResult;
+        } else {
+            // JSON解析失败,说明是图片二进制数据,直接返回
+            return $result;
+        }
     }
     }
 
 
     /**
     /**