Beispiel #1
0
 def get_message(self,
                 project_id: str,
                 mobile: str,
                 release: "str" = None) -> str:
     """获取短信息
     :param project_id: 项目编号
     :param mobile:电话号码
     :param release: 是否释放该号码
     :return:
     """
     num = 12
     while num >= 0:
         if not release:
             response = get_response(
                 get_message_url.format(mobile=mobile,
                                        projectid=project_id,
                                        token=self.token))
         else:
             response = get_response(
                 get_message_url.format(mobile=mobile,
                                        projectid=project_id,
                                        token=self.token) + "&release=1")
         result = response.split("|")
         if result[0] == "success":
             print("验证码为:{}".format(result[1]))
             return result[1]
         time.sleep(5)
         print("还在获取短信验证码倒数第{}次".format(num))
         num -= 1
     else:
         print("获取信息超时")
         raise GetMsnTimeOut
Beispiel #2
0
 def get_send_sms_state(self, mobile: str, project_id: str) -> bool:
     """获取发送消息的状态
     :param mobile: 电话号码
     :param project_id: 项目编号
     :return:
     """
     num = 12
     while True:
         response = get_response(
             send_message_status_url.format(mobile=mobile,
                                            projectid=project_id,
                                            token=self.token))
         if response == "success":
             print("状态确认成功")
             return True
         elif response == "fail":
             print("短信发送不成功")
             return False
         elif error_code.get(response):
             raise error_code.get(response)
         else:
             num -= 1
             time.sleep(5)
     else:
         return False
Beispiel #3
0
 def releaseall(self) -> bool:
     """释放所有号码
     :return:
     """
     response = get_response(freed_mobile_all_url.format(token=self.token))
     if response == "success":
         print("释放成功")
         return True
     raise error_code.get(response)
Beispiel #4
0
 def __init__(self, username: str, password: str):
     """登录获取token
     :param username: 用户名
     :param password: 密码
     """
     response = get_response(
         login_url.format(user=username, password=password))
     result = response.split('|')
     if result[0] == "success":
         self.token = result[1]
Beispiel #5
0
 def check_account(self) -> bool:
     """检查用户是否可用
     :return: true or false
     """
     response = get_response(get_account_info_url.format(token=self.token))
     result = response.split("|")
     if result[0] == "success":
         info = json.loads(result[1])
         if info.get("Status") == 1:
             print("账户正常:{}".format(result))
             return True
         raise error_code.get(response)
Beispiel #6
0
 def add_ignore(self, mobile: str, project_id: str) -> bool:
     """拉黑电话号码
     :param mobile:手机号
     :param project_id: 项目编号
     :return:
     """
     response = get_response(
         add_ignore_url.format(mobile=mobile,
                               projectid=project_id,
                               token=self.token))
     if response == "success":
         print("拉黑成功")
         return True
     print("{}拉黑失败".format(mobile))
     raise error_code.get(response)
Beispiel #7
0
 def get_mobile(self, project_id: str, **kwargs: dict) -> str:
     """获取手机号
     :param project_id: 项目id
     :param kwargs: 额外参数
     :return:
     """
     response = get_response(
         get_mobile_url.format(projectid=project_id, token=self.token))
     result = response.split("|")
     if result[0] == "success":
         return result[1]
     elif response == "2004":  # 防止暂时没有可用号码
         print(error_code.get(response))
         self.get_mobile(project_id, **kwargs)
     else:
         raise MobileError
Beispiel #8
0
 def send_sms(self, mobile: str, project_id: str, sms: str) -> bool:
     """发送信息
     :param mobile: 电话号码
     :param project_id:项目编号
     :param sms:发送消息内容
     :return:
     """
     sms = quote(sms)
     response = get_response(
         send_sms_url.format(mobile=mobile,
                             projectid=project_id,
                             message=sms,
                             token=self.token))
     if response == "success":
         print("消息发送成功;开始确认状态")
         return self.get_send_sms_state(mobile, project_id)
     raise error_code.get(response)