介绍
这篇文章主要介绍了c#微信公众号与订阅号接口开发示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。
c#微信公众号与订阅号接口开发示例代码,具体如下:
using 系统; using 包含; using 先; using 包含; using System.Web.Security; using weixin_api; public class wxgz_api : IHttpHandler { public 才能;void  ProcessRequest (HttpContext 上下文) {才能 ,,,context.Response.ContentType =,“文本/plain"; ,,,string postString =, string.Empty; ,,,if (HttpContext.Current.Request.HttpMethod.ToUpper (),==,“POST") ,,,{ ,,,,,//微信服务器对接口消息 ,,,,,using (Stream Stream =, HttpContext.Current.Request.InputStream) ,,,,,{ ,,,,,,,Byte [], postBytes =, new 字节(stream.Length); ,,,,,,,stream.Read (postBytes, 0, (Int32) stream.Length); ,,,,,,,postString =, Encoding.UTF8.GetString (postBytes); ,,,,,,,处理(postString); ,,,,,} ,,,} ,,, ,,,{ ,,,,,//微信进行的得到测试(开发者认证) ,,,,,WxAuth (); ,,,} ,,}///才能,& lt; summary>///才能,处理信息并应答///才能,& lt;/summary> private 才能;void 处理(string postStr) {才能 ,,,messageHelp help =, new messageHelp (); ,,,string responseContent =, help.ReturnMessage (postStr); ,,,HttpContext.Current.Response.ContentEncoding =, Encoding.UTF8; ,,,HttpContext.Current.Response.Write (responseContent); ,,} # region 才能微信验证 public 才能;void  WxAuth () {才能 ,,,string token =,“xxxxxxxx"; ,,,if (string.IsNullOrEmpty(令牌)) ,,,{ ,,,,,返回; ,,,} ,,,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(签名,令牌,还以为,时间戳,现时标志)) ,,,{ ,,,,,if (! string.IsNullOrEmpty echoString ()) ,,,,,{ ,,,,,,,HttpContext.Current.Response.Write(中的); ,,,,,,,HttpContext.Current.Response.End (); ,,,,,} ,,,} ,,}///才能,& lt; summary>///,才能验证微信签名///才能,& lt;/summary> public 才能;bool  CheckSignature (string 令牌,string 签名,,string 时间戳,,string 现时标志) {才能 ,,,string [], ArrTmp =,{,令牌,时间戳,nonce }; ,,,Array.Sort (ArrTmp); ,,,string tmpStr =, string.Join (““,, ArrTmp); ,,,tmpStr =, FormsAuthentication.HashPasswordForStoringInConfigFile (tmpStr,“SHA1"); ,,,tmpStr =, tmpStr.ToLower (); ,,,if (tmpStr ==,签名) ,,,{ ,,,,,return 真实; ,,,} ,,, ,,,{ ,,,,,return 假; ,,,} ,,} # endregion才能 public 才能;bool  IsReusable {才能 ,才能得到 ,,,{ ,,,,,return 假; ,,,} ,,} }
感谢你能够认真阅读完这篇文章,希望小编分享的“C #微信公众号与订阅号接口开发示例分析”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!