首页
📷在线壁纸
🎬娱乐天地
🔖友情链接
更多
📝留言板
Search
1
【javascript】JS-向当前url追加参数
2,345 阅读
2
【PHP】生成随机昵称
2,219 阅读
3
【PHP】判断一个字符串是否属于序列化后的数据
2,024 阅读
4
【css】html+css给文章页,做阅读全文
1,975 阅读
5
【PHP】 设计模式(23种)
1,910 阅读
📂默认分类
💓typecho
🏳️🌈代码改变世界
🍇 mysql
🍈 Winform
🍓 golang
🍉 设计模式
🥝 PHP
🍎 python
🍊 nginx
🍋 网络安全
🍍 javascript
🫑 database
🍭文艺范
🍏mac
AI
LLM
image
audio
yolo
3D
code
登录
Search
标签搜索
php
typecho
代码注释
redis
mysql
go
golang
nginx
thinkphp
docker
gin
linux
curl
html
mamp
算法
短网址
构造函数
webhook
代码片段
依然范儿特西
累计撰写
146
篇文章
累计收到
1
条评论
首页
栏目
📂默认分类
💓typecho
🏳️🌈代码改变世界
🍇 mysql
🍈 Winform
🍓 golang
🍉 设计模式
🥝 PHP
🍎 python
🍊 nginx
🍋 网络安全
🍍 javascript
🫑 database
🍭文艺范
🍏mac
AI
LLM
image
audio
yolo
3D
code
页面
📷在线壁纸
🎬娱乐天地
🔖友情链接
📝留言板
搜索到
1
篇与
的结果
2022-12-15
PHP解析小程序返回的buffer信息,并解析成图片
需要引入 GuzzleHttp 包composer require guzzlehttp/guzzle核心代码如下:<?php require __DIR__ . './vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; /** * get client * @return Client */ function httpGetClient() { static $client ; if (!$client) { $client = new Client(); } return $client; } //GET function httpGet($url) { $client = httpGetClient(); $options = [ 'verify' => false, ]; $response = $client->get($url,$options); return $response->getBody()->getContents(); } // POSTBODY function httpPostBody($url, $requestData=[], $header=[]) { $client = httpGetClient(); $options = [ 'headers' => $header, 'body' => json_encode($requestData,JSON_UNESCAPED_UNICODE ), 'verify' => false, ]; $response = $client->post($url, $options); if ($response->getStatusCode()==200) { return $response->getBody()->getContents(); }else{ return null; } } //postForm function httpPostForm($url, $requestData, $header) { $client = new Client(['verify' => false]); try { $response = $client->request('post', $url, ['form_params' => $requestData, 'headers' => $header]); $response->getStatusCode(); // 200 $response->getHeaderLine('content-type'); if ($response->getStatusCode()==200) { return [true,$response->getBody()->getContents()]; }else{ return [false,[]]; } } catch (GuzzleException $e) { } return [false,[]]; } function getAccessToken(){ $appid = ''; $secret = ''; //获取access_token $access_token_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret; $access_token_data = httpGet($access_token_url); $access_token_data = json_decode($access_token_data,true); return $access_token_data['access_token']; } function getQrcode($access_token){ $url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token='.$access_token; $requestData = [ 'path'=>'pages/order-status/index?loose_id=1', 'width'=>430, ]; $header = []; return httpPostBody($url,$requestData,$header); } $access_token = getAccessToken(); //$access_token = ""; $data = getQrcode($access_token); if(is_null(json_decode($data))){ //不是json数据, 有数据流,返回值为null $jpg = $data; //创建文件写入 $file = fopen("img/test.jpg",'w'); fwrite($file,$jpg); fclose($file); }else{ //不是数据流,则代表有错误发生 $data_array = json_decode($data,true); print_r($data_array); } ?> 如果提示你无法写入, 记得新建一个文件夹: img ,并给可写权限
2022年12月15日
29 阅读
0 评论
1 点赞