移动onelink自动化脚本,机卡分离解绑,区域限制变更

通过自动化脚本,可以实现一系列自动化操作,包括机卡分离复机、解绑、绑定首话单和绑定TAC等功能。此外,还可以进行区域限制变更,绑定新区域或首话单。这些功能可以无缝通过API方式集成到自己的平台中,并支持多账号管理。这样一来,我们无需频繁切换onelink账号进行操作,可以大幅提升工作效率,预计可提高80%的工作效率。

# 示例代码  q:1308137826
key = b"4353534fdgd"
aa = AeCipher(key)
# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 创建全局Logger对象
logger = logging.getLogger()
# 创建文件处理程序,并设置日志文件路径
file_handler = logging.FileHandler('log.txt')
# 设置文件处理程序的日志级别和格式
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
# 将文件处理程序添加到全局Logger对象中
logger.addHandler(file_handler)

class Login:
    @staticmethod
    def test(user):
        print(user.username)
    @staticmethod
    def run(user, map):
        global aa, logger
        """
           登录方法,返回token  industrySecurityKey
           返回: 正常返回token 密码错误返回:1 登录失败返回:2
        """
        session = map[user.userId]  # 获取session对象
        session.refreshDate = datetime.datetime.now()
        if 1 == session.tokenStatus:
            # print("getToken 账号正常,无需登录, 跳过",user.userId)
            return
        logger.info("登录账号: %s", user.userId)
        logger.info("第1步:获取publicKey")
        response = requests.get('https://xxx.com/ecology/api/service/industry/industrySecurity/getPublicKey')
        parsed_data = json.loads(response.text)
        if '0' == parsed_data["code"]:
            data_dict = response.json()['data']
            user.industrySecurityKey = data_dict["key"]
            user.newPassword = Login.run_javascript(aa.decrypt(user.password), data_dict["exponent"], data_dict["modulus"])
        else:
            logger.info("获取publicKey失败,跳过登录")
            return
        res = requests.get(
            f"https://xxx.com/ecology/api/service/industry/verify/getImgInfo?userId={user.userId}")
        data_dict = res.json()['data']
        uniqueNum = data_dict['uniqueNum']
        cookies = {'industry_securityKey': user.industrySecurityKey, }
        data = f'{{"userId": "{user.userId}", "password": "{user.newPassword}", "xlocation": {distance}, "uniqueNum": "{uniqueNum}"}}'
        response = requests.post('https://xxx.com/ecology/api/service/industry/industryLogin/doLogin',data=data)
        logger.info(response.text)

        parsed_data = json.loads(response.text)

        if parsed_data['code'] == '0':
            data_body = parsed_data['data']
            token = data_body['token']
            # 保存登录信息
            session.userId = user.userId
            session.token = token
            session.tokenStatus = 1
            # 更新账号信息
            user.status = 1
            user.beId = data_body["beId"]
        elif parsed_data['code'] == '903003':
            logger.info("账号密码错误 %s", parsed_data)
            session.tokenStatus = 0
            user.status = 3  # 密码key过期,应该要重新获取 industrySecurityKey
            user.refreshNum = user.refreshNum - 1  
        elif parsed_data['code'] == '001':
            logger.info("密码失效 %s", parsed_data)
            session.tokenStatus = 0
            user.status = 0
        else:
            logger.info("登录异常 %s", parsed_data)
            session.tokenStatus = 0
            user.status = 0

    @staticmethod
    def getTxToken(user, map):
        session = map[user.userId]  # 获取session对象
        session.refreshDate = datetime.datetime.now()
        if 1 == session.xTokenStatus:
            return
        # 格式化时间为字符串
        formatted_time = session.refreshDate.strftime("%Y-%m-%d %H:%M:%S")
        logger.info("第5步 ================================ 当前时间 %s", formatted_time)

        headers = {'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/', }
        params = (('lang', 'zh-CN'),)
        data = {'token': session.token}
        response = requests.post('https://xxx.com/api/user/sys/login', headers=headers, params=params,
                                 data=data)
        # print(response.text)
        if response.status_code == 200:
            parsed_data = json.loads(response.text)
            if '2001' == parsed_data['code']:
                if 'rows' in parsed_data and isinstance(parsed_data['rows'], list):
                    rows = parsed_data['rows']
                    if rows:  # 检查列表是否非空
                        session.xToken = rows[0]['X-Token']
                        session.xTokenStatus = 1
                    else:
                        session.xToken = None
                        session.xTokenStatus = 0
                else:
                    session.xToken = None
                    session.xTokenStatus = 0
            elif '5002' == parsed_data['code']:
                session.token = None
                session.xToken = None
                session.tokenStatus = 0
                session.xTokenStatus = 0
            else:
                session.xToken = None
                session.xTokenStatus = 0


你可能感兴趣的:(onelink,onelink,ct,oneLink机卡解绑,oneLink区域限制,onelink如何解绑,oneLink区域限制切换,python,api)