php微信小程序生成二维码,出现乱码,{"errcode":44002,"errmsg":"empty post data"},'{"errcode":41001,"errmsg":"access_t

微信小程序的坑简直比我的头发还多,今天下午获取微信二维码,遇到的44002,41001,还有图片没法正常显示以及小程序参数获取的问题,接下来一一解决

首先获取微信token然后再获取二维码这个没什么好说的 直接上代码

public function getQRcode()
{
$appid = ‘wx3118da96194edcd5’;
$secret = ‘15de113e48ddcfd8226afc701ee938eb’;
KaTeX parse error: Expected 'EOF', got '&' at position 115: …ient_credential&̲appid='.appid.’&secret=’.$secret),true)[‘access_token’];
url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?accesstoken=url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=access_token";
$ch = curl_init();
KaTeX parse error: Expected 'EOF', got '&' at position 33: …e(['scene' => '&̲id='.this->user_id]);
curl_setopt(ch,CURLOPTPOST,1);curlsetopt(ch, CURLOPT_POST, 1); curl_setopt(ch, CURLOPT_HEADER, ‘image/gif’);
curl_setopt(ch,CURLOPTURL,ch, CURLOPT_URL,url);
curl_setopt(ch,CURLOPTPOSTFIELDS,ch, CURLOPT_POSTFIELDS,data);
curl_setopt(ch,CURLOPTSSLVERIFYPEER,false);curlsetopt(ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt(ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen(data)));curlsetopt(data) )); curl_setopt(ch, CURLOPT_RETURNTRANSFER,1); //如果需要将结果直接返回到变量里,那加上这句。
res=curlexec(res = curl_exec(ch);
}

虽然已经获取到了小程序二维码 但是此时打印$res就会出现乱码的问题 仔细看文档的同学可能就知道 这是因为微信会返回图片二进制内容

妈的 简直不要太坑啊

data=data:image/jpeg;base64,.base64encode(data = 'data:image/jpeg;base64,'.base64_encode(res);//补全base64加密字符串头
html="<!DOCTYPEhtml><htmllang=en><head><metacharset=UTF8><title></title></head><body><imgsrc=html = "<!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>二维码</title> </head> <body> <img src='data’>

";
echo $html;

在代码上加上这一句 可以转换 直接输出图片

ok 二维码已经出来了 接下来就是获取二维码参数 比如参数为id=1

获取二维码参数还是比较简单的 微信二维码指向首页
然后在index.js编写

onLoad (option) { console.log(option) }

然后请求后台交互 将参数传过去 ,本来后台接口已经写好了 我想今天的工作可以告一段段落了,尼玛没想到检查数据的时候发现id根本没有获取到

在本地测试的时候可以

php微信小程序生成二维码,出现乱码,{"errcode":44002,"errmsg":"empty post data"},'{"errcode":41001,"errmsg":"access_t

这样操作开发工具 就会获取到参数 接着去后台打印的时候你就会发现你传过去的参数根本不是1,而是{‘id’:‘1’},我日 就没遇到过他们这种的

所以如果本地测试的话还得需要进行一下操作 兄弟我是直接被征服了 随便截取了一下1前边的7个字符 后边的2个字符 这样才得到完整’1‘,

尼玛,这个小程序简直不要太坑