首页 > PHP资讯 > 工具库 > asp.net微信开发开发者接入技巧

asp.net微信开发开发者接入技巧

工具库
这篇文章主要介绍了asp.net微信开发中有关开发者接入的相关内容,需要的朋友可以参考下

先上图,看一看需要进行哪些项目的操作:

 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 = "{" + "rn";  postData += ""button":[ " + "rn";  postData += "{ " + "rn";  postData += ""name":"简单查"," + "rn";  postData += ""sub_button":[" + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"我的薪资", " + "rn";  postData += " "key":"mypay"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"天气预报", " + "rn";  postData += " "key":"tianqiyubao"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"view"," + "rn";  postData += " "name":"火车票查询", " + "rn";  postData += " "url":"http://www.deqiaohr.com.cn/*******.aspx"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"开心一刻", " + "rn";  postData += " "key":"kaixinyixiao"" + "rn";  postData += " }]" + "rn";  postData += "}," + "rn";  postData += "{" + "rn";  postData += ""name":"会员管理", " + "rn";  postData += ""sub_button":[" + "rn";  postData += "{ " + "rn";  postData += " "type":"view"," + "rn";  postData += " "name":"会员注册", " + "rn";  postData += " "url":"http://www.deqiaohr.com.cn/****.aspx"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"view"," + "rn";  postData += " "name":"重置密码", " + "rn";  postData += " "url":"http://www.deqiaohr.com.cn/****.aspx"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"修改资料", " + "rn";  postData += " "key":"updateMessage"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"我的提问", " + "rn";  postData += " "key":"mywen"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"联系客服", " + "rn";  postData += " "key":"PhoneSerices"" + "rn";  postData += " }]" + "rn";  postData += "}," + "rn";  postData += "{" + "rn";  postData += ""name":"活动通知"," + "rn";  postData += ""sub_button":[" + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"近期活动", " + "rn";  postData += " "key":"yuangonghuodong"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"近期通知", " + "rn";  postData += " "key":"yuangongtongzhi"" + "rn";  postData += "}," + "rn";  postData += "{ " + "rn";  postData += " "type":"click"," + "rn";  postData += " "name":"有问必答", " + "rn";  postData += " "key":"youwenbida"" + "rn";  postData += " }]" + "rn";  postData += "}]" + "rn";  postData += "}" + "rn";  //自定义菜单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(); //微信接入的测试  }   }  ///  /// 获取通行证 ///  ///  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; }  ///  /// 加载菜单项 ///  /// 
 ///  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微信开发开发者接入技巧的详细内容,更多请关注php中文网其它相关文章!

工具库

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持35不支持0