Exemple #1
0
class GetBatchJobLog:
    def __init__(self, access_token, begin_date, end_date):
        """
        查询批量任务
        :param access_token: 调用接口凭证 (必须)
        :param begin_date: 开始日期。格式为2016-10-01 (必须)
        :param end_date: 结束日期。格式为2016-10-07 (必须)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._begin_date = begin_date
        self._end_date = end_date

        # URL
        self._api_url = API_URL.format(self._access_token)

    def check(self):
        """
        查询批量任务
        :return:
        """
        data = {
            "begin_date": self._begin_date,
            "end_date": self._end_date,
        }
        res = self._request.request(method="POST",
                                    url=self._api_url,
                                    json=data)
        return res.json()
Exemple #2
0
class GetUserLoginLog:
    def __init__(self, access_token, userid, begin_date, end_date):
        """
        查询成员登录 https://exmail.qq.com/qy_mng_logic/doc#10029%20
        :param access_token: 调用接口凭证 (必须)
        :param userid: 筛选条件:指定成员帐号 (必须)
        :param begin_date: 开始日期。格式为2016-10-01 (必须)
        :param end_date: 结束日期。格式为2016-10-07 (必须)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._userid = userid
        self._begin_date = begin_date
        self._end_date = end_date

        # URL
        self._api_url = API_URL.format(self._access_token)

    def check(self):
        """
        查询成员登录
        :return:
        """
        data = {
            "userid": self._userid,
            "begin_date": self._begin_date,
            "end_date": self._end_date,
        }
        res = self._request.request(method="POST",
                                    url=self._api_url,
                                    json=data)
        return res.json()
Exemple #3
0
class GetUnreadMail:
    """
    主动模式
    """
    def __init__(self, access_token, userid):
        """
        获取邮件未读数 https://exmail.qq.com/qy_mng_logic/doc#10033%20 (官方文档有毛病...怀疑是实习生写的)
        :param access_token: 调用接口凭证 (必须)
        :param userid: 成员UserID (必须)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._userid = userid

        # URL
        self._api_url = API_URL.format(self._access_token, self._userid)

    def get_unread_mails(self):
        """
        获取邮件未读数
        :return:
        """
        res = self._request.request(method="GET", url=self._api_url)
        return res.json()
Exemple #4
0
class GetMailInfo:
    def __init__(self,
                 access_token,
                 begin_date,
                 end_date,
                 mail_type=0,
                 userid='',
                 subject=''):
        """
        查询邮件 https://exmail.qq.com/qy_mng_logic/doc#10028%20
        :param access_token: 调用接口凭证 (必须)
        :param begin_date: 开始日期。格式为2016-10-01 (必须)
        :param end_date: 结束日期。格式为2016-10-07 (必须)
        :param mail_type: 邮件类型。0:收信+发信 1:发信 2:收信 (必须) --- 默认为0
        :param userid: 筛选条件:指定成员帐号
        :param subject: 筛选条件:包含指定主题内容
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._begin_date = begin_date
        self._end_date = end_date
        self._mail_type = mail_type
        self._userid = userid
        self._subject = subject

        # URL
        self._api_url = API_URL.format(self._access_token)

    def check(self):
        """
        查询邮件概况
        :return:
        """
        data = {
            "begin_date": self._begin_date,
            "end_date": self._end_date,
            "mailtype": self._mail_type,
            "userid": self._userid,
            "subject": self._subject
        }
        res = self._request.request(method="POST",
                                    url=self._api_url,
                                    json=data)
        return res.json()
Exemple #5
0
class GetOperationLog:
    def __init__(self, access_token, begin_date, end_date, operate_type=1):
        """
        查询操作记录
        :param access_token: 调用接口凭证
        :param operate_type: 类型
                                1:all
                                2:开放协议同步
                                3:编辑管理员帐号
                                4:设置分级管理员
                                5:编辑企业信息
                                6:收信黑名单设置
                                7:邮件转移设置
                                8:成员与群组管理
                                9:邮件备份管理
                                10:成员权限控制
        :param begin_date: 开始日期。格式为2016-10-01
        :param end_date: 结束日期。格式为2016-10-07
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._operation_type = operate_type
        self._begin_date = begin_date
        self._end_date = end_date

        # URL
        self._api_url = API_URL.format(self._access_token)

    def check(self):
        """
        查询操作记录
        :return:
        """
        data = {
            "type": self._operation_type,
            "begin_date": self._begin_date,
            "end_date": self._end_date,
        }
        res = self._request.request(method="POST",
                                    url=self._api_url,
                                    json=data)
        return res.json()
Exemple #6
0
class ExMailInfo:
    def __init__(self, access_token, domain: str, begin_date, end_date):
        """
        查询邮件概况 https://exmail.qq.com/qy_mng_logic/doc#10027%20
        查询开始和结束时间有限制(3个月)
        :param access_token: 调用接口凭证(必须)
        :param domain: 域名(必须)
        :param begin_date: 开始日期。格式为2016-10-01(必须)
        :param end_date: 结束日期。格式为2016-10-07(必须)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._domain = domain
        self._begin_date = begin_date
        self._end_date = end_date

        # URL
        self._api_url = API_URL.format(self._access_token)

    def check(self):
        """
        查询邮件概况
        :return:
        """
        data = {
            "domain": self._domain,
            "begin_date": self._begin_date,
            "end_date": self._end_date
        }
        res = self._request.request(method="POST",
                                    url=self._api_url,
                                    json=data)
        return res.json()
Exemple #7
0
class GetAccessToken:
    def __init__(self, corpid, corpsecret=None):
        """
        获取AccessToken
        :param corpid: 这个id是唯一的
        :param corpsecret: 这个secret是可以在管理后台刷新变更的
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._corpid = corpid
        self._corpsecret = corpsecret

        # Token
        self._access_token = ""

        # 构造访问链接
        if corpsecret is None:
            self._access_token = ""
        self._api_url = API_URL.format(corpid, corpsecret)

    def get_access_token(self):
        """
        获取AccessToken
        :return:
        """
        res = self._request.request(method="GET", url=self._api_url)
        # 返回码
        res_json = res.json()
        if res_json['errcode'] == 0:
            res_json.pop('errmsg')
            res_json.pop('errcode')
            return res_json
        else:
            return res.json()
Exemple #8
0
class LoginTencentExmail:
    def __init__(self, access_token, userid):
        """
        单点登陆 https://exmail.qq.com/qy_mng_logic/doc#10036%20
        :param access_token: 调用接口凭证 (必须)
        :param userid: 成员UserID (必须)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._userid = userid

        # URL
        self._api_url = API_URL.format(self._access_token, self._userid)

    def login(self):
        """
        登陆
        :return:
        """
        res = self._request.request(method="GET", url=self._api_url)
        return res.json()
Exemple #9
0
class Department:
    def __init__(self,
                 access_token,
                 operation,
                 depart_id='',
                 depart_name='',
                 depart_parent_id='',
                 depart_order=0,
                 depart_fuzzy=0):
        """
        部门对象
        :param access_token: AccessToken调用接口凭证 (必须)
        :param operation: 操作变量(["create", "update", "delete", "list", "search"], 对应增、更、删、列、查)
        :param depart_id: 部门id (必须) (更新, 删除(注:不能删除根部门;不能删除含有子部门、成员的部门), 获取列表)
        :param depart_name: 部门名称。长度限制为1~64个字节,字符不能包括\:*?"<>| (必须) (创建, 更新, 查找)
                            注: 更新时则为需要更新的名称
        :param depart_parent_id: 父部门id。id为1可表示根部门 (必须) (创建, 更新)
        :param depart_order: 在父部门中的次序值。order值小的排序靠前,1-10000为保留值,若使用保留值,将被强制重置为0。 (非必须) (创建, 更新)
        :param depart_fuzzy: 1/0:是否模糊匹配 (非必需) (查找)
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._depart_id = depart_id
        self._depart_name = depart_name
        self._depart_parent_id = depart_parent_id
        self._depart_order = depart_order
        self._depart_fuzzy = depart_fuzzy

        # URL
        operation_list = ["create", "update", "delete", "list", "search"]
        if operation in operation_list:
            self._api_url = API_URL.format(operation, self._access_token)
        else:
            raise ValueError("Operation is error!")

    def create_depart(self):
        """
        创建部门
        :return:
        """
        # 封装参数
        if "create" in self._api_url:
            data = {
                'name': self._depart_name,
                'parentid': self._depart_parent_id,
                'order': self._depart_order
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def update_depart(self):
        """
        更新部门
        :return:
        """
        # 封装参数
        if "update" in self._api_url:
            data = {
                "id": self._depart_id,
                "name": self._depart_name,
                "parentid": self._depart_parent_id,
                "order": self._depart_order
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def delete_depart(self):
        """
        删除部门
        :return:
        """
        if "delete" in self._api_url:
            self._api_url = self._api_url + "&id=" + str(self._depart_id)
            res = self._request.request(method="GET", url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def list_departs(self):
        """
        获取部门列表
        :return:
        """
        if "list" in self._api_url:
            self._api_url = self._api_url + "&id=" + self._depart_id
            res = self._request.request(method="GET", url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def search_departs(self):
        """
        查找部门
        :return:
        """
        if "search" in self._api_url:
            data = {"name": self._depart_name, "fuzzy": self._depart_fuzzy}
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}
Exemple #10
0
class User:
    def __init__(self,
                 access_token,
                 operation,
                 userid='',
                 name='',
                 department='',
                 position='',
                 mobile='',
                 tel='',
                 extid='',
                 gender='',
                 slaves='',
                 enable=1,
                 password='',
                 cpwd_login='',
                 department_id='',
                 fetch_child=0,
                 userlist=''):
        """
        通讯录用户管理
        :param access_token: 调用接口凭证 (必须)
        :param operation: 操作 (必须) [创建、更新、删除、获取用户、获取部门用户、获取部门用户详情、批量检查账号]
        :param userid: 成员UserID。企业邮帐号名,邮箱格式 (创建(必须) , 更新(必须))
        :param name: 成员名称。长度为1~64个字节 (创建(必须) , 更新)
        :param department: 成员所属部门id列表,不超过20个 (创建(必须) , 更新)
        :param position: 职位信息。长度为0~64个字节 (创建, 更新)
        :param mobile: 手机号码 (创建, 更新)
        :param tel: 座机号码 (创建, 更新)
        :param extid: 编号 (创建, 更新)
        :param gender: 性别。1表示男性,2表示女性 (创建, 更新)
        :param slaves: 别名列表 1.Slaves 上限为5个 2.Slaves 为邮箱格式 (创建, 更新)
        :param enable: 启用/禁用成员。1表示启用成员,0表示禁用成员 (更新) --- 默认设置为1
        :param password: 密码 (创建(必须) , 更新)
        :param cpwd_login: 用户重新登录时是否重设密码, 登陆重设密码后,该标志位还原。0表示否,1表示是,缺省为0 (创建, 更新)
        :param department_id: 获取的部门id。id为1时可获取根部门下的成员 (获取(必须))
        :param fetch_child: 1/0:是否递归获取子部门下面的成员 (获取) --- 默认设置为0
        :param userlist: 成员帐号,每次检查不得超过20个
        """
        # 请求对象
        self._request = BaseHttpRequest()

        self._access_token = access_token
        self._operation = operation
        self._userid = userid
        self._name = name
        self._department = department
        self._position = position
        self._mobile = mobile
        self._tel = tel
        self._extid = extid
        self._gender = gender
        self._slaves = slaves
        self._enable = enable
        self._password = password
        self._cpwd_login = cpwd_login
        self._department_id = department_id
        self._fetch_child = fetch_child
        self._userlist = userlist

        if self._department != "" and not isinstance(self._department, list):
            raise TypeError("Department type is err!")

        if self._slaves != "" and not isinstance(self._slaves, list):
            raise TypeError("Slaves type is err!")

        if self._userlist != "" and not isinstance(self._userlist, list):
            raise TypeError("Userlist type is err!")

        # URL
        operation_list = ["create", "update", "delete", "get", "simplelist", "list", "batchcheck"]
        if operation in operation_list:
            self._api_url = API_URL.format(operation, self._access_token)
        else:
            raise ValueError("Operation is error!")

    def create_user(self):
        """
        创建成员
        :return:
        """
        if "create" in self._api_url:
            data = {
                "userid": self._userid,
                "name": self._name,
                "department": self._department,
                "position": self._position,
                "mobile": self._mobile,
                "tel": self._tel,
                "extid": self._extid,
                "gender": self._gender,
                "slaves": self._slaves,
                "password": self._password,
                "cpwd_login": self._cpwd_login
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def update_user(self):
        """
        更新成员
        :return:
        """
        if "update" in self._api_url:
            data = {
                "userid": self._userid,
                "name": self._name,
                "department": self._department,
                "position": self._position,
                "mobile": self._mobile,
                "tel": self._tel,
                "extid": self._extid,
                "gender": self._gender,
                "slaves": self._slaves,
                "enable": self._enable,
                "password": self._password,
                "cpwd_login": self._cpwd_login
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def delete_user(self):
        """
        删除用户
        :return:
        """
        if "delete" in self._api_url:
            self._api_url = self._api_url + "&userid=" + self._userid
            res = self._request.request(method="GET",
                                        url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def get_user(self):
        """
        获取用户
        :return:
        """
        if "get" in self._api_url:
            self._api_url = self._api_url + "&userid=" + self._userid
            res = self._request.request(method="GET",
                                        url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def get_department_user(self):
        """
        获取部门用户
        :return:
        """
        if "simplelist" in self._api_url:
            self._api_url = self._api_url + "&department_id=" + self._department_id\
                            + "&fetch_child=" + str(self._fetch_child)
            res = self._request.request(method="GET",
                                        url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def get_department_user_detail(self):
        """
        获取部门用户(详情)
        :return:
        """
        if "list" in self._api_url:
            self._api_url = self._api_url + \
                            "&department_id=" + self._department_id + \
                            "&fetch_child=" + str(self._fetch_child)
            res = self._request.request(method="GET",
                                        url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def batch_check_account(self):
        """
        批量检查账号
        :return:
        """
        if "batchcheck" in self._api_url:
            data = {"userlist": self._userlist}
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}
Exemple #11
0
class Group:
    def __init__(self,
                 access_token,
                 operation: str,
                 groupid: str,
                 groupname='',
                 userlist='',
                 grouplist='',
                 department='',
                 allow_type=0,
                 allow_userlist=''):
        """
        邮件群组
        :param access_token: 调用接口凭证(必须)
        :param operation: 操作[创建、更新、删除、查询] (必须)
        :param groupid: 邮件群组名称 (创建(必须), 更新(必须))
        :param groupname: 邮件群组名称 (创建(必须), 更新)
        :param userlist: 成员帐号,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
        :param grouplist: 成员邮件群组,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
        :param department: 成员部门,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
        :param allow_type: 群发权限。0: 企业成员, 1任何人, 2:组内成员,3:指定成员 (创建(必须), 更新) --- 默认为0
        :param allow_userlist: 群发权限为指定成员时,需要指定成员
        """
        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._operation = operation
        self._groupid = groupid
        self._groupname = groupname
        self._userlist = userlist
        self._grouplist = grouplist
        self._department = department
        self._allow_type = allow_type
        self._allow_userlist = allow_userlist

        if self._userlist != "" and not isinstance(self._userlist, list):
            raise TypeError("Userlist type is err!")

        if self._grouplist != "" and not isinstance(self._grouplist, list):
            raise TypeError("Grouplist type is err!")

        if self._allow_userlist != "" and not isinstance(
                self._allow_userlist, list):
            raise TypeError("Allow_userlist type is err!")

        # URL
        operation_list = ["create", "update", "delete", "get"]
        if operation in operation_list:
            self._api_url = API_URL.format(operation, self._access_token)
        else:
            raise ValueError("Operation is error!")

    def create_mail_group(self):
        """
        创建邮件群组
        :return:
        """
        if "create" in self._api_url:
            data = {
                "groupid": self._groupid,
                "groupname": self._groupname,
                "userlist": self._userlist,
                "department": self._department,
                "allow_type": self._allow_type,
                "allow_userlist": self._allow_userlist
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def update_mail_group(self):
        """
        更新邮件群组
        :return:
        """
        if "update" in self._api_url:
            data = {
                "groupid": self._groupid,
                "groupname": self._groupname,
                "userlist": self._userlist,
                "department": self._department,
                "allow_type": self._allow_type,
                "allow_userlist": self._allow_userlist
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def delete_mail_group(self):
        """
        删除邮件群组
        :return:
        """
        if "delete" in self._api_url:
            self._api_url = self._api_url + "&groupid=" + self._groupid
            res = self._request.request(method="GET", url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def get_mail_group_info(self):
        """
        获取邮件群组信息
        :return:
        """
        if "get" in self._api_url:
            self._api_url = self._api_url + "&groupid=" + self._groupid
            res = self._request.request(method="GET", url=self._api_url)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}
Exemple #12
0
class Function:
    def __init__(self,
                 access_token: str,
                 operation: str,
                 userid: str,
                 function_type='',
                 option=''):
        """
        邮件功能设置
        :param access_token: 调用接口凭证 (必须)
        :param operation: 操作[获取、更改] (必须)
        :param userid: 成员UserID。企业邮帐号名,邮箱格式 (必须)
        :param function_type: 功能设置属性类型
                              1: 强制启用安全登录
                              2: IMAP/SMTP服务
                              3: POP/SMTP服务
                              4: 是否启用安全登录
                              (必须)
        :param option: 功能设置属性
                       type:属性类型。value:属性值(字符型)
                       示例: [{"type":1,"value":"0"},{"type":2,"value":"1"},{"type":3,"value":"0"}]}
                       1: 强制启用安全登录
                       2: IMAP/SMTP服务
                       3: POP/SMTP服务
                       4: 是否启用安全登录,不可用
                       (必须)
        """

        # 请求对象
        self._request = BaseHttpRequest()

        # 参数
        self._access_token = access_token
        self._operation = operation
        self._userid = userid
        self._function_type = function_type
        self._option = option

        if self._function_type != "" and not isinstance(self._function_type, list):
            raise TypeError("Function_type type is err!")

        if self._option != "" and not isinstance(self._option, list):
            raise TypeError("Option type is err!")

        # URL
        operation_list = ["get", "update"]
        if operation in operation_list:
            self._api_url = API_URL.format(operation, self._access_token)
        else:
            raise ValueError("Operation is error!")

    def get_function_attribute(self):
        """
        获取功能属性
        :return:
        """
        if "get" in self._api_url:
            data = {
                "userid": self._userid,
                "type": self._function_type
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}

    def update_function_attribute(self):
        """
        更改功能属性
        :return:
        """
        if "update" in self._api_url:
            data = {
                "userid": self._userid,
                "option": self._option
            }
            res = self._request.request(method="POST",
                                        url=self._api_url,
                                        json=data)
            return res.json()
        else:
            return {'errmsg': 'Invalid input', 'errcode': -1}