欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET微信公眾號(hào)查看粉絲信息接口

 更新時(shí)間:2016年11月21日 14:54:56   作者:天風(fēng)隼  
這篇文章主要為大家詳細(xì)介紹了ASP.NET微信公眾號(hào)查看粉絲信息接口的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ASP.NET微信粉絲信息接口查看代碼,供大家參考,具體內(nèi)容如下

微信Token實(shí)體類:

 /// <summary>
 /// 微信Token實(shí)體類
 /// </summary>
 public class WeChatTokenEntity
 {
 public string Access_token { get; set; }

 public string Expires_in { get; set; }
 }

用戶信息實(shí)體類

 /// <summary>
 /// 用戶實(shí)體信息類
 /// </summary>
 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請(qǐng)求微信url,得到token
  * 2.通過access_token和openid得到用戶信息(頭像地址等)
  * 3.通過access_token和media_id得到用戶發(fā)送的微信消息
  * 
  */


 string appId = "wxxxxxxxxxxxxxx";
 string appSecret = "1234567890-==687";

 string wechatUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";


 public WeChatDemo()
 {

 }

 /// <summary>
 /// 獲取token信息
 /// </summary>
 /// <returns></returns>
 public WeChatTokenEntity GetWechatToken()
 {
  //請(qǐng)求的url地址
  string tokenUrl = string.Format(wechatUrl, appId, appSecret);
  WeChatTokenEntity myToken;

  try
  {
  //聲明并實(shí)例化一個(gè)WebClient對(duì)象
  WebClient client = new WebClient();
  //從執(zhí)行url下載數(shù)據(jù)
  byte[] pageData = client.DownloadData(tokenUrl);
  //把原始數(shù)據(jù)的byte數(shù)組轉(zhuǎn)為字符串
  string jsonStr = Encoding.Default.GetString(pageData);
  //初始化一個(gè)JavaScriptSerializer json解析器
  //序列化注意:需要引用System.Web.Extensions
  JavaScriptSerializer jss = new JavaScriptSerializer();
  //將字符串反序列化為Token對(duì)象
  myToken = jss.Deserialize<WeChatTokenEntity>(jsonStr);
  }
  catch (WebException ex)
  {
  throw ex;
  }
  catch (Exception ex)
  {
  throw ex;
  }

  return myToken;
 }

 /// <summary>
 /// 獲取用戶信息
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="openId"></param>
 /// <returns></returns>
 public WeChatUserEntity GetUserIfo(string accessToken, string openId)
 {
  WeChatUserEntity wue = new WeChatUserEntity();

  string url = "https://api.weixin.qq.com/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<WeChatUserEntity>(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.weixin.qq.com/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;
 }

 /// <summary>
 /// 時(shí)間戳轉(zhuǎn)為當(dāng)前時(shí)間
 /// </summary>
 /// <param name="timeStamp"></param>
 /// <returns></returns>
 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("國(guó)家:" + 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("時(shí)間:" + 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();
 }
 }

運(yùn)行結(jié)果如圖:

本文已被整理到了《ASP.NET微信開發(fā)教程匯總》,歡迎大家學(xué)習(xí)閱讀。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 使用ASP.NET?Web?API構(gòu)建Restful?API

    使用ASP.NET?Web?API構(gòu)建Restful?API

    這篇文章介紹了使用ASP.NET?Web?API構(gòu)建Restful?API的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • VS 2015開發(fā)跨平臺(tái)手機(jī)應(yīng)用的配置教程

    VS 2015開發(fā)跨平臺(tái)手機(jī)應(yīng)用的配置教程

    這篇文章主要給大家介紹了關(guān)于VS 2015開發(fā)跨平臺(tái)手機(jī)應(yīng)用配置的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • .NET?Core部署為Windows服務(wù)的詳細(xì)步驟

    .NET?Core部署為Windows服務(wù)的詳細(xì)步驟

    這篇文章主要介紹了.NET?Core部署為Windows服務(wù),想要將.NET?Core部署為window服務(wù),項(xiàng)目中需要進(jìn)行以下配置:項(xiàng)目中引入Microsoft.Extensions.Hosting.WindowsServices包,本文給大家詳細(xì)講解,需要的朋友可以參考下
    2022-10-10
  • Asp.net移除Server,X-Powered-By和X-AspNet-Version頭

    Asp.net移除Server,X-Powered-By和X-AspNet-Version頭

    這篇文章主要介紹了Asp.net移除Server,?X-Powered-By,?和X-AspNet-Version頭,移除X-AspNet-Version很簡(jiǎn)單,只需要在Web.config中增加相應(yīng)配置節(jié),感興趣的朋友一起看看吧
    2024-02-02
  • .NET的Ajax請(qǐng)求數(shù)據(jù)提交實(shí)例

    .NET的Ajax請(qǐng)求數(shù)據(jù)提交實(shí)例

    這篇文章主要介紹了.NET的Ajax請(qǐng)求數(shù)據(jù)提交實(shí)例,較為詳細(xì)的分析了Ajax請(qǐng)求、數(shù)據(jù)的提交以及參數(shù)的傳遞技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • asp.net中Null在從數(shù)據(jù)庫(kù)讀取的時(shí)候的一點(diǎn)點(diǎn)小技巧

    asp.net中Null在從數(shù)據(jù)庫(kù)讀取的時(shí)候的一點(diǎn)點(diǎn)小技巧

    我們先看下面的一段代碼,這段代碼其實(shí)很平常,也是我們平時(shí)做項(xiàng)目很常用的一段
    2012-04-04
  • ASP.NET中Application和Cache的區(qū)別分析

    ASP.NET中Application和Cache的區(qū)別分析

    在asp.net中儲(chǔ)存數(shù)據(jù)的方式有很多,包括application,session,cache, cookie, viewstate。其中application和cache的應(yīng)用范圍,使用方式都比較相似,這里主要對(duì)比一下這兩種方式。
    2010-03-03
  • ASP.NET 生成靜態(tài)頁面 實(shí)現(xiàn)思路

    ASP.NET 生成靜態(tài)頁面 實(shí)現(xiàn)思路

    網(wǎng)上的cms系統(tǒng)好多都是支持生成靜態(tài)的,大家在使用過程中,也肯定遇到了很多的問題,下面就是一些實(shí)現(xiàn)的原理,其實(shí) asp,php,asp.net的原理都是差不多的。
    2009-06-06
  • ASP.NET搭配Ajax實(shí)現(xiàn)搜索提示功能

    ASP.NET搭配Ajax實(shí)現(xiàn)搜索提示功能

    為了更好的用戶體驗(yàn),不論是桌面軟件還是網(wǎng)站,在搜索查詢的輸入中都會(huì)加入提示功能,就像百度搜索一樣!今天筆者就ASP.NET編程介紹一下如何利用Ajax來實(shí)現(xiàn)搜索信息提示功能。
    2015-09-09
  • Blazor組件的生命周期解析

    Blazor組件的生命周期解析

    這篇文章介紹了Blazor組件的生命周期,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04

最新評(píng)論