php 生成小程序二维码
<?php
//剛開始我調(diào)試的時(shí)候報(bào)各種錯(cuò)誤,注意data的數(shù)據(jù)格式,是拼接成一個(gè)json而不是直接的數(shù)組。另外賬號(hào)密碼都是我寫的測(cè)試的,掉用的時(shí)候輸入成正式的即可
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx96jjkad81a880c36&secret=dff3ab41iuii43cb109ef9c6469e';
$arr = file_get_contents($url);
$a = json_decode($arr,true);
$access_token = $a['access_token'];
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token='.$access_token;
$path="pages/mine/mine/mine?query=1";
$width=430;
$data='{"path":"'.$path.'","width":'.$width.'}';
$return = request_post($url,$data);
//保存在根目錄一個(gè)文件
file_put_contents('./'.time().'.jpg',$return);
function request_post($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($ch, 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;
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/ayanboke/p/9372401.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的php 生成小程序二维码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 来米伽上征信吗
- 下一篇: thinkphp5 消息队列thinkp