Beispiel #1
0
        /// <summary>
        /// 最后生成signature:
        /// </summary>
        /// <param name="nonceStr"></param>
        /// <param name="timespanstr"></param>
        /// <returns></returns>
        public static string Getsignature(string nonceStr, string timespanstr)
        {
            if (SessionTools.GetSession("access_tokenzj") == null)
            {
                Getaccesstoken();
            }
            if (SessionTools.GetSession("ticketzj") == null)
            {
                Getjsapi_ticket();
            }
            //string url = HttpContext.Current.Request.Url.ToString();
            //string url = PayConfig.WebSiteDomain() + HttpContext.Current.Request.ApplicationPath;
            string url = PayConfig.WebSiteDomain() + HttpContext.Current.Request.RawUrl;
            string str = "jsapi_ticket=" + (string)SessionTools.GetSession("ticketzj") + "&noncestr=" + nonceStr +
                         "&timestamp=" + timespanstr + "&url=" + url;// +"&wxref=mp.weixin.qq.com";
            string singature = SHA1Util.getSha1(str);

            return(singature.ToLower());
        }
Beispiel #2
0
        /// <summary>
        /// 接着获取jsapi_ticket:
        /// 用第一步拿到的access_token 采用http GET方式请求获得jsapi_ticket
        /// (有效期7200秒,开发者必须在自己的服务全局缓存jsapi_ticket)
        /// </summary>
        /// <returns></returns>
        public static string Getjsapi_ticket()
        {
            string         accesstoken = (string)SessionTools.GetSession("access_tokenzj");
            string         urljson     = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accesstoken + "&type=jsapi";
            string         strjson     = "";
            UTF8Encoding   encoding    = new UTF8Encoding();
            HttpWebRequest myRequest   = (HttpWebRequest)WebRequest.Create(urljson);

            myRequest.Method      = "GET";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response       = myRequest.GetResponse() as HttpWebResponse;
            Stream          responseStream = response.GetResponseStream();
            StreamReader    reader         = new System.IO.StreamReader(responseStream, Encoding.UTF8);
            string          srcString      = reader.ReadToEnd();

            reader.Close();
            if (srcString.Contains("ticket"))
            {
                CommonJsonModel model = new CommonJsonModel(srcString);
                strjson = model.GetValue("ticket");
                SessionTools.SetSession("ticketzj", strjson);
            }
            return(strjson);
        }