|  | @@ -297,28 +297,13 @@ class Goods extends Base
 | 
	
		
			
				|  |  |              $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;
 | 
	
		
			
				|  |  |          $this->success('获取成功', $base64_file);
 | 
	
		
			
				|  |  |      }
 |