public weixin(int _DT_id, Lebi_Site CurrentSite = null) { DT_id = _DT_id; BaseConfig_DT dtbcf = null; if (DT_id > 0) { dtbcf = ShopCache.GetBaseConfig_DT(DT_id); if (dtbcf != null) { appid = dtbcf.platform_weixin_id; appkey = dtbcf.platform_weixin_secret; number = dtbcf.platform_weixin_number; platform_image = dtbcf.platform_weixin_image; } } if (DT_id == 0 || dtbcf == null) { if (CurrentSite != null) { if (CurrentSite.platform_weixin_id != "" && CurrentSite.platform_weixin_secret != "") { appid = CurrentSite.platform_weixin_id; appkey = CurrentSite.platform_weixin_secret; number = CurrentSite.platform_weixin_number; } if (appid == "") { appid = ShopCache.GetBaseConfig().platform_weixin_id; } if (appkey == "") { appkey = ShopCache.GetBaseConfig().platform_weixin_secret; } if (number == "") { number = ShopCache.GetBaseConfig().platform_weixin_number; } platform_image = ShopCache.GetBaseConfig().platform_weixin_image; } else { BaseConfig bcf = ShopCache.GetBaseConfig(); appid = bcf.platform_weixin_id; appkey = bcf.platform_weixin_secret; number = bcf.platform_weixin_number; platform_image = bcf.platform_weixin_image; } } Model.weixin.token t = GetToken(); Token = t.access_token; Shop.Bussiness.Site site = new Shop.Bussiness.Site(); url = "https://api.weixin.qq.com/"; reurnurl = ShopCache.GetBaseConfig().HTTPServer + "://" + RequestTool.GetRequestDomain() + site.WebPath + "/platform/login_weixin.aspx"; }
/// <summary> /// 获得TOKEN /// https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx7374191e442b14ef&secret=c2f9f7d4a6985b2dd0194a86b2254d8c /// </summary> /// <returns></returns> public Model.weixin.token GetToken() { //if (EndTime > DateTime.Now) // return tokenmodel; string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appkey; StringBuilder sb = new StringBuilder(); string str = Get(url); JavaScriptSerializer jss = new JavaScriptSerializer(); try { tokenmodel = jss.Deserialize <Model.weixin.token>(str); EndTime = System.DateTime.Now.AddSeconds(tokenmodel.expires_in); return(tokenmodel); } catch (Exception ex) { TxtLog.Add("微信获得TOKEN异常:" + ex.ToString()); return(new Model.weixin.token()); } }