Implementation of Douyin device registration algorithm

 

See here for pure algorithm implementation

 

The following code is not a pure algorithm implementation, and may not be applicable...

1. The first step: packet capture

        The Douyin APP has just been installed on the phone, and then opened, it will automatically request the API to register the device, capture the registered package and analyze it. The captured package data is as follows:

POST /service/2/device_register/?ac=wifi&channel=wandoujia_aweme2&aid=1128&app_name=aweme&version_code=750&version_name=7.5.0&device_platform=android&ssmix=a&device_type=HWI-AL00&device_brand=HUAWEI&language=zh&os_api=28&os_version=9&uuid=868793039197273&openudid=9ba4839bf09a1834&manifest_version_code=750&resolution=1080*2160&dpi=480&update_version_code=7502&_rticket=1585398980154&app_type=normal&mcc_mnc=46001&ts=1585398980&tt_data=a HTTP/1.1

body:加密后的数据

This is the TikTok device registration interface. The most important information of the interface is placed in the body, which is obtained after being encrypted.

2. Analysis:

        There are actually three main parameters before the body is not encrypted: udid, openudid, and mc. As for how these three parameter values ​​are generated, it is actually very simple, you can leave a message if you are not sure.

        After the three parameters are obtained, further calculation and gzip compression are performed, and then the device registration can be completed by requesting the API in the body.

3. On the code

class WeChat_YY_yhzf:

    NoResult = {
        'msg':'fail.'
    }

    @classmethod
    def get_system(cls):
        system = platform.system()
        if system.startswith("Win"):
            return "win" + platform.machine()[-2:]
        elif system.startswith("Lin"):
            return "linux" + platform.machine()[-2:]
        else:
            return "osx64"

    @classmethod
    def get_random_mc(cls):
        mc_random = ["a", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
        mc = '{}:{}:{}:{}:{}:{}'.format("".join(random.choices(mc_random, k=2)),"".join(random.choices(mc_random, k=2)))
        return mc

    @classmethod
    def hexStr_to_str(cls,hex_str):
        hexadecimal = hex_str.encode('utf-8')
        return str_bin

    @classmethod
    async def douyinDeviceRegister(cls):
        hex_str = cls.get_hex_str()
        astr = cls.hexStr_to_str(hex_str)
        proxyip = await get_proxy()
        async with aiohttp.ClientSession() as session:
            async with session.post(DGapi.DouYin, data=astr, headers=DOUYIN_HEADERS, proxy=proxyip) as resp:
                ret = await resp.json()
                return ret

4. Registration result

{"code": 200, "data": {"server_time": 1585398886, "device_id": 71290152969, "install_id": 109475974564, "device_id_str": "71290152969", "install_id_str": "109475974564", "new_user": 1}, "success": 1}

It's done, the registered device can be made into a device pool, random access, exchange learning +v:YY_yhzf.

Guess you like

Origin blog.csdn.net/nanxiaotiantian/article/details/105168014