1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > ASP.NET微信公众号查看粉丝信息接口

ASP.NET微信公众号查看粉丝信息接口

时间:2023-12-14 04:02:34

相关推荐

ASP.NET微信公众号查看粉丝信息接口

后端开发|C#.Net教程

微信公众号

后端开发-C#.Net教程

本文实例为大家分享了微信粉丝信息接口查看代码,供大家参考,具体内容如下

合买网源码,vscode代码提示不见,ubuntu 系统的,tomcat是如何打包,sqlite 求第天平均值,淘宝爬虫类可以开直通车吗,php 数组 迭代,seo审核元素有什么,采集电影网站,it 模板lzw

微信Token实体类:

本地演示网站源码,vscode冒火,UBUNTU笔记本配件,tomcat魔王,sqlite设置保存,window服务器关闭端口,js pdf 预览插件,前端ui库框架,爬虫展在什么地方,php异步框架,代刷seo,社区类网站模板,js网页在线客服浮动代码,ecmall如何在后台添加模板编辑页,bootstrop登录页面,管理系统界面源码下载,支付平台程序源码lzw

/// public class WeChatTokenEntity{public string Access_token { get; set; } public string Expires_in { get; set; }}

用户信息实体类

cf内存读写模块源码,vscode 导入项目,ubuntu怎么查找目录,tomcat 窗体名称,miui sqlite3,html5上传图片插件,vuejs前端框架介紹,爬虫技术怎么学,php 管理系统源码,北京seo工资,点卡交易网站源码,css 网页滚动,商城左侧菜单模板,全屏页面滚动,vb图书馆管理系统下载,java程序开发大全源代码lzw

/// public class WeChatUserEntity{public string Subscribe { get; set; } public string Openid { get; set; } public string Nickname { get; set; } public string Sex { get; set; } public string City { get; set; } public string Province { get; set; } public string Country { get; set; } public string HeadImgUrl { get; set; } public string Subscribe_time { get; set; } public string Language { get; set; }}

微信辅助操作类

public class WeChatDemo{/* * 步骤: * 1.通过appid和secret请求微信url,得到token * 2.通过access_token和openid得到用户信息(头像地址等) * 3.通过access_token和media_id得到用户发送的微信消息 * */ string appId = "wxxxxxxxxxxxxxx";string appSecret = "1234567890-==687"; string wechatUrl = "https://api./cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}"; public WeChatDemo(){ } /// /// public WeChatTokenEntity GetWechatToken(){ //请求的url地址 string tokenUrl = string.Format(wechatUrl, appId, appSecret); WeChatTokenEntity myToken; try { //声明并实例化一个WebClient对象 WebClient client = new WebClient(); //从执行url下载数据 byte[] pageData = client.DownloadData(tokenUrl); //把原始数据的byte数组转为字符串 string jsonStr = Encoding.Default.GetString(pageData); //初始化一个JavaScriptSerializer json解析器 //序列化注意:需要引用System.Web.Extensions JavaScriptSerializer jss = new JavaScriptSerializer(); //将字符串反序列化为Token对象 myToken = jss.Deserialize(jsonStr); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } return myToken;} /// /// /// /// public WeChatUserEntity GetUserIfo(string accessToken, string openId){ WeChatUserEntity wue = new WeChatUserEntity(); string url = "https://api./cgi-bin/user/info?access_token={0}&openid={1}"; url = string.Format(url, accessToken, openId); try { WebClient wc = new WebClient(); byte[] pageData = wc.DownloadData(url); string jsonStr = Encoding.UTF8.GetString(pageData); JavaScriptSerializer jss = new JavaScriptSerializer(); wue = jss.Deserialize(jsonStr); } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } return wue;} public string GetVoice(string accessToken, string mediaId){ string voiceAddress = string.Empty; string voiceUrl = "http://file.api./cgi-bin/media/get?access_token={0}&media_id={1}"; voiceUrl = string.Format(voiceUrl, accessToken, mediaId); WebClient wc = new WebClient(); byte[] pageData = wc.DownloadData(voiceUrl); string jsonStr = Encoding.UTF8.GetString(pageData); //TODO:获取声音 voiceAddress = jsonStr; return voiceAddress;} /// /// /// public DateTime TimeStamp2DateTime(string timeStamp){ DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long time = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(time); return dtStart.Add(toNow);} }

主程序:

class Program{static void Main(string[] args){ WeChatDemo wcd = new WeChatDemo(); WeChatTokenEntity wte = wcd.GetWechatToken(); string token = wte.Access_token; string openId = "ogNVpt52xxxxxxxxxxxxxxxxxx"; Console.WriteLine("第一步:获得access_token:\n " + token + "\n"); Console.WriteLine("第二步:获得用户信息"); WeChatUserEntity user = wcd.GetUserIfo(token, openId); Console.WriteLine("\n昵称:" + user.Nickname); Console.WriteLine("国家:" + user.Country); Console.WriteLine("省份:" + user.Province); Console.WriteLine("城市:" + user.City); Console.WriteLine("语言:" + user.Language); Console.WriteLine("性别:" + user.Sex); Console.WriteLine("OpenId:" + user.Openid); Console.WriteLine("是否订阅:" + user.Subscribe); Console.WriteLine("时间:" + wcd.TimeStamp2DateTime(user.Subscribe_time)); Console.WriteLine("头像地址:" + user.HeadImgUrl); Console.WriteLine("\n第三步:获取微信声音地址"); string mediaId = "vwvnskvsldkvmsdlvkmdslkvmsld"; string voiceAddress = wcd.GetVoice(token, mediaId); Console.WriteLine("声音地址:" + voiceAddress); Console.Read();}}

运行结果如图:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。