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

asp.net微信開發(fā)(開發(fā)者接入)

 更新時間:2015年11月12日 11:57:45   作者:將哥  
這篇文章主要介紹了asp.net微信開發(fā)中有關(guān)開發(fā)者接入的相關(guān)內(nèi)容,需要的朋友可以參考下

先上圖,看一看需要進行哪些項目的操作:

 

在項目的根目錄或者特定的文件夾內(nèi),創(chuàng)建一個ashx文件(一般處理程序文件),如圖

 public void ProcessRequest(HttpContext context)
 {
  context.Response.ContentType = "text/plain";
  
  string postString = string.Empty;
  if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
  {
  using (Stream stream = HttpContext.Current.Request.InputStream)
  {
   Byte[] postBytes = new Byte[stream.Length];
   stream.Read(postBytes, 0, (Int32)stream.Length);
   postString = Encoding.UTF8.GetString(postBytes);
  }

  if (!string.IsNullOrEmpty(postString))
  {
   ResponseXML(postString);//返回給微信用戶信息
  }

  ///加載自定義菜單
  string postData = "{" + "\r\n";
  postData += "\"button\":[ " + "\r\n";
  postData += "{ " + "\r\n";
  postData += "\"name\":\"簡單查\"," + "\r\n";
  postData += "\"sub_button\":[" + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"我的薪資\", " + "\r\n";
  postData += " \"key\":\"mypay\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"天氣預(yù)報\", " + "\r\n";
  postData += " \"key\":\"tianqiyubao\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"view\"," + "\r\n";
  postData += " \"name\":\"火車票查詢\", " + "\r\n";
  postData += " \"url\":\"http://www.deqiaohr.com.cn/*******.aspx\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"開心一刻\", " + "\r\n";
  postData += " \"key\":\"kaixinyixiao\"" + "\r\n";
  postData += " }]" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{" + "\r\n";
  postData += "\"name\":\"會員管理\", " + "\r\n";
  postData += "\"sub_button\":[" + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"view\"," + "\r\n";
  postData += " \"name\":\"會員注冊\", " + "\r\n";
  postData += " \"url\":\"http://www.deqiaohr.com.cn/****.aspx\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"view\"," + "\r\n";
  postData += " \"name\":\"重置密碼\", " + "\r\n";
  postData += " \"url\":\"http://www.deqiaohr.com.cn/****.aspx\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"修改資料\", " + "\r\n";
  postData += " \"key\":\"updateMessage\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"我的提問\", " + "\r\n";
  postData += " \"key\":\"mywen\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"聯(lián)系客服\", " + "\r\n";
  postData += " \"key\":\"PhoneSerices\"" + "\r\n";
  postData += " }]" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{" + "\r\n";
  postData += "\"name\":\"活動通知\"," + "\r\n";
  postData += "\"sub_button\":[" + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"近期活動\", " + "\r\n";
  postData += " \"key\":\"yuangonghuodong\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"近期通知\", " + "\r\n";
  postData += " \"key\":\"yuangongtongzhi\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"有問必答\", " + "\r\n";
  postData += " \"key\":\"youwenbida\"" + "\r\n";
  postData += " }]" + "\r\n";
  postData += "}]" + "\r\n";
  postData += "}" + "\r\n";

  //自定義菜單token的獲取 是用 下面的兩個參數(shù) 獲取的 不能直接用 公眾平臺的token
  string to = GetAccessToken();
  //本人不喜歡 后臺 json的操作 直接截取就可以了 得到的就是 token 或者 自己 獲取 json的token
  to = to.Substring(17, to.Length - 37);
  //加載菜單
  string i = GetPage("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + to, postData);

  }
  else
  {
  Auth(); //微信接入的測試
  }
  
 }

 

 /// <summary>
 /// 獲取通行證
 /// </summary>
 /// <returns></returns>
 private string GetAccessToken()
 {
  string url_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=********&secret=*********";
  HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token);
  myRequest.Method = "GET";
  HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
  string content = reader.ReadToEnd();
  reader.Close();
  return content;
 }

 

 /// <summary>
 /// 加載菜單項
 /// </summary>
 /// <param name="p"></param>
 /// <param name="postData"></param>
 /// <returns></returns>
 private string GetPage(string p, string postData)
 {
  Stream outstream = null;
  Stream instream = null;
  StreamReader sr = null;
  HttpWebResponse response = null;
  HttpWebRequest request = null;
  Encoding encoding = Encoding.UTF8;
  byte[] data = encoding.GetBytes(postData);
  // 準(zhǔn)備請求...
  try
  {
  // 設(shè)置參數(shù)
  request = WebRequest.Create(p) as HttpWebRequest;
  CookieContainer cookieContainer = new CookieContainer();
  request.CookieContainer = cookieContainer;
  request.AllowAutoRedirect = true;
  request.Method = "POST";
  request.ContentType = "application/x-www-form-urlencoded";
  request.ContentLength = data.Length;
  outstream = request.GetRequestStream();
  outstream.Write(data, 0, data.Length);
  outstream.Close();
  //發(fā)送請求并獲取相應(yīng)回應(yīng)數(shù)據(jù)
  response = request.GetResponse() as HttpWebResponse;
  //直到request.GetResponse()程序才開始向目標(biāo)網(wǎng)頁發(fā)送Post請求
  instream = response.GetResponseStream();
  sr = new StreamReader(instream, encoding);
  //返回結(jié)果網(wǎng)頁(html)代碼
  string content = sr.ReadToEnd();
  string err = string.Empty;
  return content;
  }
  catch (Exception ex)
  {
  string err = ex.Message;
  return string.Empty;
  }
 }

 

 /// <summary>
 /// 獲取參數(shù)進行認證
 /// </summary>
 private void Auth()
 {
  string token = "*****";//你申請的時候填寫的Token

  string echoString = HttpContext.Current.Request.QueryString["echoStr"];
  string signature = HttpContext.Current.Request.QueryString["signature"];
  string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
  string nonce = HttpContext.Current.Request.QueryString["nonce"];

  if (CheckSignature(token, signature, timestamp, nonce))
  {
  if (!string.IsNullOrEmpty(echoString))
  {
   HttpContext.Current.Response.Write(echoString);
   HttpContext.Current.Response.End();
  }
  }

 }
 /// <summary>
 /// 對微信傳入?yún)?shù)進行封裝到數(shù)組,拼接字符串,進行加密操作
 /// </summary>
 /// <param name="token"></param>
 /// <param name="signature"></param>
 /// <param name="timestamp"></param>
 /// <param name="nonce"></param>
 /// <returns></returns>
 private bool CheckSignature(string token, string signature, string timestamp, string nonce)
 {
  string[] ArrTmp = { token, timestamp, nonce };//將參數(shù)放進數(shù)組

  Array.Sort(ArrTmp);//對數(shù)組進行排序
  string tmpStr = string.Join("", ArrTmp);//將數(shù)組進行拼接
  ///對拼接后的字符串進行加密操作
  tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");
  //轉(zhuǎn)換成小寫形式
  tmpStr = tmpStr.ToLower();
  //比對成功返回
  if (tmpStr == signature)
  {
  return true;
  }
  else
  {
  return false;
  }
 }

精彩專題分享:ASP.NET微信開發(fā)教程匯總,歡迎大家學(xué)習(xí)。

以上就是關(guān)于asp.net微信開發(fā)的第一篇,針對開發(fā)者接入進行學(xué)習(xí),之后會有更新更多關(guān)于asp.net微信開發(fā)的文章,希望大家持續(xù)關(guān)注。

相關(guān)文章

  • vs2010制作簡單的asp.net網(wǎng)站

    vs2010制作簡單的asp.net網(wǎng)站

    這篇文章主要介紹了vs2010制作簡單的asp.net網(wǎng)站,只要十步哦,感興趣的小伙伴們可以參考一下
    2015-09-09
  • asp.net(C#)中給控件添加客戶端js事件的方法

    asp.net(C#)中給控件添加客戶端js事件的方法

    今天做一個輸入界面,有一需求根據(jù)一個DropDownList選擇不同,后面部分出現(xiàn)不同的輸入界面,若把響應(yīng)事件放在服務(wù)端去做,得頻繁刷頁面。就想放在客戶來處理顯示和隱藏相應(yīng)的輸入界面。
    2010-03-03
  • 使用Spring.Net框架實現(xiàn)多數(shù)據(jù)庫

    使用Spring.Net框架實現(xiàn)多數(shù)據(jù)庫

    這篇文章介紹了Spring.Net框架實現(xiàn)多數(shù)據(jù)庫的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • ASP.NET筆記之Calender的使用說明

    ASP.NET筆記之Calender的使用說明

    在Calender中,所有可選擇的符號會顯示下劃線,這是因為它們在瀏覽器都會呈現(xiàn)為鏈接。如果讓用戶可以選擇某天、月、周,必須設(shè)置SelectionMode屬性
    2013-04-04
  • Asp.net XML文檔進行添加刪改操作的實例代碼

    Asp.net XML文檔進行添加刪改操作的實例代碼

    Asp.net 對一下XML文檔進行添加刪改的實例
    2009-12-12
  • 用擴展方法優(yōu)化多條件查詢(不定條件查詢)

    用擴展方法優(yōu)化多條件查詢(不定條件查詢)

    在我們開發(fā)過程中,特別是管理系統(tǒng)的開發(fā),經(jīng)常會遇到多條件查詢(或者叫不定條件查詢)的案例,就是提供給User輸入的查詢條件有多個不同的查詢欄位,而且,在實際使用中并不能確定User會使用哪些條件來當(dāng)做搜索條件
    2012-12-12
  • CreateOutputCachedItemKey 緩存key的創(chuàng)建

    CreateOutputCachedItemKey 緩存key的創(chuàng)建

    有關(guān)OutputCache的相關(guān)資料大家可以查看 OutputCacheProvider OutputCache的一點點認識 ,我們還是復(fù)習(xí)一下OutputCache內(nèi)容
    2012-11-11
  • ASP.NET C#生成下拉列表樹實現(xiàn)代碼

    ASP.NET C#生成下拉列表樹實現(xiàn)代碼

    下拉列表樹很方便且時尚的一個導(dǎo)航,貌似很多的朋友都想實現(xiàn)這樣一個列表樹,本文將滿足你們的設(shè)想,通過本文你們可以學(xué)到如何使用c#生成下拉列表樹,感興趣的你可不要錯過了啊
    2013-02-02
  • asp.net 分頁潛談

    asp.net 分頁潛談

    最近研究了一下Asp.net下的分頁功能。以前受前輩們的誤導(dǎo),人云已云的以為做分頁很難很麻煩。這一研究才發(fā)現(xiàn),分頁也不過如此嘛。
    2009-06-06
  • 使用.net core3.0 正式版創(chuàng)建Winform程序的方法(圖文)

    使用.net core3.0 正式版創(chuàng)建Winform程序的方法(圖文)

    這篇文章主要介紹了使用.net core3.0 正式版創(chuàng)建Winform程序的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03

最新評論