Exemple #1
0
        private static string GetMsg(string remsg, ResultCryptography ccg)
        {
            if (ccg.HasCrypto())
            {
                string sEncryptMsg = "";

                WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(ccg.sToken, ccg.sEncodingAESKey, ccg.sAppID);
                int           ret   = 0;
                ret = wxcpt.EncryptMsg(remsg, ccg.timestamp, ccg.nonce, ref sEncryptMsg);

                if (ret != 0)
                {
                    LogHelper.WriteLog("ERR: Encrypt fail:" + ErrorManage.GetErrorInfo(ret));
                    return("");
                }

                return(sEncryptMsg);
            }

            return(remsg);
        }
Exemple #2
0
        /// <summary>
        /// 微信回调入口
        /// </summary>
        /// <param name="Request"></param>
        /// <param name="Response"></param>
        public static void ReceviceMain(HttpRequestBase Request, HttpResponseBase Response)
        {
            try
            {
                if (Request.HttpMethod.ToLower() != "post")
                {
                    Response.End();
                }
                else
                {
                    Stream s = System.Web.HttpContext.Current.Request.InputStream;
                    byte[] b = new byte[s.Length];
                    s.Read(b, 0, (int)s.Length);
                    var    postStr = Encoding.UTF8.GetString(b);
                    string sMsg    = "";
                    //LogHelper.WriteLog("post结果:" + postStr);
                    var checkgrp = new ResultCryptography()
                    {
                        encrypttype     = "raw",
                        timestamp       = "",
                        nonce           = "",
                        sToken          = token,
                        sEncodingAESKey = encodingAESKey,
                        sAppID          = appid
                    };
                    if (Request.QueryString["encrypt_type"] != null && Request.QueryString["encrypt_type"].ToLower() == "aes")
                    {
                        //解密
                        string sReqMsgSig    = Request.QueryString["msg_signature"].ToString();
                        string sReqTimeStamp = Request.QueryString["timestamp"].ToString();
                        string sReqNonce     = Request.QueryString["nonce"].ToString();

                        checkgrp.encrypttype = "aes";
                        checkgrp.timestamp   = sReqTimeStamp;
                        checkgrp.nonce       = sReqNonce;

                        WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAESKey, appid);

                        int ret = 0;
                        ret = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, postStr, ref sMsg);

                        if (ret != 0)
                        {
                            LogHelper.WriteLog("ERR: Decrypt fail:" + ErrorManage.GetErrorInfo(ret));
                            return;
                        }
                    }
                    else
                    {
                        sMsg = postStr;
                    }
                    var msgModel = XmlHelpler.GetMsg(sMsg);

                    ReceiveMsg.SwitchCase(Response, msgModel, checkgrp);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("ReceviceMain-" + ex.Message + "," + ex.Source + "," + ex.StackTrace);
            }
        }