Esempio n. 1
0
        public string GetSignature(string url)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("noncestr", nonceStr);
            dic.Add("jsapi_ticket", WechatApi.GetAccessTokenAndRefresh());
            dic.Add("timestamp", timestamp);
            dic.Add("url", url);

            Dictionary <string, string> sortDic = dic.OrderBy(e => e.Key).ToDictionary(k => k.Key, v => v.Value);
            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> pair in sortDic)
            {
                sb.Append(pair.Key);
                sb.Append("=");
                sb.Append(pair.Value);
                sb.Append("&");
            }
            sb.Remove(sb.Length - 1, 1);

            string sign = StringCoding.EncodeSHA1(sb.ToString()).ToLower();

            LogHelper.Info(String.Format("WxPayJsConfig GetSignature:{0} -> {1}", sb.ToString(), sign));

            return(sign);
        }
Esempio n. 2
0
        public static void Test()
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("jsapi_ticket", "sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg");
            dic.Add("timestamp", "1414587457");
            dic.Add("url", "http://mp.weixin.qq.com?params=value");
            dic.Add("noncestr", "Wm3WZYTPz0wzccnW");

            Dictionary <string, string> sortDic = dic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> pair in sortDic)
            {
                sb.Append(pair.Key);
                sb.Append("=");
                sb.Append(pair.Value);
                sb.Append("&");
            }
            sb.Remove(sb.Length - 1, 1);

            Console.WriteLine(sb.ToString());

            string codeString = StringCoding.EncodeSHA1(sb.ToString());

            Console.WriteLine(codeString);
        }
Esempio n. 3
0
        /// <summary>
        /// 对时间戳和随机数签名
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <returns></returns>
        public static string Sign(string timestamp, string nonce)
        {
            string token = ConfigurationManager.AppSettings["WechatToken"];

            string[] tmpArr = { token, timestamp, nonce };

            Array.Sort(tmpArr);

            string tmpStr = string.Join("", tmpArr);

            return(StringCoding.EncodeSHA1(tmpStr).ToLower());
        }
Esempio n. 4
0
 private void buttonSHA1_Click(object sender, EventArgs e)
 {
     richTextBoxOut.Text = StringCoding.EncodeSHA1(richTextBoxIn.Text, ConvertUtil.ConvertEncodingString(comboBoxSHA1.Text));
 }