抖音設備註冊算法實現

純算法實現方式看這裏

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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章