Ejemplo n.º 1
0
        public static string GetSignature(List <KeyValuePair <string, string> > RequestPara)
        {
            //获取所有的参数
            //Dictionary<string, string> dict = new Dictionary<string, string>();
            //var _params = param.Split(',');

            //foreach (var a in _params)
            //{
            //    dict.Add(a, RequestPara.Find(b => b.Key == a).Value);
            //}


            // var config = GetWeChatConfigByID(int.Parse(Request["AppID"]));
            //Todo
            // dict.Add("appSignKey", "iMih0xabKQdw8CBbkTM5Ley84WhN4oL6u5lbDui6G9tUlQo7fJE1CcktZ2UiETnU1FZ0R3ZvzYLKOzmaziyms5QuMia8czkEwFv2TQUg4G45Ha0aHPEHXnhjVqUPnKPJ");

            RequestPara.Add(new KeyValuePair <string, string>("appSignKey", "iMih0xabKQdw8CBbkTM5Ley84WhN4oL6u5lbDui6G9tUlQo7fJE1CcktZ2UiETnU1FZ0R3ZvzYLKOzmaziyms5QuMia8czkEwFv2TQUg4G45Ha0aHPEHXnhjVqUPnKPJ"));

            StringBuilder sb = new StringBuilder();

            OrdinalComparer comp = new OrdinalComparer();
            //参数排序
            var keys = RequestPara.OrderBy(a => a.Key, comp);

            foreach (var a in keys)
            {
                sb.AppendFormat("&{0}={1}", a.Key, a.Value);
            }

            //加密
            return(SHA1UtilHelper.GetSha1(sb.ToString().Substring(1)).ToLower());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建sha1签名
        /// </summary>
        /// <returns></returns>
        public string CreateSHA1Sign()
        {
            StringBuilder sb    = new StringBuilder();
            ArrayList     akeys = new ArrayList(Parameters.Keys);

            akeys.Sort();

            foreach (string k in akeys)
            {
                string v = (string)Parameters[k];
                if (null != v && "".CompareTo(v) != 0 &&
                    "sign".CompareTo(k) != 0 && "key".CompareTo(k) != 0)
                {
                    if (sb.Length == 0)
                    {
                        sb.Append(k + "=" + v);
                    }
                    else
                    {
                        sb.Append("&" + k + "=" + v);
                    }
                }
            }
            string paySign = SHA1UtilHelper.GetSha1(sb.ToString()).ToString().ToLower();

            //debug信息
            this.SetDebugInfo(sb.ToString() + " => sign:" + paySign);
            return(paySign);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// sha1加密
        /// </summary>
        /// <returns></returns>
        private static string CreateSha1(Hashtable parameters)
        {
            var sb    = new StringBuilder();
            var akeys = new ArrayList(parameters.Keys);

            akeys.Sort();

            foreach (var k in akeys)
            {
                if (parameters[k] != null)
                {
                    var v = (string)parameters[k];

                    if (sb.Length == 0)
                    {
                        sb.Append(k + "=" + v);
                    }
                    else
                    {
                        sb.Append("&" + k + "=" + v);
                    }
                }
            }
            return(SHA1UtilHelper.GetSha1(sb.ToString()).ToLower());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取JS-SDK权限验证的签名Signature
        /// </summary>
        /// <param name="jsapi_ticket">jsapi_ticket</param>
        /// <param name="noncestr">随机字符串(必须与wx.config中的nonceStr相同)</param>
        /// <param name="timestamp">时间戳(必须与wx.config中的timestamp相同)</param>
        /// <param name="url">当前网页的URL,不包含#及其后面部分(必须是调用JS接口页面的完整URL)</param>
        /// <returns></returns>
        public static string GetSignature(string jsapi_ticket, string noncestr, long timestamp, string url)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("jsapi_ticket=").Append(jsapi_ticket).Append("&")
            .Append("noncestr=").Append(noncestr).Append("&")
            .Append("timestamp=").Append(timestamp).Append("&")
            .Append("url=").Append(url.IndexOf("#") >= 0 ? url.Substring(0, url.IndexOf("#")) : url);
            return(SHA1UtilHelper.GetSha1(sb.ToString()).ToLower());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加卡券Ext参数的签名加密方法
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static string CreateNonekeySha1(Hashtable parameters)
        {
            var sb      = new StringBuilder();
            var aValues = new ArrayList(parameters.Values);

            aValues.Sort();

            foreach (var v in aValues)
            {
                sb.Append(v);
            }
            return(SHA1UtilHelper.GetSha1(sb.ToString()).ToLower());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 判断微信维权签名
        /// </summary>
        /// <returns></returns>
        public virtual Boolean IsWXsignfeedback()
        {
            StringBuilder sb      = new StringBuilder();
            Hashtable     signMap = new Hashtable();

            foreach (string k in XmlMap.Keys)
            {
                if (SignField.IndexOf(k.ToLower()) != -1)
                {
                    signMap.Add(k.ToLower(), XmlMap[k]);
                }
            }
            signMap.Add("appkey", this.Appkey);


            ArrayList akeys = new ArrayList(signMap.Keys);

            akeys.Sort(ASCIISort.Create());

            foreach (string k in akeys)
            {
                string v = (string)signMap[k];
                if (sb.Length == 0)
                {
                    sb.Append(k + "=" + v);
                }
                else
                {
                    sb.Append("&" + k + "=" + v);
                }
            }

            string sign = SHA1UtilHelper.GetSha1(sb.ToString()).ToString().ToLower();

            this.SetDebugInfo(sb.ToString() + " => SHA1 sign:" + sign);

            return(sign.Equals(XmlMap["AppSignature"]));
        }
        /// <summary>
        /// 判断微信签名
        /// </summary>
        /// <returns></returns>
        public virtual Boolean IsWXsign()
        {
            StringBuilder sb      = new StringBuilder();
            Hashtable     signMap = new Hashtable();

            foreach (string k in XmlMap.Keys)
            {
                if (k != "SignMethod" && k != "AppSignature")
                {
                    signMap.Add(k.ToLower(), XmlMap[k]);
                }
            }
            signMap.Add("appkey", Appkey);


            ArrayList akeys = new ArrayList(signMap.Keys);

            akeys.Sort();

            foreach (string k in akeys)
            {
                string v = (string)signMap[k];
                if (sb.Length == 0)
                {
                    sb.Append(k + "=" + v);
                }
                else
                {
                    sb.Append("&" + k + "=" + v);
                }
            }

            string sign = SHA1UtilHelper.GetSha1(sb.ToString()).ToLower();

            SetDebugInfo(sb + " => SHA1 sign:" + sign);

            return(sign.Equals(XmlMap["AppSignature"]));
        }