/// <summary> /// 获取钉钉token /// </summary> /// <returns></returns> public static string GetDingToken() { token = RedisHelper.Get("DingToken"); if (!string.IsNullOrWhiteSpace(token)) { return(token); } IDingTalkClient client = new DefaultDingTalkClient(dingUrl + "/gettoken"); OapiGettokenRequest req = new OapiGettokenRequest { Appkey = appkey, Appsecret = appsecret }; req.SetHttpMethod("GET"); OapiGettokenResponse rsp = client.Execute(req); if (rsp.Body != null) { token = rsp.AccessToken; RedisHelper.Set("DingToken", token, expireSeconds: 7200); return(token); } return(token); }
/// <summary> /// 获取 access_token /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { string access_token = string.Empty; if (rad_SDK.Checked) { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest req = new OapiGettokenRequest(); req.Appkey = txt_appkey.Text; req.Appsecret = txt_appsecret.Text; req.SetHttpMethod("GET"); OapiGettokenResponse rsp = client.Execute(req, access_token); var obj = JsonConvert.DeserializeObject <JObject>(rsp.Body); access_token = obj["access_token"].ToString(); } else { string url = string.Format("https://oapi.dingtalk.com/gettoken?appkey={0}&appsecret={1}", txt_appkey.Text, txt_appsecret.Text); var result = HttpHelper.Get(url, Encoding.UTF8); var obj = JsonConvert.DeserializeObject <JObject>(result); if (obj != null) { if (obj["errcode"].ToString().Trim() == "0") { access_token = obj["access_token"].ToString(); } else { access_token = obj["errmsg"].ToString(); } } } txt_access_token.Text = access_token; }
public static string GetAccessToken() { string value = CacheHelper.GetCache <string>(AccessTokenKey); if (!string.IsNullOrEmpty(value)) { return(value); } //测试 //"ding4uxjomils4jwiiap" //"7X-k8WA5D3cPdktnbkot_jPxW7FvstBZ4NITsJBI7EdT6c8BgUVBAyI3oAUWfqnV" //正式 //"dingnzjnupiizxh0tbys" //"_tnoyOl07vNpPtuEJJVfWulcTcO0mOky7MVFyLjeTmhsIpHyoDXlHqOufnZyK8Up" IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest { Appkey = "", // ConfigurationManager.AppSettings["DingTalkAppKey"], Appsecret = "" // ConfigurationManager.AppSettings["DingTalkAppSecret"] }; request.SetHttpMethod("Get"); OapiGettokenResponse response = client.Execute(request); value = response.AccessToken; CacheHelper.SetCache(AccessTokenKey, value, 7200); return(value); }
/// <summary> /// 企业开发内部应用通过appkey和appsecret获取access_token /// </summary> /// <param name="corpId"></param> /// <param name="corpSecret"></param> /// <returns></returns> public static string GetAccessToken2(string appkey, string appsecret) { /* * https://oapi.dingtalk.com/gettoken?appkey=id&appsecret=secret * "errcode": 0, * "errmsg": "ok", * "access_token": "fw8ef8we8f76e6f7s8df8s" */ try { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appkey; request.Appsecret = appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); if (response.Errcode == 0) { return(response.AccessToken); } } catch (Exception ex) { throw; } return(string.Empty); }
/// <summary> /// 企业内部通过本企业的CorpId和CorpSecret,来换取access_token /// </summary> /// <param name="corpId"></param> /// <param name="corpSecret"></param> /// <returns></returns> public static string GetAccessToken(string corpId, string corpSecret) { /* * https://oapi.dingtalk.com/gettoken?corpid={corpid}&corpsecret={corpSecret或开发授权码} * "errcode": 0, * "errmsg": "ok", * "access_token": "fw8ef8we8f76e6f7s8df8s" */ try { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Corpid = corpId; request.Corpsecret = corpSecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); if (response != null && response.Errcode == 0) { return(response.AccessToken); } else { throw new Exception(response.ErrMsg); } } catch (Exception ex) { throw; } return(string.Empty); }
public static void SetAccessToken(CacheItemRemovedReason reason) { //企业内部开发 var accessToken = HttpRuntime.Cache.Get("Dingtalk_AccessToken"); if (accessToken == null) { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = Allocation.Appkey; request.Appsecret = Allocation.Appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); HttpRuntime.Cache.Insert("Dingtalk_AccessToken", response.AccessToken, null, DateTime.Now.AddSeconds(3600), Cache.NoSlidingExpiration); } //定制服务商 //var accessToken = HttpRuntime.Cache.Get("Dingtalk_AccessToken"); //if (accessToken == null) //{ // DefaultDingTalkClient client = new DefaultDingTalkClient(Config.ServerUrl); // OapiServiceGetCorpTokenRequest req = new OapiServiceGetCorpTokenRequest(); // req.AuthCorpid = "ding0f2ae4da768e493235c2f4657eb6378f"; // OapiServiceGetCorpTokenResponse execute = client.Execute(req, "suitev6ajx5rbjrfqph0m", "y26DwWRab7il6nEe_oE9ib0xjwzPsG83KWyZBuS2ONVxTHZlk1spWyyec27m-Avw", Config.SuiteTicket); // Access_Token access_Token = JsonConvert.DeserializeObject<Access_Token>(execute.Body); // HttpRuntime.Cache.Insert("Dingtalk_AccessToken", access_Token.access_token, null, DateTime.Now.AddSeconds(3600), Cache.NoSlidingExpiration); //} }
/// <summary> /// 获取Access_Token /// </summary> /// <returns></returns> public static string Get_Access_Token() { try { var Appkey = ConfigurationManager.AppSettings["appKey"]; var Appsecret = ConfigurationManager.AppSettings["appSecret"]; log.Info(string.Format("通过Appkey:{0},Appsecret{1}获取Access_Token", Appkey, Appsecret)); DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = Appkey; request.Appsecret = Appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); if (response.Errcode == 0) { log.Info("AccessToken:" + response.AccessToken); return(response.AccessToken); } } catch (Exception ex) { return(ex.Message); } return("请求失败,请确认Appkey,Appsecret是否正确,或查看网络连接是否正常"); }
public string GetLogin(string code) { if (!string.IsNullOrEmpty(code)) { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = "dingjl4zohfnzjnpqudc"; request.Appsecret = "38H3T-CatuPEwnZOXq5ZhDIwqDFGye4vrxc36yLVZx7pfAumOmZBN0WSgbZB-A0-"; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); string token = response.AccessToken; client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getuserinfo"); OapiUserGetuserinfoRequest request1 = new OapiUserGetuserinfoRequest(); request1.Code = code; request1.SetHttpMethod("GET"); OapiUserGetuserinfoResponse response1 = client.Execute(request1, token); String userId = response1?.Userid ?? null; client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get"); OapiUserGetRequest request2 = new OapiUserGetRequest(); request2.Userid = userId; request2.SetHttpMethod("GET"); OapiUserGetResponse response2 = client.Execute(request2, token); string str = JsonConvert.SerializeObject(new { response2.Jobnumber, response2.ManagerUserId, response2.Name, response2.Roles, response2.Userid }); return(response2.Body); } else { return("0"); } }
public static string AccessToken() { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = "ding4pmpx3dj9azo1k7s"; request.Appsecret = "TYETGgC7XXsFB8hfwIg_hSB537kCJQX71O3wcrrqDYY1Gn6xwc3zBWJmfLlxp1Yc"; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); return(response.AccessToken); }
/// <summary> /// 获取企业凭证 /// <para> /// 获取调用企业接口凭证。可通过 appkey、appsecret 或 corpid、corpsecret 换取access_token /// </para> /// </summary> /// <param name="appkey">应用凭证AppKey</param> /// <param name="appsecret">应用凭证APPSecret</param> /// <returns></returns> public static string GetToken(string appkey, string appsecret) { IDingTalkClient client = new DefaultDingTalkClient(Settings.Default.GetTokenServerUrl); OapiGettokenRequest req = new OapiGettokenRequest(); req.Appkey = appkey; req.Appsecret = appsecret; req.SetHttpMethod("GET"); OapiGettokenResponse rsp = client.Execute(req); return(rsp.Body); }
/// <summary> /// 取得临时的Access Token /// </summary> /// <param name="app_id">client_id</param> /// <param name="app_key">client_secret</param> /// <param name="return_uri">redirect_uri</param> /// <param name="code">临时Authorization Code,官方提示2小时过期</param> /// <returns>Dictionary</returns> /// 返回说明: /// { /// "errcode": 0, /// "errmsg": "ok", /// "access_token": "fw8ef8we8f76e6f7s8df8s" /// } //public static Dictionary<string, object> get_access_token(string app_key, string app_secret, string getaccess_tokenurl) //{ // //参数 // IDictionary<string, string> parm = new Dictionary<string, string>(); // parm.Add("appkey", app_key); // parm.Add("appsecret", app_secret); // //调用官方C#的SDK方法进行请求 // WebUtils webhelper = new WebUtils(); // //发送并接受返回值 // string result = webhelper.DoGet(getaccess_tokenurl, parm); // if (!result.Contains("\"errcode\": 0,")) // { // return null; // } // try // { // Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result); // return dic; // } // catch // { // return null; // } //} /// <summary> /// 获取用户userid /// </summary> /// <param name="access_token">临时的Access Token</param> /// <param name="code">免登授权码</param> /// <returns>JsonData</returns> //public static Dictionary<string, object> get_info(string access_token, string code, string getuser_info) //{ // //参数 // IDictionary<string, string> parm = new Dictionary<string, string>(); // parm.Add("access_token", access_token); // parm.Add("code", code); // //调用官方C#的SDK方法进行请求 // WebUtils webhelper = new WebUtils(); // //发送并接受返回值 // string result = webhelper.DoGet(getuser_info, parm); // if (!result.Contains("\"errcode\": 0,")) // { // return null; // } // try // { // Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result); // return dic; // } // catch // { // return null; // } //} #endregion #region 钉钉接口方法 /// <summary> /// 取得临时的Access Token /// { /// "errcode": 0, /// "errmsg": "ok", /// "access_token": "fw8ef8we8f76e6f7s8df8s" /// } /// </summary> public static OapiGettokenResponse GetDingTalkAccessToken() { DefaultDingTalkClient client = new DefaultDingTalkClient(@"https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest req = new OapiGettokenRequest(); req.Appkey = appkey; req.Appsecret = appsecret; req.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(req); return(response); }
/// <summary> /// 根据企业尖,和密码返回 AccessToken /// </summary> /// <param name="CorpId"></param> /// <param name="CorpSecret"></param> /// <returns></returns> private string GetAccessToken(string CorpId, string CorpSecret) { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = CorpId; request.Appsecret = CorpSecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); return(response.AccessToken); }
/// <summary> /// 获取token /// </summary> /// <returns></returns> public static OapiGettokenResponse getToken() { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest req = new OapiGettokenRequest(); req.Appkey = AppKey; req.Appsecret = Appsecret; req.SetHttpMethod("GET"); OapiGettokenResponse rsp = client.Execute(req); return(rsp); }
public virtual string GetToken() { //Console.WriteLine($"Appkey:【{this.AppKey}】"); //Console.WriteLine($"AppSecret:【{ this.AppSecret}】"); IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = this.AppKey; request.Appsecret = this.AppSecret; request.SetHttpMethod("GET");//默认post请求,get请求需要主动指定 OapiGettokenResponse response = client.Execute(request); //Console.WriteLine(response.Body); return(response.AccessToken); }
public static void SetAccessToken(CacheItemRemovedReason reason) { //企业内部开发 var accessToken = HttpRuntime.Cache.Get("Dingtalk_AccessToken"); if (accessToken == null) { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appKey; request.Appsecret = appSecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); HttpRuntime.Cache.Insert("Dingtalk_AccessToken", response.AccessToken, null, DateTime.Now.AddSeconds(3600), Cache.NoSlidingExpiration); } }
/// <summary> /// 获取token /// </summary> /// <returns></returns> public static string GetAccessToken(string appKey, string appSecret) { try { var client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest tokenRequest = new OapiGettokenRequest(); tokenRequest.Corpid = appKey; tokenRequest.Corpsecret = appSecret; tokenRequest.SetHttpMethod("GET"); OapiGettokenResponse retString = client.Execute(tokenRequest); log.Info("GetAccessToken: " + retString.Body); return(retString.AccessToken); } catch (Exception ex) { log.Info(ex); return(""); } }
private string getDingAccessToken() { if (isInVaildTime()) { return(accessToken); } lastgetTokenTime = DateTime.Now; DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appkey; request.Appsecret = appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); accessToken = response.IsError ? string.Empty : response.AccessToken; return(accessToken); }
public static string GetToken() { try { DefaultDingTalkClient client = new DefaultDingTalkClient(URLConstant.URL_GET_TOKKEN); OapiGettokenRequest request = new OapiGettokenRequest { Appkey = Constants.APP_KEY, Appsecret = Constants.APP_SECRET }; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); string accessToken = response.AccessToken; return(accessToken); } catch (Exception e) { throw e; } }
public void GetToken() { DefaultDingTalkClient client = new DefaultDingTalkClient($"{m_host}/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appKey; request.Appsecret = appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); if (response.Errcode == 0) { access_token = response.AccessToken; //LogService.AppendDebugLog(typeof(DingTalkService), $"获得最新token:{access_token}"); } else { access_token = string.Empty; //LogService.AppendDebugLog(typeof(DingTalkService), response.ToString()); } get_token_time = DateTime.Now; }
private void SetAccessToken() { if (DateTime.Now >= access_token_expiredTime) { try { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appkey; request.Appsecret = appsecret; request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); access_Token = response.AccessToken; access_token_expiredTime = DateTime.Now.AddSeconds(response.ExpiresIn - 300); } catch { access_Token = string.Empty; access_token_expiredTime = DateTime.Now.AddSeconds(-1000); } } }
static void Main(string[] args) { //获取到AccessToken获取AccessToken需要Appkey和Appsecret,请求是GET DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken"); OapiGettokenRequest request = new OapiGettokenRequest(); request.Appkey = appKey; //Appkey request.Appsecret = appSecret; //Appsecret request.SetHttpMethod("GET"); OapiGettokenResponse response = client.Execute(request); //获取到AccessToken accessToken = response.AccessToken; // 创建员工 DefaultDingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/create"); OapiUserCreateRequest request1 = new OapiUserCreateRequest(); request1.Userid = "zhangsan"; request1.Mobile = "16657119236"; request1.Email = "*****@*****.**"; request1.Name = "张三"; List <long> departments1 = new List <long>(); departments1.Add(1L); request1.Department = JSON.ToJSON(departments1); OapiUserCreateResponse response1 = client1.Execute(request1, accessToken); Console.WriteLine("创建员工:"); Console.WriteLine(response1.Body); Console.WriteLine(); // 删除员工 DefaultDingTalkClient client2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/delete"); OapiUserDeleteRequest request2 = new OapiUserDeleteRequest(); request2.Userid = "zhangsan"; request2.SetHttpMethod("GET"); OapiUserDeleteResponse response2 = client2.Execute(request2, accessToken); Console.WriteLine("删除员工:"); Console.WriteLine(response2.Body); Console.WriteLine(); // 获取用户信息 DefaultDingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get"); OapiUserGetRequest request3 = new OapiUserGetRequest(); request3.Userid = userId; request3.SetHttpMethod("GET"); OapiUserGetResponse response3 = client3.Execute(request3, accessToken); Console.WriteLine("获取用户信息:"); Console.WriteLine(response3.Body); Console.WriteLine(); // 获取管理员信息 DefaultDingTalkClient client4 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get_admin"); OapiUserGetAdminRequest request4 = new OapiUserGetAdminRequest(); request4.SetHttpMethod("GET"); OapiUserGetAdminResponse response4 = client4.Execute(request4, accessToken); Console.WriteLine("获取管理员信息:"); Console.WriteLine(response4.Body); Console.WriteLine(); // 创建角色 DefaultDingTalkClient client5 = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role"); OapiRoleAddRoleRequest request5 = new OapiRoleAddRoleRequest(); request5.RoleName = "Test"; request5.GroupId = groupId; OapiRoleAddRoleResponse response5 = client5.Execute(request5, accessToken); Console.WriteLine("创建角色:"); Console.WriteLine(response5.Body); Console.WriteLine(); //更新角色,有bug,提示需要修改为GET,修改后依然报错称缺少CorId和APPkey,但是新版本小程序已经没有CorId了。 DefaultDingTalkClient client6 = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/update_role"); OapiRoleUpdateRoleRequest request6 = new OapiRoleUpdateRoleRequest(); request6.RoleName = "AnyThing"; request6.RoleId = 1; request6.SetHttpMethod("GET"); OapiRoleUpdateRoleResponse response6 = client.Execute(request6, accessToken); Console.WriteLine("更新角色"); Console.WriteLine(response6.Body); Console.WriteLine(); // 删除角色 DefaultDingTalkClient client7 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/deleterole"); OapiRoleDeleteroleRequest request7 = new OapiRoleDeleteroleRequest(); request7.RoleId = response5.RoleId; OapiRoleDeleteroleResponse response7 = client7.Execute(request7, accessToken); Console.WriteLine("删除角色:"); Console.WriteLine(response7.Body); Console.WriteLine(); // 添加外部联系人 官方代码有问题(已解决,需要在OpenExtContactDomain前加上request名 // 然而又有新问题:还是和上面“更新角色”的报错一样,提示:缺少参数 corpid or appkey DefaultDingTalkClient client8 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/extcontact/create"); OapiExtcontactCreateRequest request8 = new OapiExtcontactCreateRequest(); OapiExtcontactCreateRequest.OpenExtContactDomain contacter = new OapiExtcontactCreateRequest.OpenExtContactDomain { Title = "CFO", Name = "测试的外部联系人", StateCode = "86", CompanyName = "钉钉", Mobile = "15295778118" }; request8.Contact_ = contacter; OapiExtcontactCreateResponse response8 = client8.Execute(request8, accessToken); Console.WriteLine("添加外部联系人:"); Console.WriteLine(response6.Body); Console.WriteLine(); // 获取外部联系人列表 DefaultDingTalkClient client9 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/extcontact/list"); OapiExtcontactListRequest request9 = new OapiExtcontactListRequest(); request9.Size = 20L; request9.Offset = 0L; OapiExtcontactListResponse response9 = client9.Execute(request9, accessToken); Console.WriteLine("获取外部联系人列表:"); Console.WriteLine(response9.Body); Console.WriteLine(); // 创建群会话 //DefaultDingTalkClient client10 = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/create"); //OapiChatCreateRequest request10 = new OapiChatCreateRequest(); //request10.Name = "TestCreate"; //request10.Owner = userId; //request10.Useridlist ??= new List<string>(); //request10.Useridlist.Add(userId); //OapiChatCreateResponse response10 = client10.Execute(request10, accessToken); //Console.WriteLine("创建群会话"); //Console.WriteLine(response10.Body); //Console.WriteLine(); //// 获取群会话 //DefaultDingTalkClient client11 = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/get"); //OapiChatGetRequest request11 = new OapiChatGetRequest(); //request11.Chatid = response10.Chatid; //request11.SetHttpMethod("GET"); //OapiChatGetResponse response11 = client11.Execute(request11, accessToken); //Console.WriteLine("获取群会话"); //Console.WriteLine(response11.Body); //Console.WriteLine(); //// 更新群对话 //DefaultDingTalkClient client12 = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/update"); //OapiChatUpdateRequest request12 = new OapiChatUpdateRequest(); //request12.Chatid = response10.Chatid; //request12.Name = "TestUpdate"; //OapiChatUpdateResponse response12 = client12.Execute(request12, accessToken); //Console.WriteLine("更新群对话"); //Console.WriteLine(response12.Body); //Console.WriteLine(); // 发送工作通知 DefaultDingTalkClient client13 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); OapiMessageCorpconversationAsyncsendV2Request request13 = new OapiMessageCorpconversationAsyncsendV2Request(); request13.AgentId = agentId; request13.ToAllUser = true; OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msgDomain = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain(); msgDomain.Msgtype = "oa"; msgDomain.Oa = new OapiMessageCorpconversationAsyncsendV2Request.OADomain(); msgDomain.Oa.MessageUrl = "http://dingtalk.com"; msgDomain.Oa.Head = new OapiMessageCorpconversationAsyncsendV2Request.HeadDomain(); msgDomain.Oa.Head.Bgcolor = "FFBBBBBB"; msgDomain.Oa.Head.Text = "头部标题"; msgDomain.Oa.Body = new OapiMessageCorpconversationAsyncsendV2Request.BodyDomain(); msgDomain.Oa.Body.Title = "正文标题"; msgDomain.Oa.Body.Form = new List <OapiMessageCorpconversationAsyncsendV2Request.FormDomain>(); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "姓名", Value = "张三" }); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "年龄", Value = "20" }); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "身高", Value = "1.8米" }); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "体重", Value = "130斤" }); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "学历", Value = "本科" }); msgDomain.Oa.Body.Form.Add(new OapiMessageCorpconversationAsyncsendV2Request.FormDomain() { Key = "爱好", Value = "打球、听音乐" }); msgDomain.Oa.Body.Rich = new OapiMessageCorpconversationAsyncsendV2Request.RichDomain(); msgDomain.Oa.Body.Rich.Num = "15.6"; msgDomain.Oa.Body.Rich.Unit = "元"; msgDomain.Oa.Body.Content = "大段文本大段文本大段文本大段文本大段文本"; msgDomain.Oa.Body.Image = "@lADOADmaWMzazQKA"; msgDomain.Oa.Body.FileCount = "3"; msgDomain.Oa.Body.Author = "李四"; request13.Msg_ = msgDomain; //request13.Msg = @"{ // ""msgtype"": ""oa"", // ""oa"": { // ""message_url"": ""http://dingtalk.com"", // ""head"": { // ""bgcolor"": ""FFBBBBBB"", // ""text"": ""头部标题"" // }, // ""body"": { // ""title"": ""正文标题"", // ""form"": [ // {""key"": ""姓名:"", ""value"": ""张三""}, // {""key"": ""年龄:"", ""value"": ""20""}, // {""key"": ""身高:"", ""value"": ""1.8米""}, // {""key"": ""体重:"", ""value"": ""130斤""}, // {""key"": ""学历:"", ""value"": ""本科""}, // {""key"": ""爱好:"", ""value"": ""打球、听音乐""} // ], // ""rich"": {""num"": ""15.6"", ""unit"": ""元""}, // ""content"": ""大段文本大段文本大段文本大段文本大段文本大段文本"", // ""image"": ""@lADOADmaWMzazQKA"", // ""file_count"": ""3"", // ""author"": ""李四"" // } // } //}"; OapiMessageCorpconversationAsyncsendV2Response response13 = client13.Execute(request13, accessToken); Console.WriteLine("发送工作通知:"); Console.WriteLine(response13.Body); Console.WriteLine(); //获取工作通知消息的发送进度 DefaultDingTalkClient client14 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendprogress"); OapiMessageCorpconversationGetsendprogressRequest request14 = new OapiMessageCorpconversationGetsendprogressRequest(); request14.AgentId = agentId; request14.TaskId = response13.TaskId; OapiMessageCorpconversationGetsendprogressResponse response14 = client14.Execute(request14, accessToken); Console.WriteLine("获取工作通知消息的发送进度"); Console.WriteLine(response14.Body); Console.WriteLine(); //获取工作通知消息的发送结果 DefaultDingTalkClient client15 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult"); OapiMessageCorpconversationGetsendresultRequest request15 = new OapiMessageCorpconversationGetsendresultRequest(); request15.AgentId = agentId; request15.TaskId = response13.TaskId; OapiMessageCorpconversationGetsendresultResponse response15 = client15.Execute(request15, accessToken); Console.WriteLine("获取工作通知消息的发送结果"); Console.WriteLine(response15.Body); Console.WriteLine(); ////发送消息到企业群(使用时需将client10注释恢复) //DefaultDingTalkClient client16 = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/send"); //OapiChatSendRequest request16 = new OapiChatSendRequest(); //request16.Chatid = response10.Chatid; //request16.Msg = @"{ // ""msgtype"":""text"", // ""text"": { // ""content"": ""测试发送消息到企业群: 还在coding吗兄弟?"", // } //}"; //OapiChatSendResponse response16 = client16.Execute(request16, accessToken); //Console.WriteLine("发送消息到企业群"); //Console.WriteLine(response16.Body); //Console.WriteLine(); //发起代办 IDingTalkClient client17 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/workrecord/add"); OapiWorkrecordAddRequest request17 = new OapiWorkrecordAddRequest(); request17.Userid = userId; request17.CreateTime = 1496678400000L; request17.Title = "title"; request17.Url = "https://oa.dingtalk.com"; List <OapiWorkrecordAddRequest.FormItemVoDomain> formItemList = new List <OapiWorkrecordAddRequest.FormItemVoDomain>(); OapiWorkrecordAddRequest.FormItemVoDomain formItem = new OapiWorkrecordAddRequest.FormItemVoDomain(); formItemList.Add(formItem); formItem.Title = "标题"; formItem.Content = "内容 "; request17.FormItemList_ = formItemList; request17.BizId = "TestRecord"; OapiWorkrecordAddResponse response17 = client17.Execute(request17, accessToken); Console.WriteLine("发起代办"); Console.WriteLine(response17.Body); Console.WriteLine(); //更新代办 IDingTalkClient client18 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/workrecord/update"); OapiWorkrecordUpdateRequest request18 = new OapiWorkrecordUpdateRequest(); request18.Userid = userId; request18.RecordId = "TestRecord"; request18.SetHttpMethod("GET"); OapiWorkrecordUpdateResponse response18 = client.Execute(request18, accessToken); Console.WriteLine("更新代办"); Console.WriteLine(response18.Body); Console.WriteLine(); ////根据部门获取到Urid //DefaultDingTalkClient clie = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getDeptMember"); //OapiUserGetDeptMemberRequest req = new OapiUserGetDeptMemberRequest(); //req.DeptId = "1"; //req.SetHttpMethod("GET"); //OapiUserGetDeptMemberResponse rsp = clie.Execute(req, AccessToken); //List<string> userid = rsp.UserIds; ////获取到Urid就是在公司里要发送到那个人的id //string Urid = userid[0]; ////发送消息 //IDingTalkClient cl = new DefaultDingTalkClient("https://eco.taobao.com/router/rest"); //CorpMessageCorpconversationAsyncsendRequest req1 = new CorpMessageCorpconversationAsyncsendRequest(); //req1.Msgtype = "oa";//发送消息是以oa的形式发送的,其他的还有text,image等形式 //req1.AgentId = 917416506;//微应用ID //req1.UseridList = Urid;//收信息的userId,这个是by公司来区分,在该公司内这是一个唯一标识符 //req1.ToAllUser = false;//是否发给所有人 // //消息文本 ////req1.Msgcontent = "{\"message_url\": \"http://dingtalk.com\",\"head\": {\"bgcolor\": \"FFBBBBBB\",\"text\": \"头部标题\"},\"body\": {\"title\": \"拿钱学习\",\"form\": [{\"key\": \"姓名:\", \"value\": \"hong\" },{\"key\": \"年龄:\", \"value\": \"18\" },{\"key\": \"身高:\", \"value\": \"1.6米\"},{\"key\": \"体重:\",\"value\": \"90斤\"},{\"key\": \"学历:\",\"value\": \"硕士\"},{\"key\": \"爱好:\",\"value\": \"学习\"}],\"rich\": {\"num\": \"10000\",\"unit\": \"元\"},\"content\": \"快去学习!!!\",\"file_count\": \"1\",\"author\": \"小白\"}}"; ////CorpMessageCorpconversationAsyncsendResponse rsp1 = cl.Execute(req1, AccessToken);//发送消息 //req1.Msgcontent = @"{ // ""message_url"": ""http://dingtalk.com"", // ""head"": {""bgcolor"": ""FFBBBBBB"",""text"": ""头部标题""}, // ""body"": { // ""title"": ""拿钱学习"", // ""form"": [ // {""key"": ""姓名:"", ""value"": ""hong"" }, // {""key"": ""年龄:"", ""value"": ""18"" }, // {""key"": ""身高:"", ""value"": ""1.6米""}, // {""key"": ""体重:"", ""value"": ""90斤""}, // {""key"": ""学历:"", ""value"": ""硕士""}, // {""key"": ""爱好:"", ""value"": ""学习""}], // ""rich"": {""num"": ""10000"",""unit"": ""元""}, // ""content"": ""快去学习!!!"", // ""file_count"": ""1"", // ""author"": ""小白"" // } //}"; //CorpMessageCorpconversationAsyncsendResponse rsp1 = cl.Execute(req1, AccessToken);//发送消息 //Console.WriteLine(rsp1.Body); Console.ReadLine(); }