Ejemplo n.º 1
0
        /// <summary>
        /// 根据code获取客户ID
        /// </summary>
        /// <returns></returns>
        public static Result GetDingUserIDByMobile(string Mobile)
        {
            Result result = new Result()
            {
                Code = 1
            };
            string                     accessToken = GetDingToken();
            IDingTalkClient            client      = new DefaultDingTalkClient(dingUrl + "/user/get_by_mobile");
            OapiUserGetByMobileRequest req         = new OapiUserGetByMobileRequest
            {
                Mobile = Mobile
            };

            req.SetHttpMethod("GET");
            OapiUserGetByMobileResponse rsp = client.Execute(req, accessToken);

            if (rsp != null && rsp.Errcode == 0)
            {
                result.StrOjb = rsp.Userid;
            }
            else if (rsp != null && rsp.Errcode != 0)
            {
                result.Code    = 0;
                result.Obj     = rsp;
                result.Message = rsp.Errmsg;
            }
            else
            {
                result.Code    = 0;
                result.Message = "获取钉钉客户ID有误";
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 通过手机号码找用户id
 /// </summary>
 /// <param name="phoneNum"></param>
 /// <param name="accessToken"></param>
 /// <returns></returns>
 public static string GetUserIdByPhone(string phoneNum, string accessToken)
 {
     try
     {
         IDingTalkClient            client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get_by_mobile");
         OapiUserGetByMobileRequest request = new OapiUserGetByMobileRequest();
         request.Mobile = phoneNum;
         request.SetHttpMethod("GET");
         OapiUserGetByMobileResponse response = client.Execute(request, accessToken);
         log.Info("GetUserIdByPhone: " + response.Body);
         return(response.Userid);
     }
     catch (Exception ex)
     {
         log.Info(ex);
         return("");
     }
 }