无为清净楼资源网 Design By www.qnjia.com
先上图,看一看需要进行哪些项目的操作:
在项目的根目录或者特定的文件夹内,创建一个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" + to, postData); } else { Auth(); //微信接入的测试 } } /// <summary> /// 获取通行证 /// </summary> /// <returns></returns> private string GetAccessToken() { string url_token = "https://api.weixin.qq.com/cgi-bin/token"; 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微信开发的文章,希望大家持续关注。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 张敬轩2005《我的梦想我的路》几何娱乐[WAV+CUE][1G]
- 群星《人到四十男儿情(SRS+WIZOR)》[原抓WAV+CUE]
- 马久越《上善若水HQCDII》[低速原抓WAV+CUE]
- 龚玥《女儿情思》6N纯银SQCD【WAV+CUE】
- 张惠妹《你在看我吗》大碟15 金牌大风[WAV+CUE][1G]
- 群星《左耳·听见爱情》星文唱片[WAV+CUE][1G]
- 群星《抖音嗨疯-DISCO英文版》[WAV+CUE][1G]
- 群星.1990-情义无价(TP版)【中唱】【WAV+CUE】
- 马兆骏.1990-心情·七月【滚石】【WAV+CUE】
- 方伊琪.1979-沙鸥(LP版)【星岛全音】【WAV+CUE】
- 蔡琴《醇厚嗓音》6N纯银SQCD【WAV+CUE】
- 陈曦《遇见HQCD》[WAV+CUE]
- 大提琴-刘欣欣《爱的问候》HDCD[WAV+CUE]
- 周耀辉/邓慧中《从什么时候开始》[320K/MP3][95.71MB]
- 周耀辉/邓慧中《从什么时候开始》[FLAC/分轨][361.29MB]