获取公众号素材管理列表-教程
2017-02-28 16:23
176 查看
思路
1.根据公众号的appid和secret获取到access_token;
2.根据access_token以及相关参数获取素材管理列表数据
直接上传代码,有注释,很简单。
<?php /* * 获取access_token *grant_type 获取access_token填写client_credential *appid 第三方用户唯一凭证 *secret 第三方用户唯一凭证密钥,即appsecret **/ $appid="**"; $secret="**"; $access_token=get_access_token($appid,$secret); //print "<div>调试凭证".$access_token."</div><br />"; $returnData=get_article_list("news","0","1",$access_token); print "<div>返回的数据".$returnData."</div><br />"; function get_access_token($appid,$secret) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret.""; $response = file_get_contents($url); //返回数据格式:{"access_token":"ACCESS_TOKEN","expires_in":7200} //expires_in:凭证有效时间 $res = json_decode($response, true); return $res['access_token']; }; /* *获取文章列表 *type 素材的类型:图片(image)、视频(video)、语音 (voice)、图文(news) *offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回 *count 返回素材的数量,取值在1到20之间 */ function get_article_list($type, $offset, $count, $access_token) { //https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=ACCESS_TOKEN $url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=".$access_token; $data = '{"type":"'.$type.'","offset":"'.$offset.'","count":"'.$count.'"}'; //返回的数据 $response =get_response_post($url, $data); return $response; }; function get_response_post($url, $data) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0);//过滤头部 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($curl,CURLOPT_POST,true); // post传输数据 curl_setopt($curl,CURLOPT_POSTFIELDS,$data);// post传输数据 $responseText = curl_exec($curl); curl_close($curl); return $responseText; }; ?>
相关文章推荐
- 公众号门店列表管理,获取微信门店列表
- 微信公众号开发教程[010]-消息管理-获取公众号的自动回复规则
- ajax初级教程之获取博文列表
- AJAX实用教程——获取博客园博文列表
- 【Cocos Creator 基础教程(其他)】——游戏素材资源获取方法
- Activiti基础教程--04管理流程定义(流程定义部署ZIP/classpath)、查看(获取流程定义图图片)、删除,不能修改
- php版微信公众账号第三方管理工具开发简明教程
- WinPcap教程(1):获取网卡列表
- WinPcap教程:(1)获取设备列表
- 【fastweixin框架教程8】微信企业号临时素材管理
- 03环信好友管理 - 获取好友列表
- 微信素材管理之新增、删除和获取永久素材
- 【精品教程】BT5虚拟机版reaver穷举PIN多图教程硬盘保存进度获取支持WPS路由列表
- 微信开发之获取素材列表并保存
- ajax初级教程之获取博文列表
- Android实战简易教程-第七十七枪(获取附近可用WIFI列表 附新书地址)
- WinPcap教程(1):获取网卡列表
- xmpp开发教程(四)-获取好友列表
- 微信公众平台开发【素材管理】获取临时素材
- 微信公众后台开发之素材管理