In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what are the basic interfaces for the development value of. net Weixin Official Accounts. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.
1 获取许可令牌
AccessToken类封装了许可令牌的相关属性和方法。
(注:OAuthAccessToken封装了网页授权许可令牌的相关方法。)
属性有:
access_token--令牌字符串
expires_in--有效时间(单位:秒)
静态方法有:
Get--获取许可令牌
/// /// 获取许可令牌 /// /// /// protected void btnGetAccessToken_Click(object sender,EventArgs e) { string userName = lbPublicAccount.SelectedValue; AccessToken token = AccessToken.Get(userName); txtAccessToken.Text = token != null ? token.access_token : "获取许可令牌失败。"; }
2 获取微信服务器地址
ServerAddresses类封装了获取服务器地址的属性和方法。
属性有:
ip_list--服务器地址数组
静态方法有:
Get--获取服务器地址
/// /// 获取微信服务器地址 /// /// /// protected void btnGetServerAddress_Click(object sender, EventArgs e) { ErrorMessage errorMessage; ServerAddresses addresses = ServerAddresses.Get(out errorMessage); if (errorMessage.IsSuccess && addresses.ip_list != null) { StringBuilder sb = new StringBuilder(); foreach (string ip in addresses.ip_list) sb.AppendFormat("{0},", ip); txtServerAddress.Text = sb.ToString(); } else txtServerAddress.Text = string.Format("获取微信服务器地址失败。{0}", errorMessage); }
3 上传、下载多媒体文件
MultiMediaHelper类封装了多媒体文件的相关方法。
静态方法有:
Upload--上传多媒体文件
Download--下载多媒体文件
GetDownloadUrl--获取多媒体文件的地址
GetVideoMediaId--得到消息群发中的视频媒体ID
/// /// 上传多媒体文件 /// /// /// protected void btnUpload_Click(object sender, EventArgs e) { string userName = lbPublicAccount.SelectedValue; MultiMediaTypeEnum type = (MultiMediaTypeEnum)Enum.Parse(typeof(MultiMediaTypeEnum), lbMultiMediaType.SelectedValue); string filename = fileUpload.FileName; byte[] bytes = fileUpload.FileBytes; ErrorMessage errorMessage; MultiMediaUploadResult result = MultiMediaHelper.Upload(userName, type, filename, bytes, out errorMessage); if (errorMessage.IsSuccess && result != null) hlShowMultiMedia.NavigateUrl = MultiMediaHelper.GetDownloadUrl(AccessToken.Get(userName).access_token, result.MediaId); else hlShowMultiMedia.NavigateUrl = string.Format("_javascript:alert('上传多媒体文件失败。\r\n{0}');", errorMessage); }上传多媒体文件,并生成下载链接的示例
4 创建、显示二维码
QrCode类封装了跟二维码相关的属性与方法。
属性有:
ticket--二维码的ticket
expire_seconds--二维码的有效时间(单位:秒)
url--二维码图片解析后的地址
静态方法有:
Create--创建二维码,不同的重载方法可以创建不同类型的二维码
GetUrl--获取二维码图片的地址
/// /// 创建二维码 /// /// /// protected void btnCreateQrCode_Click(object sender, EventArgs e) { string userName = lbPublicAccount.SelectedValue; string strSceneId = txtSceneId.Text; QrCode qrcode=null; ErrorMessage errorMessage; if( cbIsTemple.Checked) { int expireSeconds = int.Parse(txtExpireSeconds.Text); int sceneId; if (int.TryParse(strSceneId, out sceneId)) qrcode = QrCode.Create(userName, expireSeconds, sceneId, out errorMessage); else errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "场景值id必须为整数。"); } else { int sceneId; if (int.TryParse(strSceneId, out sceneId)) qrcode = QrCode.Create(userName, sceneId, out errorMessage); else qrcode = QrCode.Create(userName, strSceneId, out errorMessage); } if (errorMessage.IsSuccess && qrcode != null) imgQrCode.ImageUrl = QrCode.GetUrl(qrcode.ticket); else imgQrCode.ImageUrl = ""; }
5 长链接转短链接
ShortUrl封装了长连接转短链接的方法。
静态方法有:
Get--将长链接转换成短链接
/// /// 获取短链接 /// /// /// protected void btnGetShortUrl_Click(object sender, EventArgs e) { string userName = lbPublicAccount.SelectedValue; ErrorMessage errorMessage; string shortUrl = ShortUrl.Get(userName, txtLongUrl.Text, out errorMessage); if (errorMessage.IsSuccess && string.IsNullOrWhiteSpace(shortUrl)) txtShortUrl.Text = shortUrl; else txtShortUrl.Text = string.Format("获取短链接失败。{0}", errorMessage); }关于".net微信公众号开发值基础接口有哪些"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
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.