小程序二维码接口问题

$url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
$post_data=json_encode($data);
$res=$this->request_post($post_data,$url);
//由于二进制不能转json字符串,但是可以直接写入文件变成图片,所以使用file_put_contents就能解决图片输出的问题,每一次生成二维码请求一次接口就行了。接口调用去看手册https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html
file_put_contents($_SERVER['DOCUMENT_ROOT']."/test.png",$res);
 /**
     * @author zhoushiwei
     * @date 2018/11/2
     *  curl post请求
     */
    public function request_post($post_data,$url) {
        $postUrl = $url;
        $curlPost=$post_data;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//跳过SSL验证
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

        $data = curl_exec($ch);//运行curl
        //异常后处理
        if($data===false){
            $this->error("请求失败");
        }
        curl_close($ch);

        return $data;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值