• 【转载】钉钉开发c#帮助类 获取用户信息 DingHelper.cs


    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

  • 相关阅读:
    3.10_eclipse的使用和Object类型
    团队项目推荐:礼物推荐 —— by Xizhou
    团队项目推荐:不一样的旅游——by Lijun
    团队项目推荐:自动化卡通人脸生成——by Feng Nie
    团队项目推荐:手机社交照片管理软件——by Zhaofan
    Team Project Proposal:App:等车时间预测(重写) -- by DengPan
    对MSRA-USTC 2011的 meng-meng(萌萌) 的team project的学习和评价
    Team Project Proposal: All-in-one多信息源整合的移动应用[Revised in 8th Oct]——by Yuchan
    Team Project Proposal:App:等车时间预测 -- by DengPan
    Team Project Proposal:手机音频美化APP——by Kun Qian
  • 原文地址:https://www.cnblogs.com/vilva/p/10399480.html
Copyright © 2020-2023  润新知