调用官方生成二维码接口,返回的图片有问题。【】swiper组件下套用video出现的问题--微信小程序教程 ...。
通过客户端方式调用:(部分代码)
var token = res.data.access_token;
wx.request({
url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + token,
method: 'POST',
data: {
scene: 'orderId=' + orderId,
path: 'pages/hall/receiveDetail/receiveDetail',
width: 258,
auto_color: false,
line_color: { "r": "0", "g": "0", "b": "0" }
},
dataType:'utf-8',
success: function (res) {
callback(res.data);
}
})
返回的图片为乱码,经过php处理后,基本上为不可见的图片
通过php方式调用:
//获取access_token
public function get_access_token(){
$appid = $wx_config['appid'];
$secret = $wx_config['secret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
return $data = $this->curl_get($url);
}
public function curl_get($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
return $data;
}
//获得二维码
public function get_qrcode() {
header('content-type:image/jpeg');
$data = array();
$data['scene'] = "orderId=14915621621515756124648";
$data['page'] = "pages/hall/receiveDetail/receiveDetail";
$data = json_encode($data);
$access = json_decode($this->get_access_token(),true);
$access_token= $access['access_token'];
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
$da = $this->get_http_array($url,$data);
echo json_encode(array('pictures'=>$da));
$this->assign('data',$da);
$this->fetch();
}
public function get_http_array($url,$post_data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //没有这个会自动输出,不用print_r();也会在后面多个1
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
$out = json_decode($output);
return $out;
}
返回的结果一样,请求官方能给予解答。
微信小程序开发相关问题解答;本文来自微信小程序工厂 http://www.xcxgc.com 转载请保留。
微信小程序开发者回答:
付***:
相同的问题,请问解决了吗?是偶现的问题。
付***:
此问题是 access_token失效的问题。
wx.requestPayment 支付成功有时不走回调+微信小程序开发教程
本文网址:http://www.91bianli.com/kaifazhinan/72239.html