예제 #1
0
        public void GetWXConfig()
        {
            var dtNow = DateTime.Now;
            //string nonceStr = "Wm3WZYTPz0wzccnW";// DateTime.Now.ToString("yyyyMMddHHmmss");
            string nonceStr  = WxJSSDKConfig.create_nonce_str(16);
            long   timestamp = WxJSSDKConfig.create_timestamp(dtNow);
            var    token     = WXInterface.GetAccessToken(Config.AppID, Config.AppSecret).access_token;

            if (token != null)
            {
                string url    = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;//获取当前url
                var    ticket = WXInterface.GetTicket(token, "jsapi");
                if (ticket != null)
                {
                    string signature = create_signature(ticket.ticket, nonceStr, timestamp.ToString(), url);
                    ViewBag.ticket    = ticket.ticket;
                    ViewBag.signature = signature;
                }
                ViewBag.token     = token;
                ViewBag.nonceStr  = nonceStr;
                ViewBag.timestamp = timestamp;
                ViewBag.appId     = Config.AppID;
                ViewBag.url       = url;
            }
        }
예제 #2
0
        /// <summary>
        /// 获取微信jssdk鉴权配置
        /// </summary>
        /// <param name="wxContext"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public WxJSSDKConfig GetWxJSSDKConfig(WxContext wxContext, string url)
        {
            WxJSSDKConfig config = new WxJSSDKConfig();

            config.AppId     = wxContext.AuthInfo.AppId;
            config.TimeStamp = Convert.ToString(DateTimeUtil.GetCurrentTimeStamp());
            config.Signature = GetSignture(GetTicket(wxContext).Ticket, wxContext.NonceStr, url, config.TimeStamp);
            config.NonceStr  = wxContext.NonceStr;

            return(config);
        }