300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > PHP 获取微信小程序接口B二维码接口

PHP 获取微信小程序接口B二维码接口

时间:2023-08-14 12:27:07

相关推荐

PHP 获取微信小程序接口B二维码接口

独角兽企业重金招聘Python工程师标准>>>

获取微信小程序获取access_token

调用

$appid = '小程序的APPID';$secret = '小程序的secret';$token = get_access_token($appid,$secret);

方法

//微信小程序获取access_tokenfunction get_access_token($appid,$secret){$url = "https://api./cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";return $data = curl_get($url);}//模拟GETfunction 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;}

获取B接口二维码

调用

​$token = '获取的token'; 请参考上面方法$scene = 'uid=6'; //要传的参数$page = '';//跳转的路径(不填默认首页)$path = './1.jpg'; //二维码保存的路径get_qrcode($token,$scene,$page,$path);​

方法

//获得二维码function get_qrcode($access_token,$scene,$page,$path) {// header('content-type:image/gif');//header('content-type:image/png');格式自选,不同格式貌似加载速度略有不同,想加载更快可选择jpgheader('content-type:image/jpg');$uid = 6;$data = array();$data['scene'] = $scene;$data['page'] = $page;$data = json_encode($data);$access = json_decode($access_token,true);$access_token= $access['access_token'];$url = "https://api./wxa/getwxacodeunlimit?access_token=" . $access_token;$da = api_notice_increment($url,$data);file_put_contents($path, $da); }function api_notice_increment($url, $data){$ch = curl_init();$header = "Accept-Charset: utf-8";curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($curl, CURLOPT_HTTPHEADER, $header);curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_AUTOREFERER, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$tmpInfo = curl_exec($ch);if (curl_errno($ch)) {return false;}else{return $tmpInfo;}}

小程序前端获取参数

//微信小程序js文件中查看scene所带的参数Page({onLoad: function(options) {// options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scenevar scene = decodeURIComponent(options.scene)consol.log(scene)}})//我这里传的参数为$data['scene'] = "uid=" 10086;//使用console.log(scene);得到的结果为 uid=10086//获得uid 的值var uid = scene.split("=")[1];/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。