代码优化
This commit is contained in:
@@ -912,7 +912,8 @@ class ChannelController extends BaseController
|
||||
'width' => 430, // 二维码的宽度
|
||||
]);
|
||||
|
||||
if ($response instanceof StreamResponse) {
|
||||
// 成功时返回的是 StreamResponse,失败时通常返回数组(包含 errcode/errmsg)
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$img = $response->getBody()->getContents();
|
||||
$imgBase64 = 'data:image/png;base64,' . base64_encode($img);
|
||||
|
||||
@@ -927,14 +928,26 @@ class ChannelController extends BaseController
|
||||
'token' => $token // 返回token,小程序端可以通过scene查询
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
}
|
||||
|
||||
// 如果不是流响应,而是数组(错误信息),则解析错误返回
|
||||
if (is_array($response) && isset($response['errcode']) && $response['errcode'] != 0) {
|
||||
$errMsg = isset($response['errmsg']) ? $response['errmsg'] : '微信接口返回错误';
|
||||
return json([
|
||||
'code' => 500,
|
||||
'success' => false,
|
||||
'msg' => '生成小程序码失败:响应格式错误',
|
||||
'data' => null
|
||||
'msg' => '生成小程序码失败:' . $errMsg,
|
||||
'data' => $response
|
||||
]);
|
||||
}
|
||||
|
||||
// 其他未知格式
|
||||
return json([
|
||||
'code' => 500,
|
||||
'success' => false,
|
||||
'msg' => '生成小程序码失败:响应格式错误',
|
||||
'data' => $response
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
|
||||
Reference in New Issue
Block a user