In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "example Analysis of the Advanced Interface for the Development of Wechat Public platform", which is easy to understand and well-organized. I hope it can help you solve your doubts. Now let the editor lead you to study and study the article "sample Analysis of the Advanced Interface for the Development of Wechat Public platform".
The advanced interface here refers to the advanced functions enabled for the authenticated service number.
Advanced features can be broadly classified as:
User interface
Packet interface
Customer service interface (different from the multi-customer service introduced earlier)
Group sending interface
Multimedia interface
QR code interface
Template message API (not all accounts can be activated)
OAuth3.0 (relatively complex, which will be covered later)
All of the above interfaces are contained under the Senparc.Weixin.MP.AdvancedAPIs namespace.
Some common operations
Almost all advanced APIs need to use AccessToken to communicate (note that this AccessToken is required for all of the following unspecified APIs), so most of them will have an AccessToken parameter passed in. For information on how to obtain and operate AccessToken, please see Senparc.Weixin.MP SDK Wechat Public platform Development tutorial (8): general API instructions.
User interface
Source folder: Senparc.Weixin.MP/AdvancedAPIs/User
The relevant methods in the source code are as follows:
For more information on namespace Senparc.Weixin.MP.AdvancedAPIs {/ / interface, please see 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 / user interface / public static class User { / / get the user information / call the API credential / the identity of the ordinary user For the current official account, the only / / return national and regional language version, zh_CN simplified, zh_TW traditional En English / / 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 (url) / / Wechat will return information such as error code in case of error An example of a JSON packet is as follows (this example is an invalid AppID error): / / {"errcode": 40013, "errmsg": "invalid appid"}} / get the following OpenId information / 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 (url);}
Packet interface
Source folder: Senparc.Weixin.MP/AdvancedAPIs/Groups
The relevant methods in the source code are as follows:
Namespace Senparc.Weixin.MP.AdvancedAPIs {/ user group interface / public static class Groups {/ create grouping / 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 (accessToken, urlFormat, data) } / send text message / 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 (url);} / get user grouping / 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 (accessToken, urlFormat, data) } / create a grouping / grouping name (within 30 characters) / 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) } / Mobile user grouping / 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
To be clear, the customer service interface here is different from the previous "multi-customer service". The previously introduced multi-customer service changes the user conversation status to multi-customer service, and the message is sent to a special multi-customer service client. This conversation is initiated by the user. The "customer service" here actually refers to actively pushing messages to specified users at any time (users have interacted within 48 hours), and the conversation does not need to be initiated by users.
Source folder: Senparc.Weixin.MP/AdvancedAPIs/Custom
The relevant methods in the source code are as follows:
Namespace Senparc.Weixin.MP.AdvancedAPIs {/ customer service interface / public static class Custom {private const string URL_FORMAT = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}";" / / send text message / 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) } / send a picture message / 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) } / send voice message / 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) } / send video message / 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) } / send music message / Music title (optional) / / Music description (optional) / / Music Link / / High quality Music Link The wifi environment gives priority to the media ID / public static WxJsonResult SendMusic (string accessToken, string openId, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaId) that play music / video thumbnails using this link. {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) } / send Teletext message / Music title (optional) / / Music description (optional) / / Music Link / / High quality Music Link The wifi environment gives priority to the media ID / public static WxJsonResult SendNews (string accessToken, string openId, List articles) that play music / video thumbnails using this link. {var data = new {touser = openId, msgtype = "news" News = new {articles = articles.Select (z = > new {title = z.Title, description = z.Description, url = z.Url Picurl = picture link for z.PicUrl// picture and text messages JPG and PNG formats are supported. The better results are as follows: large image 640: 320, small image 80: 80}) .ToList ()}} Return CommonJsonSend.Send (accessToken, URL_FORMAT, data);}}
Group sending interface
The effect of mass posting here is the same as logging in to Wechat backend.
Source folder: Senparc.Weixin.MP/AdvancedAPIs/GroupMessage
The relevant methods in the source code are as follows:
Namespace Senparc.Weixin.MP.AdvancedAPIs {/ Advanced mass sending interface / public static class GroupMessage {/ Note: / 1. This API is only provided to the service number / 2 that has been authenticated by Wechat. Although the number of daily calls for developers using the advanced mass sending interface is limited to 100 However, users can only receive 4 messages per month. Please test / 3 carefully. Users can only receive 4 mass messages per month, whether on public platform websites or using APIs. Mass messages with more than 4 messages will fail to send to the user. / group_id of the group sent to / media_id / 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}";" of the group message Var data = new {filter = new {group_id = groupId}, mpnews = new {media_id = mediaId}, msgtype = "mpnews"} Return CommonJsonSend.Send (accessToken, urlFormat, data) } / media_id / openId string array / public static SendResult SendGroupMessageByOpenId (string accessToken, string mediaId) for sending messages in groups according to OpenId 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 (accessToken, urlFormat, data) } / delete group messages / messages sent out ID / public static WxJsonResult DeleteSendMessage (string accessToken, string mediaId) {/ / official API address is https://api.weixin.qq.com//cgi-bin/message/mass/delete?access_token={0} There should be one more / const string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token={0}";" Var data = new {msgid = mediaId}; return CommonJsonSend.Send (accessToken, urlFormat, data);}
Multimedia interface
Multimedia interface is used to upload pictures, voice, picture and text messages and other multimedia information. Generally, these messages can be used for customer service interface or mass transmission.
Source folder: Senparc.Weixin.MP/AdvancedAPIs/Media
The relevant methods in the source code are as follows:
For more information on namespace Senparc.Weixin.MP.AdvancedAPIs {/ / API, please see 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 / Multimedia File Interface / public. Static class Media {/ upload media files / 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 (); fileDictionary ["media"] = file; return HttpUtility.Post.PostFileGetJson (url, null, fileDictionary, null) } / download media files / 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) } / upload Teletext message material / Token / Teletext message group / 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 (accessToken, urlFormat, data);}
QR code interface
Using the QR code interface, you can easily create and verify the QR code. The created QR code is used to allow users to follow or identify the scanned scene.
Source 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 / QR code interface / public static class QrCode { / create the QR code / the valid time of the QR code In seconds. The maximum does not exceed 1800. 0 is permanent QR code / / scene value ID, temporary QR code is 32-bit integer, and the maximum value for permanent QR code is 1000 / / 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 (accessToken, urlFormat, data); / get the QR code (no AccessToken is required) / return HTTP error code 404 in error cases (such as illegal ticket). / / 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 message is similar to SMS notification, it follows a certain template format (different from picture and text information, etc.), and not every verified service number can be obtained.
Source folder: Senparc.Weixin.MP/AdvancedAPIs/TemplateMessage
The relevant methods in the source code are as follows:
Namespace Senparc.Weixin.MP.AdvancedAPIs {/ template message interface / public static class Template {public static WxJsonResult SendTemplateMessage (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 (accessToken, urlFormat, msgData);}
OAuth3.0 interface
The OAuth API is used to securely verify the identity of users accessed using Wechat embedded browsers (such as obtaining OpenId).
Source folder: Senparc.Weixin.MP/AdvancedAPIs/OAuth
The above is all the contents of the article "example Analysis of the Advanced Interface developed by Wechat Public platform". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.