微信小程序接口B二维码接口调用
微信小程序二维码接口A与C总共生成的码数量限制为100,000,也就是说如果超出了这个现在二维码调用就会失败,我这边的业务需要调用二维码的频率较多,以防万一。
文档在此 —- [ 微信小程序二维码获取文档 ]
微信小程序获取二维码首先要获得access_token
动态获得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/gif');
$uid = 6;
$data = array();
$data['scene'] = "uid=" . $uid;
$data['page'] = "pages/index/index";
$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_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
$out = json_decode($output);
return $out;
}
Page({
onLoad: function(options) {
var scene = decodeURIComponent(options.scene)
consol.log(scene)
}
})
var uid = scene.split("=")[1];/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
这是我个人的做法,思考的可能不周全,做法也不是那么规范,但是希望可以帮到需要的人,欢迎加群讨论:578385176,我的扣扣:1377274329