-
Notifications
You must be signed in to change notification settings - Fork 29
/
Test.aspx.cs
169 lines (148 loc) · 7.83 KB
/
Test.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Runtime.Serialization.Json;
using Suite.Common;
using System.IO;
using System.Text;
using Model;
using SubSonic;
using Suite.API;
namespace Suite
{
public partial class Test : System.Web.UI.Page
{
private string m_SuiteKey;
private string m_SuiteSecret;
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);
//}
}
private void GetUserCode(string code)
{
try
{
//string url = "https://oapi.dingtalk.com/user/getuserinfo?access_token={0}&code={1}";
//string accessToken = Helper.GetAccessToken();
//url = string.Format(url, accessToken, code);
string result = "{\"deviceId\":\"7535b6af00572de1bd22da2067156b9e\",\"errcode\":0,\"errmsg\":\"ok\",\"is_sys\":true,\"userid\":\"manager185\"}";//Helper.GetCorpExecuteResult(url);
var ser = new DataContractJsonSerializer(typeof(UserCode));
var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
UserCode userCode = (UserCode)ser.ReadObject(ms);
result = GetUserInfo(userCode.userid);
//context.Response.Write(result);
}
catch (Exception ex)
{
Helper.WriteLog("result: " + ex.Message);
//context.Response.Write(ex.Message);
}
}
private string GetUserInfo(string userId)
{
string accessToken = Helper.GetAccessToken();
string url = "https://oapi.dingtalk.com/user/get?access_token={0}&userid={1}";
url = string.Format(url, accessToken, userId);
string result = Helper.GetCorpExecuteResult(url);
var ser = new DataContractJsonSerializer(typeof(UserInfo));
var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
UserInfo userInfo = (UserInfo)ser.ReadObject(ms);
return result;
}
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();
}
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;
}
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);
}
}
}