• 钉钉开发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;
    }
    }

  • 相关阅读:
    pandas 流式导出excel
    django serializer 定制error_message
    selenium etree xpath使用总结
    Python之路--Python基础
    初见Flask
    Git
    MySQL补充——索引,流程控制,数据备份,python操作mysql,SQLAlchemy
    Python之路--Django--Ajax、同源策略、Jsonp、CORS
    Python之路--Django--form组件与model form组件
    Python之路--Django--中间件
  • 原文地址:https://www.cnblogs.com/chenshihaook/p/9054593.html
Copyright © 2020-2023  润新知