好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > asp.net微信開發(開發者接入)

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

熱門標簽:聊城智能電銷機器人電話 寧德防封版電銷卡 海東防封電銷卡 南昌自動外呼系統線路 辦公用地圖標注網點怎么操作 安陸市地圖標注app 上海市三維地圖標注 西寧電銷外呼系統公司 云南外呼系統代理

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

 

在項目的根目錄或者特定的文件夾內,創建一個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\":\"天氣預報\", " + "\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\":\"聯系客服\", " + "\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的獲取 是用 下面的兩個參數 獲取的 不能直接用 公眾平臺的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_credentialappid=********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);
  // 準備請求...
  try
  {
  // 設置參數
  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();
  //發送請求并獲取相應回應數據
  response = request.GetResponse() as HttpWebResponse;
  //直到request.GetResponse()程序才開始向目標網頁發送Post請求
  instream = response.GetResponseStream();
  sr = new StreamReader(instream, encoding);
  //返回結果網頁(html)代碼
  string content = sr.ReadToEnd();
  string err = string.Empty;
  return content;
  }
  catch (Exception ex)
  {
  string err = ex.Message;
  return string.Empty;
  }
 }

 

 /// summary>
 /// 獲取參數進行認證
 /// /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>
 /// 對微信傳入參數進行封裝到數組,拼接字符串,進行加密操作
 /// /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 };//將參數放進數組

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

精彩專題分享:ASP.NET微信開發教程匯總,歡迎大家學習。

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

您可能感興趣的文章:
  • 微信小程序 獲取微信OpenId詳解及實例代碼
  • MVC微信網頁授權獲取用戶OpenId
  • PHP通過微信跳轉的Code參數獲取用戶的openid(關鍵代碼)
  • 微信公眾號支付(一)如何獲取用戶openId
  • 微信公眾平臺實現獲取用戶OpenID的方法
  • .net實現微信公眾賬號接口開發實例代碼
  • .net開發微信公眾平臺實例教程
  • asp.net微信開發(永久素材管理)
  • asp.net開發微信公眾平臺之獲取用戶消息并處理
  • .NET微信公眾號獲取OpenID和用戶信息

標簽:南寧 平涼 青海 衢州 崇左 洛陽 贛州 汕尾

巨人網絡通訊聲明:本文標題《asp.net微信開發(開發者接入)》,本文關鍵詞  asp.net,微信,開發,開發者,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net微信開發(開發者接入)》相關的同類信息!
  • 本頁收集關于asp.net微信開發(開發者接入)的相關信息資訊供網民參考!
  • 推薦文章