婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > asp.net微信開(kāi)發(fā)(開(kāi)發(fā)者接入)

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

熱門(mén)標(biāo)簽:聊城智能電銷(xiāo)機(jī)器人電話 寧德防封版電銷(xiāo)卡 海東防封電銷(xiāo)卡 南昌自動(dòng)外呼系統(tǒng)線路 辦公用地圖標(biāo)注網(wǎng)點(diǎn)怎么操作 安陸市地圖標(biāo)注app 上海市三維地圖標(biāo)注 西寧電銷(xiāo)外呼系統(tǒng)公司 云南外呼系統(tǒng)代理

先上圖,看一看需要進(jìn)行哪些項(xiàng)目的操作:

 

在項(xiàng)目的根目錄或者特定的文件夾內(nèi),創(chuàng)建一個(gè)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);//返回給微信用戶(hù)信息
  }

  ///加載自定義菜單
  string postData = "{" + "\r\n";
  postData += "\"button\":[ " + "\r\n";
  postData += "{ " + "\r\n";
  postData += "\"name\":\"簡(jiǎn)單查\"," + "\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ù)報(bào)\", " + "\r\n";
  postData += " \"key\":\"tianqiyubao\"" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"view\"," + "\r\n";
  postData += " \"name\":\"火車(chē)票查詢(xún)\", " + "\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\":\"開(kāi)心一刻\", " + "\r\n";
  postData += " \"key\":\"kaixinyixiao\"" + "\r\n";
  postData += " }]" + "\r\n";
  postData += "}," + "\r\n";
  postData += "{" + "\r\n";
  postData += "\"name\":\"會(huì)員管理\", " + "\r\n";
  postData += "\"sub_button\":[" + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"view\"," + "\r\n";
  postData += " \"name\":\"會(huì)員注冊(cè)\", " + "\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\":\"我的提問(wèn)\", " + "\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\":\"活動(dòng)通知\"," + "\r\n";
  postData += "\"sub_button\":[" + "\r\n";
  postData += "{ " + "\r\n";
  postData += " \"type\":\"click\"," + "\r\n";
  postData += " \"name\":\"近期活動(dòng)\", " + "\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\":\"有問(wèn)必答\", " + "\r\n";
  postData += " \"key\":\"youwenbida\"" + "\r\n";
  postData += " }]" + "\r\n";
  postData += "}]" + "\r\n";
  postData += "}" + "\r\n";

  //自定義菜單token的獲取 是用 下面的兩個(gè)參數(shù) 獲取的 不能直接用 公眾平臺(tái)的token
  string to = GetAccessToken();
  //本人不喜歡 后臺(tái) 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(); //微信接入的測(cè)試
  }
  
 }

 

 /// 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>
 /// 加載菜單項(xiàng)
 /// /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)備請(qǐng)求...
  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ā)送請(qǐng)求并獲取相應(yīng)回應(yīng)數(shù)據(jù)
  response = request.GetResponse() as HttpWebResponse;
  //直到request.GetResponse()程序才開(kāi)始向目標(biāo)網(wǎng)頁(yè)發(fā)送Post請(qǐng)求
  instream = response.GetResponseStream();
  sr = new StreamReader(instream, encoding);
  //返回結(jié)果網(wǎng)頁(yè)(html)代碼
  string content = sr.ReadToEnd();
  string err = string.Empty;
  return content;
  }
  catch (Exception ex)
  {
  string err = ex.Message;
  return string.Empty;
  }
 }

 

 /// summary>
 /// 獲取參數(shù)進(jìn)行認(rèn)證
 /// /summary>
 private void Auth()
 {
  string token = "*****";//你申請(qǐng)的時(shí)候填寫(xiě)的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>
 /// 對(duì)微信傳入?yún)?shù)進(jìn)行封裝到數(shù)組,拼接字符串,進(jìn)行加密操作
 /// /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ù)放進(jìn)數(shù)組

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

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

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

您可能感興趣的文章:
  • 微信小程序 獲取微信OpenId詳解及實(shí)例代碼
  • MVC微信網(wǎng)頁(yè)授權(quán)獲取用戶(hù)OpenId
  • PHP通過(guò)微信跳轉(zhuǎn)的Code參數(shù)獲取用戶(hù)的openid(關(guān)鍵代碼)
  • 微信公眾號(hào)支付(一)如何獲取用戶(hù)openId
  • 微信公眾平臺(tái)實(shí)現(xiàn)獲取用戶(hù)OpenID的方法
  • .net實(shí)現(xiàn)微信公眾賬號(hào)接口開(kāi)發(fā)實(shí)例代碼
  • .net開(kāi)發(fā)微信公眾平臺(tái)實(shí)例教程
  • asp.net微信開(kāi)發(fā)(永久素材管理)
  • asp.net開(kāi)發(fā)微信公眾平臺(tái)之獲取用戶(hù)消息并處理
  • .NET微信公眾號(hào)獲取OpenID和用戶(hù)信息

標(biāo)簽:南寧 青海 衢州 崇左 洛陽(yáng) 贛州 汕尾

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net微信開(kāi)發(fā)(開(kāi)發(fā)者接入)》,本文關(guān)鍵詞  asp.net,微信,開(kāi)發(fā),開(kāi)發(fā)者,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net微信開(kāi)發(fā)(開(kāi)發(fā)者接入)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于asp.net微信開(kāi)發(fā)(開(kāi)發(fā)者接入)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 介休市| 尼木县| 鲁甸县| 瓦房店市| 丹东市| 布拖县| 洪湖市| 田林县| 安岳县| 卢湾区| 富阳市| 沛县| 清徐县| 博客| 南溪县| 区。| 岚皋县| 卢氏县| 德保县| 安图县| 寻甸| 巨野县| 福建省| 安远县| 井陉县| 图木舒克市| 东阿县| 泸水县| 民县| 若羌县| 遂溪县| 咸宁市| 江油市| 奉节县| 沾益县| 瓮安县| 新丰县| 澄城县| 库尔勒市| 吉木萨尔县| 美姑县|