示例#1
0
        /// <summary>
        /// 获取返回时的签名验证结果
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="sign">对比的签名结果</param>
        /// <param name="signType">签名方式</param>
        /// <param name="key">交易安全校验码</param>
        /// <param name="code">字符编码格式</param>
        /// <returns>签名验证结果</returns>
        private static bool GetSignVeryfy(SortedDictionary <string, string> inputPara, string sign, string signType, string key, Encoding code)
        {
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            //过滤空值、sign与sign_type参数
            sPara = AlipayCore.FilterPara(inputPara);

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

            //获得签名验证结果
            bool isSgin = false;

            if (sign != null && sign != "")
            {
                switch (signType)
                {
                case "MD5":
                    isSgin = AlipayMD5.Verify(preSignStr, sign, key, code);
                    break;

                default:
                    break;
                }
            }

            return(isSgin);
        }
示例#2
0
        /// <summary>
        /// 获取返回时的签名验证结果
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="sign">对比的签名结果</param>
        /// <returns>签名验证结果</returns>
        private static bool GetAppSignVeryfy(SortedDictionary <string, string> inputPara, string sign, string signType, string publicKey, string appInputCharset)
        {
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            //过滤空值、sign与sign_type参数
            sPara = AlipayCore.FilterPara(inputPara);

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

            //获得签名验证结果
            bool isSgin = false;

            if (sign != null && sign != "")
            {
                switch (signType)
                {
                case "RSA":
                    isSgin = AlipayRSAFromPkcs8.verify(preSignStr, sign, publicKey, appInputCharset);
                    break;

                default:
                    break;
                }
            }

            return(isSgin);
        }
示例#3
0
        /// <summary>
        /// 获取是否是支付宝服务器发来的请求的验证结果
        /// </summary>
        /// <param name="notifyId">通知验证ID</param>
        /// <param name="veryfyUrl">支付宝消息验证地址</param>
        /// <param name="partner">收款支付宝帐户ID</param>
        /// <returns>验证结果</returns>
        private static string GetResponseTxt(string notifyId, string veryfyUrl, string partner)
        {
            string veryfy_url = string.Format("{0}partner={1}&notify_id={2}", veryfyUrl, partner, notifyId);

            //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求
            string responseTxt = AlipayCore.Get_Http(veryfy_url, 120000);

            return(responseTxt);
        }
示例#4
0
        /// <summary>
        /// 获取是否是支付宝服务器发来的请求的验证结果
        /// </summary>
        /// <param name="notify_id">通知验证ID</param>
        /// <returns>验证结果</returns>
        private static string GetAppResponseTxt(string notify_id, string appVeryfyUrl, string partner)
        {
            string veryfy_url = appVeryfyUrl + "partner=" + partner + "&notify_id=" + notify_id;

            //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求
            string responseTxt = AlipayCore.Get_Http(veryfy_url, 120000);

            return(responseTxt);
        }
示例#5
0
        /// <summary>
        /// 生成要请求给支付宝的参数数组
        /// </summary>
        /// <param name="sParaTemp">请求前的参数数组</param>
        /// <param name="signType">签名方式</param>
        /// <param name="key">交易安全校验码</param>
        /// <param name="code">字符编码</param>
        /// <returns>要请求的参数数组字符串</returns>
        private static string BuildRequestParaToString(SortedDictionary <string, string> sParaTemp, string signType, string key, Encoding code)
        {
            //待签名请求参数数组
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            sPara = BuildRequestPara(sParaTemp, signType, key, code);

            //把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
            string strRequestData = AlipayCore.CreateLinkStringUrlencode(sPara, code);

            return(strRequestData);
        }
示例#6
0
        /// <summary>
        /// 获取待签名字符串(调试用)
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <returns>待签名字符串</returns>
        private static string GetPreSignStr(SortedDictionary <string, string> inputPara)
        {
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            //过滤空值、sign与sign_type参数
            sPara = AlipayCore.FilterPara(inputPara);

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

            return(preSignStr);
        }
示例#7
0
        /// <summary>
        /// 生成要请求给支付宝的参数数组
        /// </summary>
        /// <param name="sParaTemp">请求前的参数数组</param>
        /// <param name="signType">签名方式</param>
        /// <param name="key">交易安全校验码</param>
        /// <param name="code">字符编码格式</param>
        /// <returns>要请求的参数数组</returns>
        private static Dictionary <string, string> BuildRequestPara(SortedDictionary <string, string> sParaTemp, string signType, string key, Encoding code)
        {
            //待签名请求参数数组
            Dictionary <string, string> sPara = new Dictionary <string, string>();
            //签名结果
            string mysign = "";

            //过滤签名参数数组
            sPara = AlipayCore.FilterPara(sParaTemp);

            //获得签名结果
            mysign = BuildRequestMysign(sPara, signType, key, code);

            //签名结果与签名方式加入请求提交参数组中
            sPara.Add("sign", mysign);
            sPara.Add("sign_type", signType);

            return(sPara);
        }
示例#8
0
        /// <summary>
        /// 生成请求时的签名
        /// </summary>
        /// <param name="sPara">请求给支付宝的参数数组</param>
        /// <param name="signType">签名方式</param>
        /// <param name="key">交易安全校验码</param>
        /// <param name="code">字符编码格式</param>
        /// <returns>签名结果</returns>
        private static string BuildRequestMysign(Dictionary <string, string> sPara, string signType, string key, Encoding code)
        {
            //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
            string prestr = AlipayCore.CreateLinkString(sPara);

            //把最终的字符串签名,获得签名结果
            string mysign = "";

            switch (signType)
            {
            case "MD5":
                mysign = AlipayMD5.Sign(prestr, key, code);
                break;

            default:
                mysign = "";
                break;
            }

            return(mysign);
        }