public static UploadMediaResult Upload(string filepath) { if (!System.IO.File.Exists(filepath)) { throw new System.IO.IOException(filepath + "文件不存在"); } System.IO.FileInfo file = new System.IO.FileInfo(filepath); var ext = System.IO.Path.GetExtension(filepath); switch (ext) { case ".amr": ext = "voice"; if (file.Length > 1024 * 1024) //1M { ext = "file"; } break; case ".jpg": ext = "image"; if (file.Length > 1024 * 1024 * 2) //2M { ext = "file"; } break; default: ext = "file"; break; } return(Post.PostFile <UploadMediaResult>(string.Format(URL_UPLOAD, Auth.GetToken(), ext), filepath)); }
public static void Get(Entities.Media media, string filepath) { if (System.IO.File.Exists(filepath)) { new System.IO.IOException(filepath + "已经存在。"); } System.IO.FileStream stream = new System.IO.FileStream(filepath, System.IO.FileMode.CreateNew); Utilitys.HttpUtility.Get.Download(string.Format(URL_GETMEDIA, Auth.GetToken(), media.media_id), stream); }
public static UserInfo[] list(long department_id) { var result = Get.GetJson <SimpleListResult>(string.Format(URL_LIST, Auth.GetToken(), department_id)); if (result.errcode == ReturnCode._请求成功) { return(result.userlist); } return(null); }
public static string create(UserInfo user) { var result = Post.PostJson <CreateUserResult>(string.Format(URL_CREATE, Auth.GetToken()), user); if (result != null) { return(result.userid); } return(string.Empty); }
/// <summary> /// 发送普通会话消息 /// 员工可以在微应用中把消息发送到同企业的人或群。 /// </summary> /// <param name="sender"></param> /// <param name="cid"></param> /// <param name="msg"></param> /// <returns></returns> public static SendMessageResult send_to_conversation(string sender, string cid, string agentid, DDMessage msg) { var token = Auth.GetToken(); msg.sender = sender; msg.cid = cid; msg.agentid = agentid; var rst = Post.PostJson <SendMessageResult>(string.Format(URL_send_to_conversation, token), msg); return(rst); }
public static List <Entities.Department> list() { var result = Get.GetJson <ListDepartmentResult>(string.Format(URL_LIST, Auth.GetToken())); if (result.errcode == ReturnCode._请求成功) { return(result.department); } return(null); }
/// <summary> /// 发送企业会话消息 /// 企业可以主动发消息给员工,消息量不受限制。 /// 发送企业会话消息和发送普通会话消息的不同之处在于发送消息的主体不同 - 普通会话消息发送主体是普通员工,体现在接收方手机上的联系人是消息发送员工 /// </summary> /// <param name="touser"></param> /// <param name="toparty"></param> /// <param name="agentid"></param> /// <returns></returns> public static SendMessageResult send(string touser, string toparty, string agentid, DDMessage msg) { var token = Auth.GetToken(); msg.touser = touser; msg.toparty = toparty; msg.agentid = agentid; var rst = Post.PostJson <SendMessageResult>(string.Format(URL_send, token), msg); return(rst); }
/// <summary> /// 指删除用户,最多一次删除20条 /// </summary> /// <param name="user"></param> /// <returns></returns> public static bool batchdelete(string[] user) { var result = Post.PostJson <JsonResult>(string.Format(URL_BATCHDELETE, Auth.GetToken()), new { useridlist = user.Take(20) }); return(result.errcode == ReturnCode._请求成功); }
public static bool update(UserInfo user) { var result = Post.PostJson <JsonResult>(string.Format(URL_UPDATE, Auth.GetToken()), user); return(result.errcode == ReturnCode._请求成功); }
public static bool delete(string userid) { var result = Get.GetJson <JsonResult>(string.Format(URL_DELETE, Auth.GetToken(), userid)); return(result.errcode == ReturnCode._请求成功); }
public static UserInfo get(string userid) { return(Get.GetJson <UserInfo>(string.Format(URL_GETUSERINFO_USERID, Auth.GetToken(), userid))); }
public static UserInfo getuserinfo(string code) { return(Get.GetJson <UserInfo>(string.Format(URL_GETUSERINFO_CODE, Auth.GetToken(), code))); }
public static bool update(Entities.Department dept) { var result = Post.PostJson <JsonResult>(string.Format(URL_UPDATE, Auth.GetToken()), dept); return(result.errcode == ReturnCode._请求成功); }
public static long create(string name, int parentid, string order = "", bool createDeptGroup = false) { var result = Post.PostJson <CreateDepartmentResult>(string.Format(URL_CREATE, Auth.GetToken()), new Entities.Department { name = name, parentid = parentid, order = order, createDeptGroup = createDeptGroup }); if (result.errcode == ReturnCode._请求成功) { return(result.id); } return(0); }
public static System.IO.MemoryStream Get(Entities.Media media) { System.IO.MemoryStream stream = new System.IO.MemoryStream(); Utilitys.HttpUtility.Get.Download(string.Format(URL_GETMEDIA, Auth.GetToken(), media.media_id), stream); return(stream); }