鍍金池/ 問答/PHP  HTML/ 小程序生成二維碼接口B,求教哪里出問題了

小程序生成二維碼接口B,求教哪里出問題了

遇到的問題就是,返回既沒有報錯,也沒有數(shù)據(jù),文檔說會返回二進(jìn)制,轉(zhuǎn)為圖片。但現(xiàn)在是什么都沒有,不知道哪里出了問題,求助

這是contorller部分

function getIssueQrcodeAction()
            {
                // $issueId     =    $this->request->getPost('issueId');
                $issueId = 2;
                $page     =    'pages/listPage/article/article?issueId=';
                $test = new GetQrcode();
                $t = $test->get_qrcode($page,$issueId);

                print_r($t);
                

            }
這是service業(yè)務(wù)邏輯處理部分
Class GetQrcode
    {
public function get_qrcode($page,$issueId) {
        header('content-type:image/png');
        $uid = 6;
        $data = array();
        $data['scene'] = $issueId;
        $data['page'] = $page;
        $date['width'] = 450;
        $data = json_encode($data);
        // $access = json_decode($this->get_access_token(),true);
           $a = new WeixinUsers();
        $access_token = $a->access_token();
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
        $da = $this->get_http_array($url,$data);

       return json_encode(array('pictures'=>$da));
        // $this->assign('data',$da);
        // $this->fetch();

    }
    public function get_http_array($url,$post_data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   //沒有這個會自動輸出,不用print_r();也會在后面多個1
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);
        $out = json_decode($output);
        return $out;
    }
 }

https://mp.weixin.qq.com/debu...

回答
編輯回答
不二心

$out = json_decode($output);$output返回的已經(jīng)是二進(jìn)制流了,不許用json_decode,直接使用file_put_contents接收即可

2017年6月18日 06:28
編輯回答
壞脾滊

http response里讀取響應(yīng)流,然后轉(zhuǎn)成png或你想要的格式

2018年5月3日 10:23
編輯回答
冷眸

不確定是不是因為第二個接口需要先上線小程序的原因。目前我的情況跟你一樣,想上線后再試試,但是審核未通過。。。

2017年9月5日 18:33
編輯回答
蝶戀花

有幾個問題,第一你的是POST請求,意思就是你用POST去拿去一個圖片,可能么.
第二個,請不要指定你的page,如果小程序未上線,指定了page是無法展示出來的
第三個,http_request中,curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($data));
第四個,請設(shè)置發(fā)送頭為application/json,不然你會后悔的.
最后最后一個問題,請不要直接上的代碼,看代碼很惱火,浪費人的時間,除非是很閑的人,當(dāng)然我也算

2018年3月17日 03:31
編輯回答
奧特蛋

遇到的問題就是,返回既沒有報錯,也沒有數(shù)據(jù),文檔說會返回二進(jìn)制,轉(zhuǎn)為圖片。但現(xiàn)在是什么都沒有,不知道哪里出了問題,求助

2018年3月5日 15:06
編輯回答
瘋浪

頁面page里面不要帶參數(shù), 參數(shù)放在scene里面

2017年8月22日 23:21
編輯回答
網(wǎng)妓
  $data = [
    'scene'=>$issueId,
    'page'=>$page,
    'width'=>450,
    'auto_color'=>false,
    'line_color'=>["r"=>0,"g"=>0,"b"=>0],
];

把參數(shù)都加上試試,應(yīng)該是有返回的

2017年10月25日 19:16
編輯回答
久礙你
你的服務(wù)器是http請求還是https啊?如果是https的話把你的get_http_array()方法換成下面的

clipboard.png

2017年9月17日 15:50