/// <summary> /// 公众号处理 /// </summary> /// <returns></returns> private string GZProcess() { string strGzContent = string.Empty; WXGZConfigEntity gzConfig = XmlToEntity.GetGZConfig(); //如果为公众平台且未使用加密,直接返回文本 if (string.IsNullOrEmpty(gzConfig.EncodingAESKey)) { strGzContent = ConvertDataType.Strem2String(HttpContext.Current.Request.InputStream, Encoding.UTF8); return(strGzContent); } //校验签名及返回解析后的content CheckMsgSignature(ref strGzContent); return(strGzContent); }
/// <summary> /// 校验签名 /// </summary> /// <param name="sToken">token</param> /// <param name="sEncodingAESKey">配置的加密字符串</param> /// <param name="sID">CropID或AppID</param> /// <returns></returns> private bool CheckMsgSignature(ref string sMsg) { string sReqMsgSig = HttpContext.Current.Request.Params["msg_signature"]; string sReqTimeStamp = HttpContext.Current.Request.Params["timestamp"]; string sReqNonce = HttpContext.Current.Request.Params["nonce"]; // Post请求的密文数据 string sReqData = ConvertDataType.Strem2String(HttpContext.Current.Request.InputStream, Encoding.UTF8); int ret = this._wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, sReqData, ref sMsg); if (ret != 0) { //System.Console.WriteLine("ERR: Decrypt Fail, ret: " + ret); return(false); } return(true); }