php 生成小程序二维码

        import("Vendor.Wxpay.lib.WxPay#Config", "", ".php");
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".\WxPayConfig::APPID."&secret=".\WxPayConfig::APPSECRET;
        $ret = file_get_contents($url);
        $access_token = json_decode($ret)->access_token;
        $postData = array('path' => 'pages/member/login/login');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' . $access_token);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 500);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
        $exec = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);
        if (empty($error)) {
            header("Content-type:application/octet-stream");
            header("Accept-Ranges:bytes");
            header("Accept-Length:" . strlen($exec));
            header("Content-Disposition:attachment;filename=test.jpg" );
            echo $exec;
        }

猜你喜欢

转载自blog.csdn.net/sfmcatl/article/details/79581121