用 python批量 查询华为设备序列号

查询地址:https://consumer.huawei.com/cn/support/warranty-query/

 

代码如下:

# -*- coding: utf-8 -*-

import os
import requests
# import http.cookiejar as cookielib
import json
import base64

file = open("input.txt", "r")
# 记得在同目录下面放input.txt文件 里面是sn码回车换行
lines = file.readlines()
for line in lines:
    sn = str(line).strip()
    print(sn+' > ', end='')

  
    httpClient = requests.session()
    # Xiaohe QQ496631085
    response = httpClient.get("https://ccpce-cn.consumer.huawei.com/ccpcmd/services/dispatch/secured/CCPC/EN/ccpc/queryPicVerifyCode/1000")
    # 去除括号
    res = response.text.lstrip('(').rstrip(')')
    print(res)

    verifyCodeData = json.loads(res)
    sessionId = verifyCodeData['responseData']['sessionId']
    
    # 拉取验证码  编码后 自动识别    验证码可能被关闭了,需要请联系  或自行更换
    response = httpClient.get(verifyCodeData['responseData']['picUrl'])
    base64 = base64.encodebytes(response.content)
    base64 = str(base64, "utf-8")
    base64 = base64.replace('\n', '')
    verifyCode = httpClient.post("http://aota.fotaboss.com:1995/captcha/v1", data=json.dumps({"image": base64}))
    verifyCode = json.loads(verifyCode.text)['message']
    # 识别验证码完成

    print(verifyCode+' <<<<< ', end='')


    # 需要提交的数据
    data = {"sn":sn,
            "countryCode":"CN",
            "langCode":"zh-cn",
            "sessionId":sessionId,
            "verifyCode":verifyCode,
            "channelCode":"WEBSITE",
            "country":"CN",
            "language":"zh-cn",
            "siteCode":"zh_CN"}


    # httpClient.cookies.load()
    headers ={
        'Host': 'ccpce-cn.consumer.huawei.com',
        'Connection': 'keep-alive',
        'Content-Length': '206',
        'sec-ch-ua': '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
        'Content-Type': 'application/json',
        'Origin': 'https://consumer.huawei.com',
        'Sec-Fetch-Site': 'same-site',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://consumer.huawei.com/',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9'}
    response = httpClient.post("https://ccpce-cn.consumer.huawei.com/ccpcmd/services/dispatch/secured/CCPC/EN/ccps/getDeviceV2/1000", data=json.dumps(data), headers=headers)
    result = response.text

    print(result)

 

posted @ 2021-01-16 12:50  xiaohe520  阅读(1437)  评论(3编辑  收藏  举报