抖音设备注册算法实现

 

纯算法实现方式看这里

下面的代码非纯算法实现,并不一定适用...

1、第一步:抓包

        抖音APP刚安装到手机上,再打开是都会自动请求API进行设备的注册,抓到注册的包并进行分析,抓包数据如下:

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:加密后的数据

这是抖音设备注册接口,接口最重要的信息放在了body里面,body是经过加密后得到的。

2、分析:

        body未加密前的参数其实主要就三个:udid、openudid、mc,至于这三个参数值是怎么生成的,其实很简单,不清楚的可以留言。

        三个参数拿到后,进一步计算并进行gzip压缩,然后放在body内请求API即可完成设备的注册。

3、上代码

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、注册结果

{"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}

搞定,注册好的设备可以做成一个设备池,随机取用,交流学习+v:YY_yhzf。

猜你喜欢

转载自blog.csdn.net/nanxiaotiantian/article/details/105168014