protected void btnGetSuiteToken_Click(object sender, EventArgs e) { string ticket = txtSuiteTicket.Text.Trim(); DingApiDispatch dingApi = new DingApiDispatch(m_SuiteKey, m_SuiteSecret, ticket); //获取套件访问Token dingApi.GetSuiteAccessToken(); }
/// <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) { Helper.WriteLog("Err:" + ex.Message); } }
protected void btnGetAuthInfo_Click(object sender, EventArgs e) { string ticket = txtSuiteTicket.Text.Trim(); DingApiDispatch dingApi = new DingApiDispatch(m_SuiteKey, m_SuiteSecret, ticket); string corpId = txtCorpId.Text.Trim(); string permanentCode = txtPermanentCode.Text.Trim(); //AuthCorp authCorp = dingApi.GetAuthInfo(m_SuiteKey, corpId, permanentCode); }
protected void btnActivateSuite_Click(object sender, EventArgs e) { string ticket = txtSuiteTicket.Text.Trim(); DingApiDispatch dingApi = new DingApiDispatch(m_SuiteKey, m_SuiteSecret, ticket); string corpId = txtCorpId.Text.Trim(); string permanentCode = txtPermanentCode.Text.Trim(); //string result = dingApi.ActivateSuite(m_SuiteKey, corpId, permanentCode); }
protected void btnGetPermanentCode_Click(object sender, EventArgs e) { string ticket = txtSuiteTicket.Text.Trim(); DingApiDispatch dingApi = new DingApiDispatch(m_SuiteKey, m_SuiteSecret, ticket); //获取企业的永久授权码 //PermanentCode perCode = dingApi.GetPermanentCode(txtTempAuthCode.Text.Trim()); //txtPermanentCode.Text = perCode.permanent_code; //txtCorpId.Text = perCode.auth_corp_info.corpid; }
protected void btnGetCorpToken_Click(object sender, EventArgs e) { string ticket = txtSuiteTicket.Text.Trim(); DingApiDispatch dingApi = new DingApiDispatch(m_SuiteKey, m_SuiteSecret, ticket); string corpId = txtCorpId.Text.Trim(); string permanentCode = txtPermanentCode.Text.Trim(); //CorpAccessToken corpAccessToken = dingApi.GetCorpToken(corpId, permanentCode); //txtCorpAccessToken.Text = corpAccessToken.access_token; }
/// <summary> /// 保存服务器推送临时授权码 /// </summary> /// <param name="tb"></param> public void SaveTmpAuthCode(Hashtable tb) { SuiteKeyInfo suiteKeyInfo = new SuiteKeyInfo(tb["SuiteKey"]); DingApiDispatch dingApi = new DingApiDispatch(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteSecret, suiteKeyInfo.SuiteTicket); //用临时授权码获得永久授权码 PermanentCode permanentCode = dingApi.GetPermanentCode(suiteKeyInfo.SuiteToken, tb["AuthCode"].ToString()); SuiteCorpInfo suiteCorp = new SuiteCorpInfo(SuiteCorpInfo.Columns.Corpid, permanentCode.auth_corp_info.corpid); suiteCorp.SuiteKey = suiteKeyInfo.SuiteKey; suiteCorp.TmpAuthCode = tb["AuthCode"].ToString(); suiteCorp.PermanentCode = permanentCode.permanent_code; suiteCorp.Corpid = permanentCode.auth_corp_info.corpid; suiteCorp.CorpName = permanentCode.auth_corp_info.corp_name; //获取企业授权的access_token CorpAccessToken corpAccessToken = dingApi.GetCorpToken(suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); suiteCorp.AccessToken = corpAccessToken.access_token; suiteCorp.TokenExpires = DateTime.Now.AddSeconds(corpAccessToken.expires_in); //获取企业授权的授权数据 AuthCorp authCorp = dingApi.GetAuthInfo(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); suiteCorp.CorpLogoUrl = authCorp.auth_corp_info.corp_logo_url; suiteCorp.Mobile = authCorp.auth_user_info.mobile; suiteCorp.Name = authCorp.auth_user_info.name; suiteCorp.Save(); try { foreach (AgentInfo angInfo in authCorp.auth_info.agent) { SuiteCorpAgent suiteCorpAgent = new Select().From(SuiteCorpAgent.Schema) .Where(SuiteCorpAgent.Columns.CorpId).IsEqualTo(suiteCorp.Corpid) .And(SuiteCorpAgent.Columns.AgentId).IsEqualTo(angInfo.agentid) .ExecuteSingle <SuiteCorpAgent>() ?? new SuiteCorpAgent(); suiteCorpAgent.SuiteKey = suiteKeyInfo.SuiteKey; suiteCorpAgent.CorpId = suiteCorp.Corpid; suiteCorpAgent.AgentId = angInfo.agentid; suiteCorpAgent.AgentName = angInfo.agent_name; suiteCorpAgent.LogoUrl = angInfo.logo_url; suiteCorpAgent.Appid = angInfo.appid; dingApi.ActivateSuite(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); Agent agent = dingApi.GetAgent(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode, suiteCorpAgent.AgentId); suiteCorpAgent.Description = agent.description; suiteCorpAgent.IsClose = agent.close; suiteCorpAgent.Save(); } } catch (Exception ex) { Helper.WriteLog("Err:" + ex.Message); } }
/// <summary> /// 保存服务器推送临时授权码 /// </summary> /// <param name="tb"></param> public void SaveTmpAuthCode(Hashtable tb) { SuiteKeyInfo suiteKeyInfo = new SuiteKeyInfo(tb["SuiteKey"]); DingApiDispatch dingApi = new DingApiDispatch(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteSecret, suiteKeyInfo.SuiteTicket); //用临时授权码获得永久授权码 PermanentCode permanentCode = dingApi.GetPermanentCode(suiteKeyInfo.SuiteToken, tb["AuthCode"].ToString()); SuiteCorpInfo suiteCorp = new SuiteCorpInfo(SuiteCorpInfo.Columns.Corpid, permanentCode.auth_corp_info.corpid); suiteCorp.SuiteKey = suiteKeyInfo.SuiteKey; suiteCorp.TmpAuthCode = tb["AuthCode"].ToString(); suiteCorp.PermanentCode = permanentCode.permanent_code; suiteCorp.Corpid = permanentCode.auth_corp_info.corpid; suiteCorp.CorpName = permanentCode.auth_corp_info.corp_name; //获取企业授权的access_token CorpAccessToken corpAccessToken = dingApi.GetCorpToken(suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); suiteCorp.AccessToken = corpAccessToken.access_token; suiteCorp.TokenExpires = DateTime.Now.AddSeconds(corpAccessToken.expires_in); //获取企业授权的授权数据 AuthCorp authCorp = dingApi.GetAuthInfo(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); suiteCorp.CorpLogoUrl = authCorp.auth_corp_info.corp_logo_url; suiteCorp.Mobile = authCorp.auth_user_info.mobile; suiteCorp.Name = authCorp.auth_user_info.name; suiteCorp.Save(); try { foreach (AgentInfo angInfo in authCorp.auth_info.agent) { SuiteCorpAgent suiteCorpAgent = new Select().From(SuiteCorpAgent.Schema) .Where(SuiteCorpAgent.Columns.CorpId).IsEqualTo(suiteCorp.Corpid) .And(SuiteCorpAgent.Columns.AgentId).IsEqualTo(angInfo.agentid) .ExecuteSingle<SuiteCorpAgent>() ?? new SuiteCorpAgent(); suiteCorpAgent.SuiteKey = suiteKeyInfo.SuiteKey; suiteCorpAgent.CorpId = suiteCorp.Corpid; suiteCorpAgent.AgentId = angInfo.agentid; suiteCorpAgent.AgentName = angInfo.agent_name; suiteCorpAgent.LogoUrl = angInfo.logo_url; suiteCorpAgent.Appid = angInfo.appid; dingApi.ActivateSuite(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode); Agent agent = dingApi.GetAgent(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorp.Corpid, suiteCorp.PermanentCode, suiteCorpAgent.AgentId); suiteCorpAgent.Description = agent.description; suiteCorpAgent.IsClose = agent.close; suiteCorpAgent.Save(); } } catch (Exception ex) { Helper.WriteLog("Err:" + ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { Helper.WriteLog("result:"); ////#region 获取套件配置参数 ////m_SuiteKey = ConfigurationManager.AppSettings["SuiteKey"]; ////m_SuiteSecret = ConfigurationManager.AppSettings["SuiteSecret"]; ////#endregion //string accessToken = Helper.GetAccessToken(); //string url = "https://oapi.dingtalk.com/user/simplelist?access_token="+ accessToken + "&department_id=1"; //string result = Helper.GetCorpExecuteResult(url); List<SuiteKeyInfo> suikKeyList = new Select().From(SuiteKeyInfo.Schema).ExecuteTypedList<SuiteKeyInfo>(); foreach (SuiteKeyInfo suiteKeyInfo in suikKeyList) { DingApiDispatch dingApi = new DingApiDispatch(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteSecret, suiteKeyInfo.SuiteTicket); SuiteCorpInfo corpInfo= new SuiteCorpInfo(SuiteCorpInfo.Columns.SuiteKey, suiteKeyInfo.SuiteKey); AuthCorp authCorp = dingApi.GetAuthInfo(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, corpInfo.Corpid, corpInfo.PermanentCode); if (authCorp.errcode == "0") { foreach (AgentInfo angInfo in authCorp.auth_info.agent) { SuiteCorpAgent suiteCorpAgent = new Select().From(SuiteCorpAgent.Schema) .Where(SuiteCorpAgent.Columns.CorpId).IsEqualTo(corpInfo.Corpid) .And(SuiteCorpAgent.Columns.AgentId).IsEqualTo(angInfo.agentid) .ExecuteSingle<SuiteCorpAgent>() ?? new SuiteCorpAgent(); Agent agent = dingApi.GetAgent(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, corpInfo.Corpid, corpInfo.PermanentCode, suiteCorpAgent.AgentId); suiteCorpAgent.Description = agent.description; suiteCorpAgent.IsClose = agent.close; } } } //List<SuiteCorpAgent> agentList = new Select().From(SuiteCorpAgent.Schema).ExecuteTypedList<SuiteCorpAgent>(); //foreach (SuiteCorpAgent agent in agentList) //{ // SuiteCorpInfo suiteCorpInfo = new Select().From(SuiteCorpInfo.Schema) // .Where(SuiteCorpInfo.Columns.SuiteKey).IsEqualTo(agent.SuiteKey) // .ExecuteSingle<SuiteCorpInfo>(); // SuiteKeyInfo suiteKeyInfo = new SuiteKeyInfo(agent.SuiteKey); // DingApiDispatch dingApi = new DingApiDispatch(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteSecret, // suiteKeyInfo.SuiteTicket); // if (suiteCorpInfo.TokenExpires < DateTime.Now) // { // CorpAccessToken corpAccessToken = dingApi.GetCorpToken(suiteKeyInfo.SuiteToken, suiteCorpInfo.Corpid, // suiteCorpInfo.PermanentCode); // suiteCorpInfo.AccessToken = corpAccessToken.access_token; // suiteCorpInfo.TokenExpires = DateTime.Now.AddSeconds(corpAccessToken.expires_in); // suiteCorpInfo.Save(); // } // string result = dingApi.ActivateSuite(suiteKeyInfo.SuiteKey, suiteKeyInfo.SuiteToken, suiteCorpInfo.Corpid, // suiteCorpInfo.PermanentCode); //} }