小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

微信服務(wù)號校驗URL核心代碼

 實力決定地位 2021-04-06
/驗證URL        // @param sMsgSignature: 簽名串,對應(yīng)URL參數(shù)的msg_signature        // @param sTimeStamp: 時間戳,對應(yīng)URL參數(shù)的timestamp        // @param sNonce: 隨機串,對應(yīng)URL參數(shù)的nonce        // @param sEchoStr: 隨機串,對應(yīng)URL參數(shù)的echostr        // @param sReplyEchoStr: 解密之后的echostr,當return返回0時有效        // @return:成功0,失敗返回對應(yīng)的錯誤碼
        public int VerifyURL(string sMsgSignature, string sTimeStamp, string sNonce, string sEchoStr, ref string sReplyEchoStr)
        {            int ret = 0;            if (m_sEncodingAESKey.Length != 43)
            {                return (int)WXBizMsgCryptErrorCode.WXBizMsgCrypt_IllegalAesKey;
            }
            ret = VerifySignature(m_sToken, sTimeStamp, sNonce, sEchoStr, sMsgSignature);            if (0 != ret)
            {                return ret;
            }
            sReplyEchoStr = "";            string cpid = "";            try
            {
                sReplyEchoStr = Cryptography.AES_decrypt(sEchoStr, m_sEncodingAESKey, ref cpid); //m_sCorpID);            }            catch (Exception)
            {
                sReplyEchoStr = "";                return (int)WXBizMsgCryptErrorCode.WXBizMsgCrypt_DecryptAES_Error;
            }            if (cpid != m_sCorpID)
            {
                sReplyEchoStr = "";                return (int)WXBizMsgCryptErrorCode.WXBizMsgCrypt_ValidateCorpid_Error;
            }            return 0;
        }

以上是一段微信逛網(wǎng)提供的多年校驗URL代碼,單此代碼我在微信企業(yè)號中使用過。目前由于公司需要做微信服務(wù)號使用時死活就報“簽名錯誤-40001”.最后根據(jù)博客了解自己編寫一個校驗簡單的方法。

#region 自己額外添加        /// <summary>
        /// MD5 加密        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string Sha1(string s)
        {            using (var sha1 = SHA1.Create())
            {                var result = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));                var strResult = BitConverter.ToString(result);                return strResult.Replace("-", "").ToUpper();
            }
        }        /// <summary>
        /// 驗證微信簽名        /// </summary>
        /// <param name="token">token</param>
        /// <param name="signature">簽名</param>
        /// <param name="timestamp">時間戳</param>
        /// <param name="nonce">隨機數(shù)</param>
        /// <returns></returns>
        public static bool WooCheckSignature(string token,             string signature, string timestamp, string nonce)
        {            string[] ArrTmp = { token, timestamp, nonce };            //字典排序            Array.Sort(ArrTmp);            //拼接
            string tmpStr = string.Join("", ArrTmp);            //sha1驗證
            tmpStr = Sha1(tmpStr); //FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");                                   //tmpStr = Membership.CreateUser(tmpStr, "SHA1");
            tmpStr = tmpStr.ToLower();            if (tmpStr == signature)
            {                return true;
            }            else
            {                return false;
            }
        }        #endregion 自己額外添加

用以上方法就方法就可以了。.net core 控制器使用

  /// <summary>
        ///回調(diào)地址        /// </summary>
        /// <returns></returns>
        public IActionResult InitWxPort(string echoStr, string signature, string timestamp, string nonce)
        {            var httpcontext = _accessor.HttpContext;            if (httpcontext.Request.Method.ToLower().Equals("get"))
            {                string token = Constant.CorpToken;                //WeixinUtiliy weixin = new WeixinUtiliy();
                if (WeixinUtiliy.WooCheckSignature(token, signature, timestamp, nonce))
                {                    return Content(echoStr);
                }                return Content("no as");                //return Content(weixin.Auth2(echoStr, signature, timestamp, nonce));            }            else
            {                return Ok();

            }
            
        }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多