当前位置:网站首页>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;
}
边栏推荐
- Lesson 9: workspace introduction
- SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
- Technology inventory: past, present and future of Message Oriented Middleware
- Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones
- [golang] leetcode intermediate - Search rotation sort array & search two-dimensional matrix II
- What elements are indispensable for the development of the character? What are the stages
- No one reads the series. Source code analysis of copyonwritearraylist
- Hands on deep learning (III)
- Socket, network model notes
- 2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w
猜你喜欢

Notes on dashboard & kuboard installation in kubernetes cluster
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware

Digitalization, transformation?
SAP ui5 beginner tutorial 25 - using proxy server to solve the cross domain problem of SAP ui5 application accessing remote OData service trial version
Websocket in the promotion of vegetable farmers

How to use asemi FET 7n80 and how to use 7n80

Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop

Getting started with Silverlight development 1
![[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management](/img/62/dab2ac0526795f2040394acd9efdd3.jpg)
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management

IQ debugging of Hisilicon platform ISP and image (1)
随机推荐
Research Report on demand and Competitive Prospect of global and Chinese welding personal protective equipment industry 2022-2027
SAP ui5 tutorial for beginners part XXVI - detailed steps for using OData service with mock server trial version
Vegetables sklearn - xgboost (2)
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
MySQL tuning --01--- optimization steps and system performance parameters
Highway
HCIP Day 16
Do you know what a three-tier architecture is?
Vscode voice notes to enrich information (Part 1)
Guess the size of the number
C switch nested syntax
50 days countdown! Are you ready for the Landbridge cup provincial tournament?
Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
证券如何在线开户?在线开户是安全么?
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
How to use asemi FET 7n80 and how to use 7n80
Hands on deep learning (III)
Introduction to sap ui5 tools
Mount command - file system mount