一.关于图文消息,我的理解
我理解中,普通
在其他界面时,就能使用非腾讯下的域名的图片了.例如,点击图文消息的进入相应的网页.
图文消息有多种方式.例如:
1).在收到消息时,回复一段xml结构的内容:
1468221313
1
-
注意,这里使用腾讯下的域名.
2).2.客服消息
发送图文消息(点击跳转到外链)
{
"touser": "oe5SXv45Fq5lcB5jlxdBs6QWPNj8",
"msgtype": "news",
"news": {
"articles": [{
"title": "Happy Day",
"description": "Is Really A Happy Day",
"url": "http://www.163.com",
"picurl": "http://mmsns.qpic.cn/mmsns/Gugib1CGulhxU7GQPb96z8PTwicX5ud6vIibKQQvzMGr140WicC5icVMESA/0"
}]
}
}
注意,这里使用腾讯下的域名.
以及发送图文消息(点击跳转到图文消息页面)
{
"touser": "oe5SXv45Fq5lcB5jlxdBs6QWPNj8",
"msgtype": "mpnews",
"mpnews": {"media_id": "METyzaxwXqSyyRoutIBvJbJO5W8UiZ0z0jDRp6QPEmU"}
}
注意,这里使用media_id,间接访问腾讯下的域名的图片.
3.群发消息时,先创建图文消息(获得这个图文消息的media)
{
"articles": [{
"thumb_media_id": "qI6_Ze_6PtV7svjolgs-rN6stStuHIjs9_DidOHaj0Q-mwvBelOXCFZiq2OsIU-p",
"author": "xxx",
"title": "Happy Day",
"content_source_url": "www.qq.com",
"content": "content",
"digest": "digest",
"show_cover_pic": 1
}]
}
注意,这里使用的media_id,是指图文消息上的图片,间接访问腾讯下的域名的图片.
然后,使用这个图文消息的media_id发送出去.
{
"touser": ["oe5SXv71irmrQ0TH-JxA-z_hmYLE", "oe5SXv45Fq5lcB5jlxdBs6QWPNj8"],
"mpnews": {"media_id": "123dsdajkasd231jhksad"},
"msgtype": "mpnews"
}
注意,这里使用的media_id,是指图文消息本身,间接访问腾讯下的域名的图片.
好了,图文消息作为特例,就讲到这里.
二.素材管理功能
1).新增临时素材
function upload() { //新增临时素材
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$TYPE = "image";
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$ACCESS_TOKEN&type=$TYPE";
$result = curl_http_upload($url, "media", "C:\Documents and Settings\Administrator\Desktop\bb.png");
echo $result;
}
返回值如下:
{"type":"image","media_id":"4eLt7Aw-KhlB07DalynXwoiOlCJ2_gd1jCJJiSPVKiYQahjDyVkZth4BJ38Z_Wab","created_at":1468582518}
2).获取临时素材
function download() { //获取临时素材
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$MEDIA_ID = "4eLt7Aw-KhlB07DalynXwoiOlCJ2_gd1jCJJiSPVKiYQahjDyVkZth4BJ38Z_Wab";
$url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=$ACCESS_TOKEN&media_id=$MEDIA_ID";
$result = curl_http_download($url, "C:\\Documents and Settings\\Administrator\\Desktop\\222.png");
echo $result;
}
返回值如下:
3).上传图文消息内的图片获取URL.见上面的<<一.关于图文消息,我的理解>>以及我的文章<<微信公众号开发教程[008]-消息管理-群发消息>>
4).新增永久图文素材
function add_news() { //新增永久图文素材
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$url = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=$ACCESS_TOKEN";
$data = '
{
"articles": [
{
"title": "hello",
"thumb_media_id": "METyzaxwXqSyyRoutIBvJUNQ_0j20x_SR8wYUtln0sU",
"author": "rene",
"digest": "DIGEST",
"show_cover_pic": 1,
"content": "很高兴认识你!",
"content_source_url": "http://www.163.com"
}]
}
';
$result = curl_http_post($url, $data);
echo $result;
}
返回值如下:
{"media_id":"METyzaxwXqSyyRoutIBvJSsWfbPjCQ3S9Q7yLubLiA4"}
5).修改永久图文素材
function update_news() { //修改永久图文素材
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$url = "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=$ACCESS_TOKEN";
$data = '
{
"media_id": "METyzaxwXqSyyRoutIBvJSCagx6NbQyBIqis2CemTtc",
"index": 0,
"articles": {
"title": "world",
"thumb_media_id": "METyzaxwXqSyyRoutIBvJUNQ_0j20x_SR8wYUtln0sU",
"author": "nick",
"digest": "DIGEST",
"show_cover_pic": 0,
"content": "欢迎再次光临!",
"content_source_url": "http://www.qq.com"
}
}
';
$result = curl_http_post($url, $data);
echo $result;
}
返回值如下:
{"errcode":0,"errmsg":"ok"}
6).新增其他类型永久素材:图片(mage)语音(voice)视频(video)和缩略图(thumb)
function add_material() { //新增其他类型永久素材:图片(mage)语音(voice)视频(video)和缩略图(thumb)
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$TYPE = "image";
$url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$ACCESS_TOKEN&type=$TYPE";
$result = curl_http_upload($url, "media", "C:\Documents and Settings\Administrator\Desktop\bb.png");
echo $result;
}
返回值如下:
{
"media_id": "METyzaxwXqSyyRoutIBvJb8AfNBMFRQmeU3PZR4qSx8",
"url": "http://mmbiz.qpic.cn/mmbiz/q9jYbRzAGeWze1YwBTc31ZvZGsOcx1R3oOmwkmmt2TQNjI2zURK0pTGacvITXydBPDpHv4oqCWSTPkIt0CIkoA/0?wx_fmt=png"
}
7).获取素材总数
function materialcount() { //获取素材总数
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=$ACCESS_TOKEN";
$result = curl_http_get($url);
echo $result;
}
返回值如下:
{"voice_count":0,"video_count":0,"image_count":8,"news_count":6}
8).获取素材总数
function batchget_material() { //获取素材总数
$ACCESS_TOKEN = "-iiB6nyQEtx4glTED47k1MnDa1OPbq8XyMf937Tto2x59A1bCwqAPs6hkWudXb54O192gac2AHOql-CCYOsM-FdSlfg1q56f2NoUehJ1FgOh32UbTztgqhzgOmJE1DwDKEEbAIAEYY";
$url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=$ACCESS_TOKEN";
$data = '{"type":"image","offset":0,"count":100}';
$result = curl_http_post($url, $data);
echo $result;
}
返回值如下:
{
"item": [
{
"media_id": "METyzaxwXqSyyRoutIBvJbJO5W8UiZ0z0jDRp6QPEmU",
"name": "C:\\Documents and Settings\\Administrator\\Desktop\\aa.png",
"update_time": 1468579557,
"url": "http://mmbiz.qpic.cn/mmbiz/q9jYbRzAGeWze1YwBTc31ZvZGsOcx1R3oOmwkmmt2TQNjI2zURK0pTGacvITXydBPDpHv4oqCWSTPkIt0CIkoA/0?wx_fmt=png"
},
{
"media_id": "METyzaxwXqSyyRoutIBvJUNQ_0j20x_SR8wYUtln0sU",
"name": "C:\\Documents and Settings\\Administrator\\Desktop\\bb.png",
"update_time": 1468578895,
"url": "http://mmbiz.qpic.cn/mmbiz/q9jYbRzAGeWze1YwBTc31ZvZGsOcx1R3oOmwkmmt2TQNjI2zURK0pTGacvITXydBPDpHv4oqCWSTPkIt0CIkoA/0?wx_fmt=png"
},
{
"media_id": "METyzaxwXqSyyRoutIBvJRC4DquK51hGeOPRqFCiE1k",
"name": "api_mpnews_cover.jpg",
"update_time": 1468469201,
"url": ""
},
{
"media_id": "METyzaxwXqSyyRoutIBvJYfzhcT-3QAJNMPiUu7q1As",
"name": "api_mpnews_cover.jpg",
"update_time": 1468466516,
"url": ""
}],
"total_count": 7,
"item_count": 10
}