介面測試:生成Token,使用手機did生成accessToken,再用accessToken生成token 例項

幽影冥狐發表於2020-12-26
import requests
import re
import time
import unittest
import  json
import urllib3


'''生成Token,使用手機did生成accessToken,再用accessToken生成token 例項'''

did=["B29146D1D30178771CDF1457E2F5FFCB",
"74dafc08453eb32f3b7a4c7a97a2b7e3"]



# 迴圈生成accessToken
for i in range(1):
    # if i!=2:
        for j in range(0,300):
        # for did in did:
            print(j,'did=',did[j], '\n')

            DAD=did[j]

            #使用裝置DID生成accessToken
            url='https://bld-usercenter-qa.xingkd.cn/8132/v12/api/login/third'
            data={"app_version":'2.0.2.0001',"token":DAD,"login_type":20,"device_type":1}#登入方式:QQ:12,微信:13,裝置:20
            headers = {
                       "Content-Type":"application/json",
                     }

            urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)  # 禁用安全請求警告方法一
            results= requests.post(url=url,json=data, headers=headers, verify=False).text


            QQA = json.loads(results)  # 用json.loads()把requests的請求轉換成json格式轉換為字典


            # QQC=QQB[data]
            print(j,'驗證返回值',QQA["data"]["accessToken"],'\n')
            accessToken=QQA["data"]["accessToken"]
            print('accessToken出來了',accessToken)

            # 使用accessToken生成token
            url1='https://bld-business-qa.xingkd.cn/9012/v11/api/deviceLogin'
            data1={"app_version":'2.0.2.0001',"accessToken":accessToken}
            urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)  # 禁用安全請求警告方法一
            results1= requests.post(url=url1,json=data1, headers=headers, verify=False).text
            QQB = json.loads(results1)
            print(j,'token的值=',QQB['token'],'\n')
            token1=QQB['token']
            print('token是什麼',token1,'\n')

 

相關文章