当前位置:网站首页>Laravel8+ wechat applet generates QR code
Laravel8+ wechat applet generates QR code
2022-06-25 06:17:00 【debug013】
First generate access_token
public function getAccessToken()
{
$url ="https://api.weixin.qq.com/cgi-bin/token? grant_type=client_credential&appid=".self::APPID."&secret=".self::SECRET;
$res = (new Curl())->getUrl($url);
return $res['access_token'];
}Generate qr code
public function getXcxCode(Request $request)
{
$access_token = $this->getAccessToken();
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" . $access_token;
$data['scene'] = 'h' . 2;
// Applet details page path
$data['path'] = 'pages/detail/detail';
// QR code size
$data['width'] = '500';
// dd(json_encode($data));
$res = (new Curl())->httpRequest($url,json_encode($data),"POST");
$path = 'upload/' . '2.png';
file_put_contents($path,$res);
$return['status_code'] = 2000;
$return['msg'] = 'ok';
$return['img'] = 'http://www.dome4.com/' . $path;
echo '<img src="'.$return['img'].'" />';
exit;
echo json_encode($return);
exit;
}Simulation of the request
public function httpRequest($url, $data='', $method='GET'){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
if($method=='POST')
{
curl_setopt($curl, CURLOPT_POST, 1);
if ($data != '')
{
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
}
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
边栏推荐
- Socket, network model notes
- Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
- After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
- Fdisk command – disk partition
- [data visualization application] draw spatial map (with R language code)
- Observation configuring wmic
- Digitalization, transformation?
- 证券如何在线开户?在线开户是安全么?
- PHP output (print) log to TXT text
- Mongodb basic concept learning - set
猜你喜欢
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
SAP ui5 date type sap ui. model. type. Analysis of date parsing format
Interviewer: what is an iterator? What is the relationship between async await and iterators?

Gb28181 protocol -- timing

Day22 send request and parameterization using JMeter

Distributed solar photovoltaic inverter monitoring

How to use asemi FET 7n80 and how to use 7n80
[interview with a large factory] meituan had two meetings. Was there a surprise in the end?
DOM proficient? What is the difference between node and elment?

Digitalization, transformation?
随机推荐
Vscode voice notes to enrich information (medium)
The sum problem
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware
Day21 performance test process
Location object
At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
Use generator-easy-ui5 to quickly create the engineering structure of SAP ui5 applications
Analysis report on investment and financing status and operation benefits of global and Chinese dental industry (2022 Edition)
Wind farm visualization: wind farm data
Lesson 8: FTP server setup and loading
Introduction to MySQL test run test framework
[golang] leetcode intermediate - Search rotation sort array & search two-dimensional matrix II
SAP ui5 beginner tutorial 25 - using proxy server to solve the cross domain problem of SAP ui5 application accessing remote OData service trial version
Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
Gb28181 protocol -- timing
Notes on dashboard & kuboard installation in kubernetes cluster
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
TFTP command – uploading and downloading files
Three tier architecture experiment
Why study discrete mathematics