/// <summary> /// 保存服务器定时推送过来的Ticket /// </summary> /// <param name="tb">解析后hashTable</param> public void SaveSuiteTicket(Hashtable tb) { try { SuiteKeyInfo suiteKeyInfo = new SuiteKeyInfo(tb["SuiteKey"]); suiteKeyInfo.SuiteTicket = tb["SuiteTicket"].ToString(); suiteKeyInfo.TimeStamp = tb["TimeStamp"].ToString(); DingApiDispatch dingApi = new DingApiDispatch(suiteKeyInfo.SuiteKey.Trim(), suiteKeyInfo.SuiteSecret.Trim(), suiteKeyInfo.SuiteTicket.Trim()); //获取套件访问Token SuiteAccessToken suiteAccessToken = dingApi.GetSuiteAccessToken(); if (suiteAccessToken != null) { suiteKeyInfo.SuiteToken = suiteAccessToken.suite_access_token; suiteKeyInfo.SuiteTokenExpires = DateTime.Now.AddSeconds(suiteAccessToken.expires_in); suiteKeyInfo.Save(); } } catch (Exception ex) { Logger.InfoFormat("Err", ex.Message); //Helper.WriteLog("Err:" + ex.Message); } }
/// <summary> /// 获取套件访问Token(suite_access_token) /// </summary> /// <returns> /// suite_access_token 应用套件access_token /// expires_in 有效期 /// </returns> public SuiteAccessToken GetSuiteAccessToken() { try { string postUrl = "https://oapi.dingtalk.com/service/get_suite_token"; string postData = "{\"suite_key\":\"" + suite_key + "\",\"suite_secret\": \"" + suite_secret + "\", \"suite_ticket\": \"" + suite_ticket + "\"}"; string result = WebRequestPost(postUrl, postData); var ser = new DataContractJsonSerializer(typeof(SuiteAccessToken)); var ms = new MemoryStream(Encoding.UTF8.GetBytes(result)); SuiteAccessToken suiteAccessToken = (SuiteAccessToken)ser.ReadObject(ms); return(suiteAccessToken); } catch (Exception ex) { Logger.InfoFormat("Err", ex.Message); return(null); } }