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’];
u r l = " h t t p s : / / a p i . w e i x i n . q q . c o m / w x a / g e t w x a c o d e u n l i m i t ? a c c e s s t o k e n = url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token= url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?accesstoken=access_token";
$ch = curl_init();
KaTeX parse error: Expected 'EOF', got '&' at position 33: …e(['scene' => '&̲id='.this->user_id]);
curl_setopt( c h , C U R L O P T P O S T , 1 ) ; c u r l s e t o p t ( ch, CURLOPT_POST, 1); curl_setopt( ch,CURLOPTPOST,1);curlsetopt(ch, CURLOPT_HEADER, ‘image/gif’);
curl_setopt( c h , C U R L O P T U R L , ch, CURLOPT_URL, ch,CURLOPTURL,url);
curl_setopt( c h , C U R L O P T P O S T F I E L D S , ch, CURLOPT_POSTFIELDS, ch,CURLOPTPOSTFIELDS,data);
curl_setopt( c h , C U R L O P T S S L V E R I F Y P E E R , f a l s e ) ; c u r l s e t o p t ( ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt( ch,CURLOPTSSLVERIFYPEER,false);curlsetopt(ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen( d a t a ) ) ) ; c u r l s e t o p t ( data) )); curl_setopt( data)));curlsetopt(ch, CURLOPT_RETURNTRANSFER,1); //如果需要将结果直接返回到变量里,那加上这句。
r e s = c u r l e x e c ( res = curl_exec( res=curlexec(ch);
}

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

妈的 简直不要太坑啊

d a t a = ′ d a t a : i m a g e / j p e g ; b a s e 64 , ′ . b a s e 6 4 e n c o d e ( data = 'data:image/jpeg;base64,'.base64_encode( data=data:image/jpeg;base64,.base64encode(res);//补全base64加密字符串头
h t m l = &quot; &lt; ! D O C T Y P E h t m l &gt; &lt; h t m l l a n g = ′ e n ′ &gt; &lt; h e a d &gt; &lt; m e t a c h a r s e t = ′ U T F − 8 ′ &gt; &lt; t i t l e &gt; 二 维 码 &lt; / t i t l e &gt; &lt; / h e a d &gt; &lt; b o d y &gt; &lt; i m g s r c = ′ html = &quot;&lt;!DOCTYPE html&gt; &lt;html lang=&#x27;en&#x27;&gt; &lt;head&gt; &lt;meta charset=&#x27;UTF-8&#x27;&gt; &lt;title&gt;二维码&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;img src=&#x27; html="<!DOCTYPEhtml><htmllang=en><head><metacharset=UTF8><title></title></head><body><imgsrc=data’>

";
echo $html;

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

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

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

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

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

在本地测试的时候可以

在这里插入图片描述

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

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

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值