public static string GetWineyunToken() { lock (GetWineyunTokenObj) { string token = KCache.GetCacheStr(WineyunTokenCacheKey); if (String.IsNullOrEmpty(token)) { string str = KHttpWebResponse.Get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + WineyunAppId + "&secret=" + WineyunAppSecret + "", null); if (str != null || !String.IsNullOrEmpty(str)) { Dictionary <string, Object> json = KJson.DecodeJson(str); if (json != null) { string access_token = json["access_token"] + ""; string expires_in = json["expires_in"] + ""; if (!String.IsNullOrEmpty(access_token)) { int expires = Convert.ToInt32(expires_in) / 2; KCache.AddCacheObj(WineyunTokenCacheKey, access_token, expires / 60); token = access_token; } } } if (String.IsNullOrEmpty(token)) { // KLogs.WriteError("获取token失败", "token:" + str); } } return(token); } }
public static string GetGroupTokenEndUrlParameters(int groupid, int userid) { string token = KCache.GetCacheStr(KAuthConfig.YijinTokenKey + "&" + groupid + "&" + userid); if (String.IsNullOrEmpty(token)) { string timeStamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(); string nonceStr = KNoncestr.CreateNoncestr(8); token = "timestamp=" + timeStamp + "&noncestr=" + nonceStr + "&token=" + GetToken(timeStamp, nonceStr, groupid, userid); KCache.AddCacheObj(KAuthConfig.YijinTokenKey + "&" + groupid + "&" + userid, token, KAuthConfig.GroupUserTokenKeepTime / 60); } return(token); }