using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Net;
using test;
using Newtonsoft.Json.Linq;
/// <summary>
/// DingHelper 的摘要说明
/// </summary>
public class DingHelper
{
public DingHelper()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 获取Access_Token
/// </summary>
/// <returns></returns>
public static string getAccess_Token()
{
string Access_Token = "";
string corpid = ConfigurationSettings.AppSettings["ddQyCorpId"].ToString();
string corpsecret = ConfigurationSettings.AppSettings["CorpSecret"].ToString();
test.HttpHelper http = new test.HttpHelper();
string url = "https://oapi.dingtalk.com/gettoken?corpid=" + corpid + "&corpsecret=" + corpsecret;
string res = http.GetString(url);
if (res != null)
{
JObject obj = JObject.Parse(res);
if (obj["errcode"].ToString() == "0")
{
Access_Token = obj["access_token"].ToString();
}
}
return Access_Token;
}
/// <summary>
/// 获取用户简单信息
/// </summary>
/// <param name="code"></param>
/// <param name="accessToken"></param>
/// <returns></returns>
public static string getUserInfo(string code, string accessToken)
{
string result = null;
HttpHelper http = new HttpHelper();
string url = "https://oapi.dingtalk.com/user/getuserinfo?access_token=" + accessToken + "&code=" + code;
result = http.GetString(url);
return result;
}
/// <summary>
/// 获取用户详细信息
/// </summary>
/// <param name="accessToken"></param>
/// <param name="userid"></param>
/// <returns></returns>
public static string getuserDetail(string accessToken, string userid)
{
string result = null;
HttpHelper http = new HttpHelper();
string url = "https://oapi.dingtalk.com/user/get?access_token=" + accessToken + "&userid=" + userid;
result = http.GetString(url, "", "", false, "UTF-8");
return result;
}
/// <summary>
/// 获取部门详细信息(只支持中文)
/// </summary>
/// <param name="accessToken"></param>
/// <param name="departmentId">部门id</param>
/// <returns></returns>
public static string getDepartmentInfo(string accessToken, string departmentId)
{
string result = null;
HttpHelper http = new HttpHelper();
string url = "https://oapi.dingtalk.com/department/get?access_token=" + accessToken + "&id=" + departmentId;
result = http.GetString(url, "", "", false, "UTF-8");
return result;
}
}
【转载园主】七维月ok