当前位置:网站首页>Wechat upload picture material interface
Wechat upload picture material interface
2022-06-13 08:19:00 【Parthenocissus still works】
Official wechat documents , This interface's media The explanation is a bit confusing ( It doesn't work , This is to explain what is contained in the file information , No special treatment is required )
Search for information , Write test code and keep trying , There are two main implementation methods :
1. Method 1: direct use curl, It is mainly used to test how interface parameters are set , Whether the wechat interface can be adjusted :
$pathName = realpath('./111.png');
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESSTOKEN&type=image";
$data = array(
'media' => new CURLFile($pathName, 'image/png', '111.png')
);
$description = array(
'title' => '111.png',
'introduction' => '111.png',
);
$data['description'] = urldecode(json_encode($description));
// $data = http_build_query($data);// Upload files using curlfile Out of commission http_build_query Handle
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
@curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
$data = curl_exec($ch);
$status = curl_getinfo($ch);
$errno = curl_errno($ch);
curl_close($ch);
var_dump($data);
It should be noted that according to php Version select the way to upload files , Please refer to the official website ( The screenshot is as follows )
2. The second way is to use GuzzleHttp Upload :
$pathName = realpath('./111.png');
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESSTOKEN&type=image";
$description = array(
'title' => '111.png',
'introduction' => '111.png',
);
// $data['description'] = urldecode(json_encode($description));
try{
$client = new Client();
$multipart = [
[
'name' => 'media',
'contents' => fopen($pathName, 'r')
],
[
'name' => 'description',
'contents' => urldecode(json_encode($description))
]
];
$response = $client->request('POST', $url, [
'timeout' => 3,
'multipart' => $multipart,
]);
$response = json_decode($response->getBody(), true);
var_dump($response);
}catch(\Exception $e){
echo $e->getMessage();
}
边栏推荐
- 从零开始-实现JpetStore网站-1-建立项目框架以及项目介绍
- Did decentralized digital identity
- Overall process analysis of account book operation in fabric0.6
- 生鲜配送分拣管理系统哪家比较强?
- LVM management exercise
- Plane merging (matlab)
- Web site access excel in IIS
- How to dynamically delete data rows in a table through JS (keep the head)
- The way of distributed system: Lamport logical clock
- Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
猜你喜欢
Detailed explanation of digital certificate and Ca
File upload question type
Maternal and infant supplies wholesale industry uses management software to improve efficiency and realize cost reduction and efficiency increase
How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
基于paddlepaddle的新冠肺炎识别
HCIP_ MGRE experiment
Gtk+ programming example on page 115 - simplest progress bar 2 with steps to write GTK program using anjuta
学习记录4: einops // cudnn.benchamark=true // hook
Dfinity (ICP) basic development tutorial-5
STM32CubeMX的下载和安装方式
随机推荐
Rust writes near smart contract
Sizeof, strlen find character length
CCNP_ Summary (Continued)
Edge浏览器使用BdTab新标签页插件(BD新标签页)
[problem record] json decoder. JSONDecodeError:Extra data: line xxx column xxx(char xxxx)
如何通过JS动态删除table中的数据行(保留head)
水仙花升级版(自幂数)
平面合并(MATLAB)
sizeof、strlen求字符长度
BD新标签页(BdTab)插件如何登入?
3. deploy the fabric2.2 cluster (use the official demo)
How does the BD new tab plug-in log in?
How to hide tabs in nailing applet
[complete information static game characteristics of Nash equilibrium]
使用kvm创建三台能通局域网的虚拟机
Do not update the sub component page of parameter object passed from parent to child of nailing applet?
HCIP_ MGRE comprehensive experiment
Dest0g3 520迎新赛
Motiko basic syntax in dfinity (ICP) -8
ERP基础数据 华夏