예제 #1
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="Request">当前页面</param>
        public void GetConfig(HttpRequest Request)
        {
            try
            {
                _EnterPrise_MB = this;
                appId          = Config.EAgentID;
                corpId         = Config.ECorpId;
                string corpSecret = Config.ECorpSecret;
                string url        = Request.Url.AbsoluteUri;

                nonceStr  = Helper.randNonce();
                timestamp = Helper.timeStamp();
                //string url = Request.Url.ToString();
                //if (Config.TokenModel == null)
                //{
                //    //这里重新实现
                //    Config.TokenModel = EnterpriseBusiness.GetToken(corpId, corpSecret);
                //}
                //if (string.IsNullOrEmpty(jsApiTicket))
                //{
                if (Config.TokenModel != null && !string.IsNullOrEmpty(Config.TokenModel.access_token))
                {
                    jsApiTicket = EnterpriseBusiness.GetTickets(Config.TokenModel.access_token);
                }
                //}

                string jsApiTicket_Message = string.Format("jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}", jsApiTicket, nonceStr, timestamp, url);

                //string jsApiTicket_Message = string.Format("nonce:{0},timestamp:{1},url:{2},ticket:{3}", nonceStr, timestamp, url, jsApiTicket);

                signature = FormsAuthentication.HashPasswordForStoringInConfigFile(jsApiTicket_Message, "SHA1").ToLower();

                //GenSigurate(nonceStr, timestamp, jsApiTicket, url, ref signature);
                // 这里参数的顺序要按照 key 值 ASCII 码升序排序
                //string rawstring = "{Keys.jsapi_ticket}=" +jsApiTicket
                //                 + "&{Keys.noncestr}=" + nonceStr
                //                 + "&{Keys.timestamp}=" + timestamp
                //                 + "&{Keys.url}=" + url;
                // signature = SignPackageHelper.Sha1Hex(rawstring).ToLower();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
        }