Exemple #1
0
        /// <summary>
        /// 生成请求的参数字符串
        /// </summary>
        /// <param name="sParaTemp">请求参数</param>
        /// <returns></returns>
        public static string CreateRequestParam(SortedDictionary <string, string> sParaTemp)
        {
            //待签名请求参数数组
            Dictionary <string, string> sPara = new Dictionary <string, string>();

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

            //“参数=参数值”的模式用“&”字符拼接
            string temp = SignCore.CreateLinkString(sPara);

            //获得签名结果
            string mysign = SignCore.CreateSign(temp, SignConfig.AppSecret);

            //生成请求的参数字符串
            StringBuilder prestr = new StringBuilder();

            //other param
            foreach (KeyValuePair <string, string> par in sParaTemp)
            {
                prestr.Append(par.Key + "=" + par.Value + "&");
            }

            //sign
            prestr.Append("sign=" + mysign);

            return(prestr.ToString());
        }
Exemple #2
0
        public static string CreateRequestMySign(SortedDictionary <string, string> sParaTemp)
        {
            //过滤签名参数数组
            var sPara = SignCore.FilterPara(sParaTemp);

            //“参数=参数值”的模式用“&”字符拼接
            string temp = SignCore.CreateLinkString(sPara);

            //获得签名结果
            string mysign = SignCore.CreateSign(temp, SignConfig.AppSecret);

            return(mysign);
        }
Exemple #3
0
        /// <summary>
        /// 对请求参数进行签名
        /// </summary>
        /// <param name="paramReqs"></param>
        /// <param name="secret"></param>
        /// <returns></returns>
        public string SignRequest(SortedDictionary <string, string> paramReqs, string secret)
        {
            //待签名请求参数数组
            Dictionary <string, string> sPara = new Dictionary <string, string>();

            //过滤签名参数数组
            sPara = SignCore.FilterPara(paramReqs);

            //“参数=参数值”的模式用“&”字符拼接
            string temp = SignCore.CreateLinkString(sPara);

            //获得签名结果
            string mysign = SignCore.CreateSign(temp, secret);

            return(mysign);
        }
Exemple #4
0
        /// <summary>
        /// 验证sign是否正确
        /// </summary>
        /// <param name="paramReqs">请求的参数</param>
        /// <param name="sign">签名结果</param>
        /// <param name="secret">密钥</param>
        /// <param name="_input_charset">编码格式</param>
        /// <returns></returns>
        public bool VerifySign(SortedDictionary <string, string> paramReqs, string sign, string secret, string _input_charset = "utf-8")
        {
            //过滤签名参数数组
            var sPara = SignCore.FilterPara(paramReqs);

            //“参数=参数值”的模式用“&”字符拼接
            string temp = SignCore.CreateLinkString(sPara);

            //获得签名结果
            string mysign = SignCore.CreateSign(temp, secret, _input_charset);

            if (mysign == sign)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }