Example #1
0
        /// <summary>
        /// 获取返回时的签名验证结果
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="sign">对比的签名结果</param>
        /// <returns>签名验证结果</returns>
        // ReSharper disable once InconsistentNaming
        private static bool GetSignVeryfyRSA(SortedDictionary <string, string> inputPara, string sign)
        {
            //过滤空值、sign与sign_type参数
            Dictionary <string, string> sPara = FilterPara(inputPara);

            //获取待签名字符串
            string preSignStr = CreateLinkString(sPara);

            //获得签名验证结果
            return(AlipayRSA.Verify(preSignStr, sign, RSAPublicKey, InputCharset));
        }
Example #2
0
        /// <summary>
        ///  验证消息是否是支付宝发出的合法消息
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="notifyId">通知验证ID</param>
        /// <param name="sign">支付宝生成的签名结果</param>
        /// <param name="signType"></param>
        /// <returns>验证结果</returns>
        public static bool Verify(SortedDictionary <string, string> inputPara, string notifyId, string sign, string signType, string paytype)
        {
            //获取返回时的签名验证结果
            //bool isSign = signType.ToUpper() == "RSA" ? GetSignVeryfyRSA(inputPara, sign) : GetSignVeryfyMD5(inputPara, sign);
            string PublicKey = string.Empty;

            if (paytype == "APP")
            {
                PublicKey = RSAPublicKey;
            }
            else if (paytype == "H5")
            {
                PublicKey = alipay_public_key;
            }
            bool isSign = AlipayRSA.RSACheckV1(inputPara, PublicKey, InputCharset, signType);
            //获取是否是支付宝服务器发来的请求的验证结果
            string responseTxt = "false";

            if (!string.IsNullOrEmpty(notifyId))
            {
                responseTxt = GetResponseTxt(notifyId);
            }
            return(responseTxt == "true" && isSign);
        }