Beispiel #1
0
        /// <summary>
        /// 生成请求时的签名
        /// </summary>
        /// <param name="sPara">请求给支付宝的参数数组</param>
        /// <returns>签名结果</returns>
        private static string BuildRequestMysign(Dictionary <string, string> sPara)
        {
            //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
            string prestr = AlipayCore.CreateLinkString(sPara);

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

            switch (_sign_type)
            {
            case "MD5":
                mysign = AlipayMD5.Sign(prestr, _key, _input_charset);
                break;

            case "RSA":
                mysign = AlipayRSA.sign(prestr, _private_key, _input_charset);
                break;

            case "0001":
                mysign = AlipayRSA.sign(prestr, _private_key, _input_charset);
                break;

            default:
                mysign = "";
                break;
            }

            return(mysign);
        }
Beispiel #2
0
        /// <summary>
        /// 获取待签名字符串(调试用)
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <returns>待签名字符串</returns>
        public string GetPreSignStr(Dictionary <string, string> inputPara)
        {
            Dictionary <string, string> sPara = new Dictionary <string, string>();

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

            //根据字母a到z的顺序把参数排序
            sPara = AlipayCore.SortPara(sPara);

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

            return(preSignStr);
        }
Beispiel #3
0
        /// <summary>
        /// 获取返回时的签名验证结果
        /// </summary>
        /// <param name="inputPara">通知返回参数数组</param>
        /// <param name="sign">对比的签名结果</param>
        /// <param name="isSort">是否对待签名数组排序</param>
        /// <returns>签名验证结果</returns>
        private bool GetSignVeryfy(Dictionary <string, string> inputPara, string sign, bool isSort)
        {
            Dictionary <string, string> sPara = new Dictionary <string, string>();

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

            if (isSort)
            {
                //根据字母a到z的顺序把参数排序
                sPara = AlipayCore.SortPara(sPara);
            }
            else
            {
                sPara = SortNotifyPara(sPara);
            }

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

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

            if (sign != null && sign != "")
            {
                switch (_sign_type)
                {
                case "MD5":
                    isSgin = AlipayMD5.Verify(preSignStr, sign, _key, _input_charset);
                    break;

                case "RSA":
                    isSgin = AlipayRSA.verify(preSignStr, sign, _public_key, _input_charset);
                    break;

                case "0001":
                    isSgin = AlipayRSA.verify(preSignStr, sign, _public_key, _input_charset);
                    break;

                default:
                    break;
                }
            }

            return(isSgin);
        }