1.踩坑需求:获取小程序的二维码
2.踩坑接口:
https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN3
踩坑代码
public function GetCode2(Request $request) { $path = $request['path']; $app = WXUtil::funcGetWXAPP('app.jmeii'); $response = $app->app_code->getQrCode($path); $response = $this->BinToStr($response); $this->prop_data_api['appcode'] = $response; return $this->funcReturnApi(); } public function GetCode() { $client = new Client(); $entity_site = \App\t\t_c_site_a_wx::find('app.jmeii'); $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $entity_site->sitewx_access_token; // $postdata = $postdata = json_encode($postdata); $temp = $client->request('POST', $url, [ 'json' => [ 'scene' => 'qdsad12321312312', 'page' => 'pages/__index__/__index__', 'auto_color' => FALSE ] ]); $response = $temp->getBody(); return $response; }
问题描述:
请求代码与步骤不存在问题,但返回数据为空,连错误码都没有。所以尝试使用了两种方式请求
问题原因:
在用curl,或者其他语言的其他请求函数请求到正常的数据后,千万不要用json_encode()处理返回来的数据。因为返回的是二进制的图片文件,经过json处理后就空了。
解决过程:
参考博客发现有人踩过,参阅遂解决。博客链接 https://blog.csdn.net/jesterxu/article/details/78225796
总结:
遇到问题无法解决,先查找是否有人存在同样问题,可先进行参考