Esempio n. 1
0
        public void GETWXCONFIG(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo)
        {
            Dictionary <string, string> param = new Dictionary <string, string>();

            TimeSpan ts           = DateTime.Now - new DateTime(1970, 1, 1);
            long     timestamp    = Convert.ToInt64(ts.TotalSeconds);
            string   appId        = CommonHelp.GetConfig("AppId");
            string   jsapi_ticket = CommonHelp.AppConfig("jsapi_ticket");
            string   nonceStr     = CommonHelp.GetRandomString(15);
            string   url          = P1;

            string TOP_FIELD_SIGN = "";

            param.Add("timestamp", timestamp.ToString());
            param.Add("jsapi_ticket", jsapi_ticket);
            param.Add("noncestr", nonceStr);
            param.Add("url", url);

            SortedDictionary <string, string>            dic = new SortedDictionary <string, string>(param);
            IEnumerator <KeyValuePair <string, string> > em  = dic.GetEnumerator();
            // 第1步:把所有参数名和参数值串在一起
            StringBuilder query = new StringBuilder();

            while (em.MoveNext())
            {
                string key = em.Current.Key;
                if (!TOP_FIELD_SIGN.Equals(key, StringComparison.CurrentCultureIgnoreCase))
                {
                    string value = em.Current.Value;
                    if (!string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(key))
                    {
                        query.Append("&").Append(key).Append("=").Append(value);
                    }
                }
            }
            query = new StringBuilder(query.ToString().TrimStart('&'));
            string querystring = HttpUtility.HtmlDecode(query.ToString());
            // 第2步:使用sha1加密
            string signature = WXFWHelp.EnSha1(querystring);

            msg.Result = new
            {
                appId = appId,
                //jsapi_ticket = jsapi_ticket,
                timestamp = timestamp,
                noncestr  = nonceStr,
                url       = url,
                //query = querystring,
                signature = signature
            };
        }