關於微信小程序獲取二維碼的踩坑記錄


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

總結:

遇到問題無法解決,先查找是否有人存在同樣問題,可先進行參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM