


WeChat public platform development: advanced interface description
Feb 27, 2017 pm 01:23 PMThe advanced interface mentioned here refers to the advanced functions opened for certified service accounts.
Advanced functions can be roughly classified as:
User interface
Group interface
Customer service interface (different from the multi-customer service introduced before)
Group sending interface
Multimedia interface
QR code interface
Template message interface (not all accounts can be activated)
OAuth2.0( It is relatively complicated and will be introduced later)
All the above interfaces are included in the Senparc.Weixin.MP.AdvancedAPIs namespace.
Some common operations
Almost all high-level interfaces require AccessToken for communication (note that the following interfaces without special instructions require this AccessToken, but not all), so most There will be an AccessToken parameter passed in. For information on how to obtain and operate AccessToken, see Senparc.Weixin.MP SDK WeChat Public Platform Development Tutorial (8): General Interface Description.
User interface
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/User
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { //接口詳見(jiàn):http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF /// <summary> /// 用戶(hù)接口 /// </summary> public static class User { /// <summary> /// 獲取用戶(hù)信息 /// </summary> /// <param name="accessToken">調(diào)用接口憑證</param> /// <param name="openId">普通用戶(hù)的標(biāo)識(shí),對(duì)當(dāng)前公眾號(hào)唯一</param> /// <param name="lang">返回國(guó)家地區(qū)語(yǔ)言版本,zh_CN 簡(jiǎn)體,zh_TW 繁體,en 英語(yǔ)</param> /// <returns></returns> public static UserInfoJson Info(string accessToken, string openId, Language.zh_CN) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang={2}", accessToken, openId, lang.ToString()); return HttpUtility.Get.GetJson<UserInfoJson>(url); //錯(cuò)誤時(shí)微信會(huì)返回錯(cuò)誤碼等信息,JSON數(shù)據(jù)包示例如下(該示例為AppID無(wú)效錯(cuò)誤): //{"errcode":40013,"errmsg":"invalid appid"} } /// <summary> /// 獲取關(guān)注著OpenId信息 /// </summary> /// <param name="accessToken"></param> /// <param name="nextOpenId"></param> /// <returns></returns> public static OpenIdResultJson Get(string accessToken, string nextOpenId) { string url = string.Format("https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}", accessToken); if (!string.IsNullOrEmpty(nextOpenId)) { url += "&next_openid=" + nextOpenId; } return HttpUtility.Get.GetJson<OpenIdResultJson>(url); } } }
Group interface
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/Groups
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { /// <summary> /// 用戶(hù)組接口 /// </summary> public static class Groups { /// <summary> /// 創(chuàng)建分組 /// </summary> /// <returns></returns> public static CreateGroupResult Create(string accessToken, string name) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token={0}"; var data = new { group = new { name = name } }; return CommonJsonSend.Send<CreateGroupResult>(accessToken, urlFormat, data); } /// <summary> /// 發(fā)送文本信息 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> public static GroupsJson Get(string accessToken) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token={0}"; var url = string.Format(urlFormat, accessToken); return HttpUtility.Get.GetJson<GroupsJson>(url); } /// <summary> /// 獲取用戶(hù)分組 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <returns></returns> public static GetGroupIdResult GetId(string accessToken, string openId) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/getid?access_token={0}"; var data = new { openid = openId }; return CommonJsonSend.Send<GetGroupIdResult>(accessToken, urlFormat, data); } /// <summary> /// 創(chuàng)建分組 /// </summary> /// <param name="accessToken"></param> /// <param name="id"></param> /// <param name="name">分組名字(30個(gè)字符以?xún)?nèi))</param> /// <returns></returns> public static WxJsonResult Update(string accessToken, int id, string name) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token={0}"; var data = new { group = new { id = id, name = name } }; return CommonJsonSend.Send(accessToken, urlFormat, data); } /// <summary> /// 移動(dòng)用戶(hù)分組 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="toGroupId"></param> /// <returns></returns> public static WxJsonResult MemberUpdate(string accessToken, string openId, int toGroupId) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token={0}"; var data = new { openid = openId, to_groupid = toGroupId }; return CommonJsonSend.Send(accessToken, urlFormat, data); } } }
Customer Service Interface
Explain , the customer service interface here is different from the previous "multi-customer service". The multi-customer service introduced before switches the user conversation status to multi-customer service, and the message is sent to a dedicated multi-customer service client. This conversation is initiated by the user. of. The "customer service" here actually refers to actively pushing messages to designated users at any time (the users have interacted within 48 hours), and the conversation does not need to be initiated by the user.
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/Custom
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { /// <summary> /// 客服接口 /// </summary> public static class Custom { private const string URL_FORMAT = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}"; /// <summary> /// 發(fā)送文本信息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="content"></param> /// <returns></returns> public static WxJsonResult SendText(string accessToken, string openId, string content) { var data = new { touser = openId, msgtype = "text", text = new { content = content } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } /// <summary> /// 發(fā)送圖片消息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="mediaId"></param> /// <returns></returns> public static WxJsonResult SendImage(string accessToken, string openId, string mediaId) { var data = new { touser = openId, msgtype = "image", image = new { media_id = mediaId } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } /// <summary> /// 發(fā)送語(yǔ)音消息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="mediaId"></param> /// <returns></returns> public static WxJsonResult SendVoice(string accessToken, string openId, string mediaId) { var data = new { touser = openId, msgtype = "voice", voice = new { media_id = mediaId } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } /// <summary> /// 發(fā)送視頻消息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="mediaId"></param> /// <param name="thumbMediaId"></param> /// <returns></returns> public static WxJsonResult SendVideo(string accessToken, string openId, string mediaId, string thumbMediaId) { var data = new { touser = openId, msgtype = "video", video = new { media_id = mediaId, thumb_media_id = thumbMediaId } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } /// <summary> /// 發(fā)送音樂(lè)消息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="title">音樂(lè)標(biāo)題(非必須)</param> /// <param name="description">音樂(lè)描述(非必須)</param> /// <param name="musicUrl">音樂(lè)鏈接</param> /// <param name="hqMusicUrl">高品質(zhì)音樂(lè)鏈接,wifi環(huán)境優(yōu)先使用該鏈接播放音樂(lè)</param> /// <param name="thumbMediaId">視頻縮略圖的媒體ID</param> /// <returns></returns> public static WxJsonResult SendMusic(string accessToken, string openId, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaId) { var data = new { touser = openId, msgtype = "music", music = new { title = title, description = description, musicurl = musicUrl, hqmusicurl = hqMusicUrl, thumb_media_id = thumbMediaId } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } /// <summary> /// 發(fā)送圖文消息 /// </summary> /// <param name="accessToken"></param> /// <param name="openId"></param> /// <param name="title">音樂(lè)標(biāo)題(非必須)</param> /// <param name="description">音樂(lè)描述(非必須)</param> /// <param name="musicUrl">音樂(lè)鏈接</param> /// <param name="hqMusicUrl">高品質(zhì)音樂(lè)鏈接,wifi環(huán)境優(yōu)先使用該鏈接播放音樂(lè)</param> /// <param name="thumbMediaId">視頻縮略圖的媒體ID</param> /// <returns></returns> public static WxJsonResult SendNews(string accessToken, string openId, List<Article> articles) { var data = new { touser = openId, msgtype = "news", news = new { articles = articles.Select(z => new { title = z.Title, description = z.Description, url = z.Url, picurl = z.PicUrl//圖文消息的圖片鏈接,支持JPG、PNG格式,較好的效果為大圖640*320,小圖80*80 }).ToList() } }; return CommonJsonSend.Send(accessToken, URL_FORMAT, data); } } }
Group interface
Here The effect of mass sending is the same as that of logging into the WeChat backend.
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/GroupMessage
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { /// <summary> /// 高級(jí)群發(fā)接口 /// </summary> public static class GroupMessage { /// <summary> /// 根據(jù)分組進(jìn)行群發(fā) /// /// 請(qǐng)注意: /// 1、該接口暫時(shí)僅提供給已微信認(rèn)證的服務(wù)號(hào) /// 2、雖然開(kāi)發(fā)者使用高級(jí)群發(fā)接口的每日調(diào)用限制為100次,但是用戶(hù)每月只能接收4條,請(qǐng)小心測(cè)試 /// 3、無(wú)論在公眾平臺(tái)網(wǎng)站上,還是使用接口群發(fā),用戶(hù)每月只能接收4條群發(fā)消息,多于4條的群發(fā)將對(duì)該用戶(hù)發(fā)送失敗。 /// /// </summary> /// <param name="accessToken"></param> /// <param name="groupId">群發(fā)到的分組的group_id</param> /// <param name="mediaId">用于群發(fā)的消息的media_id</param> /// <returns></returns> public static SendResult SendGroupMessageByGroupId(string accessToken, string groupId, string mediaId) { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}"; var data = new { filter = new { group_id = groupId }, mpnews = new { media_id = mediaId }, msgtype = "mpnews" }; return CommonJsonSend.Send<SendResult>(accessToken, urlFormat, data); } /// <summary> /// 根據(jù)OpenId進(jìn)行群發(fā) /// </summary> /// <param name="accessToken"></param> /// <param name="mediaId">用于群發(fā)的消息的media_id</param> /// <param name="openIds">openId字符串?dāng)?shù)組</param> /// <returns></returns> public static SendResult SendGroupMessageByOpenId(string accessToken, string mediaId, params string[] openIds) { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}"; var data = new { touser = openIds, mpnews = new { media_id = mediaId }, msgtype = "mpnews" }; return CommonJsonSend.Send<SendResult>(accessToken, urlFormat, data); } /// <summary> /// 刪除群發(fā)消息 /// </summary> /// <param name="accessToken"></param> /// <param name="mediaId">發(fā)送出去的消息ID</param> /// <returns></returns> public static WxJsonResult DeleteSendMessage(string accessToken, string mediaId) { //官方API地址為https://api.weixin.qq.com//cgi-bin/message/mass/delete?access_token={0},應(yīng)該是多了一個(gè)/ const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token={0}"; var data = new { msgid = mediaId }; return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data); } } }
Multimedia interface
Multimedia interface Used to upload multimedia information such as pictures, voices, graphic messages, etc. Generally, these information can be used for customer service interfaces or group sending.
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/Media
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { //接口詳見(jiàn):http://mp.weixin.qq.com/wiki/index.php?title=%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E5%A4%9A%E5%AA%92%E4%BD%93%E6%96%87%E4%BB%B6 /// <summary> /// 多媒體文件接口 /// </summary> public static class Media { /// <summary> /// 上傳媒體文件 /// </summary> /// <param name="accessToken"></param> /// <param name="type"></param> /// <param name="file"></param> /// <returns></returns> public static UploadResultJson Upload(string accessToken, UploadMediaFileType type, string file) { var url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", accessToken, type.ToString()); var fileDictionary = new Dictionary<string, string>(); fileDictionary["media"] = file; return HttpUtility.Post.PostFileGetJson<UploadResultJson>(url, null, fileDictionary, null); } /// <summary> /// 下載媒體文件 /// </summary> /// <param name="accessToken"></param> /// <param name="mediaId"></param> /// <param name="stream"></param> public static void Get(string accessToken, string mediaId, Stream stream) { var url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", accessToken, mediaId); HttpUtility.Get.Download(url, stream); } /// <summary> /// 上傳圖文消息素材 /// </summary> /// <param name="accessToken">Token</param> /// <param name="news">圖文消息組</param> /// <returns></returns> public static UploadMediaFileResult UploadNews(string accessToken, params NewsModel[] news) { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token={0}"; var data = new { articles = news }; return CommonJsonSend.Send<UploadMediaFileResult>(accessToken, urlFormat, data); } } }
QR code interface
Use the QR code interface to easily create and verify QR codes. The QR code created is used to allow the user to focus on or identify the scene being scanned.
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/QrCode
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { //API:http://mp.weixin.qq.com/wiki/index.php?title=%E7%94%9F%E6%88%90%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E4%BA%8C%E7%BB%B4%E7%A0%81 /// <summary> /// 二維碼接口 /// </summary> public static class QrCode { /// <summary> /// 創(chuàng)建二維碼 /// </summary> /// <param name="expireSeconds">該二維碼有效時(shí)間,以秒為單位。 最大不超過(guò)1800。0時(shí)為永久二維碼</param> /// <param name="sceneId">場(chǎng)景值ID,臨時(shí)二維碼時(shí)為32位整型,永久二維碼時(shí)最大值為1000</param> /// <returns></returns> public static CreateQrCodeResult Create(string accessToken, int expireSeconds, int sceneId) { var urlFormat = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={0}"; object data = null; if (expireSeconds > 0) { data = new { expire_seconds = expireSeconds, action_name = "QR_SCENE", action_info = new { scene = new { scene_id = sceneId } } }; } else { data = new { action_name = "QR_LIMIT_SCENE", action_info = new { scene = new { scene_id = sceneId } } }; } return CommonJsonSend.Send<CreateQrCodeResult>(accessToken, urlFormat, data); } /// <summary> /// 獲取二維碼(不需要AccessToken) /// 錯(cuò)誤情況下(如ticket非法)返回HTTP錯(cuò)誤碼404。 /// </summary> /// <param name="ticket"></param> /// <param name="stream"></param> public static void ShowQrCode(string ticket, Stream stream) { var urlFormat = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={0}"; HttpUtility.Get.Download(string.Format(urlFormat, ticket), stream); } } }
Template message interface
Template Messages are similar to SMS notifications. They follow a certain template format (different from graphic and text messages) and cannot be obtained by every verified service account.
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/TemplateMessage
The relevant methods in the source code are as follows:
namespace Senparc.Weixin.MP.AdvancedAPIs { /// <summary> /// 模板消息接口 /// </summary> public static class Template { public static WxJsonResult SendTemplateMessage<T>(string accessToken, string openId, string templateId, string topcolor, T data) { const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}"; var msgData = new TempleteModel() { template_id = templateId, topcolor = topcolor, touser = openId, data = data }; return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, msgData); } } }
OAuth2.0 interface
The OAuth interface is used to securely verify the identity of users accessed using the WeChat embedded browser (such as obtaining OpenId)
Source file folder: Senparc.Weixin.MP/AdvancedAPIs/OAuth
Compared Other interfaces OAuth2.0 are slightly complicated
For more WeChat public platform development: advanced interface description related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)