Ejemplo n.º 1
0
        /// <summary>
        /// 根据unionid获取userid
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string getUseridByUnionid(string accessToken, string unionid)
        {
            try
            {
                IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getUseridByUnionid");
                OapiUserGetUseridByUnionidRequest req = new OapiUserGetUseridByUnionidRequest();

                req.Unionid = unionid;
                req.SetHttpMethod("GET");
                OapiUserGetUseridByUnionidResponse rsp = client.Execute(req, accessToken);

                if (rsp != null && rsp.Errcode == 0)
                {
                    return(rsp.Userid);
                }
                else
                {
                    throw new Exception(rsp.Errmsg);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据unionid获取userid
        /// </summary>
        /// <param name="accessToken">accessToken</param>
        /// <param name="unionId">员工在当前开发者企业账号范围内的唯一标识,系统生成,固定值,不会改变</param>
        public OapiUserGetUseridByUnionidResponse GetUserIdByUnionId(string accessToken, string unionId)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getUseridByUnionid");
            OapiUserGetUseridByUnionidRequest request = new OapiUserGetUseridByUnionidRequest();

            request.Unionid = unionId;
            request.SetHttpMethod("GET");
            OapiUserGetUseridByUnionidResponse response = client.Execute(request, accessToken);

            return(response);
        }