最近在做带参数的小程序二维码,遇到了问题,官网文档没有特殊说明,自己总计方法如下:
public function getQrcode(){
$userId = $this->request->param('user_id');
$member_app_id = $this->request->param('appid');
$token = $this->getToken($member_app_id);
$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=".$token;
$data = [
'path' =>"pages/network/network?userId=".$userId,
'scene'=>'1001',
'width'=>430,
'auto_color'=>false,
];
$data=json_encode($data);
$res = $this->request($url,$data);
$data='image/png;base64,'.base64_encode($res);
$imageName = rand(1111,9999).'.png';
if (strstr($data,",")){
$image = explode(',',$data);
$image = $image[1];
}
$path = "./attachs/uploads/".date("Ymd",time());
if (!is_dir($path)){ //判断目录是否存在 不存在就创建
mkdir($path,0777,true);
}
$imageSrc= $path."/". $imageName; //图片名字
$r = file_put_contents(ROOT_PATH .$imageSrc, base64_decode($image));//返回的是字节数
if (!$r) {
return json(['data'=>null,"code"=>1,"msg"=>"图片生成失败"]);
}else{
return json(['data'=>1,"code"=>0,"msg"=>"图片生成成功"]);
}
$this->result($data,200,'获取二维码成功','json');
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/132463.html