#!/usr/bin/python3 import time import hashlib import json import base64 import hmac import requests import jwt import sys if len(sys.argv) != 2: print("i need one ICCID.") exit(-1) iccid = sys.argv[1] private_key = b"""-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtkpIspKwGBKe/ qSrx/JwOf/p/phAP132Tuy2XSSmas1hx49EMRZg6meEkPwz2utYQX2NKFi/CrYd3 fOrFa4HguokD9A5mdlX4TPxea91fOnFOOTdpS3iYYAYQpbR3lsE5Xau/jCcExaXz MEgG5XVRxpmFcqwvC5LYvbt37XjxvlZE2VpY8sEItOl9ALyYT3Phxyt7bHz1Vhtk /C5mtADf7OW9eUaORIVoKfFss4vsRf3MS7oi81II+izxde0StR+Psr6htlKerylh 4FffN6buyCooKk7Lj4Y2uvy7eMsWgjanYOZdZ17+2nojDq3ev5BuD/yGrzX1NYFO m4JhZd2FAgMBAAECggEANpW7hnKa7qGUJ4AJ02P/p8ezfWU58+FuyoC4y7TkcpQo IljkqxlP0E4IMZ/qccU8AJYe4XOsvWpZCcitBDzU8Vl4MVgVFz/rtVRwoTkGuyXj 8BeqR2DGohTAk4epA1rTlTjSBEENHEET+TCb1h9fD8KHESKI55qaKbMxO3vg5xTR 5cCb+Zp6vu/tZw/LeYY3aNocD9Jy7WHDLk7HgT9QQ58LI7zOAhfVj+eVnhR8m/me 3tz2LWCOxzKi5QpCP8dAUxED17C0sl+8uOup/pDvcz9s9FBmTNeljtSV6xlJ8Xhr V9LvzRrPmERc4bVikmomeS7BAAkOcVeUUQixNB5SmQKBgQDY0CYPAGZA8ST7HVCb 5eMTpxozczQTOjK0z9PETgXsepLcIcmVtAQU7NM6rkigOp1ocHOP0JGyUWNuyWhc zeKy/5mcWdxXPnJaiYoWY5p9WfYWALkgTe1FyFwsqMPS9m4BX4vxE6htvEZ315mE uQMS35Fqv8UqhZdHelu14lwfqwKBgQDM8bNY7pc6V5KPaghJUpXmkCn9JoWKANZV N41zUAS8V9i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bg/8hq819TWBTpuCYWXd hQIDAQAB -----END PUBLIC KEY----- """ ts = int(time.time()) headers = { "typ": "JWT", "kid": "tsmkc-client", "alg": "RS256" } claims = { "sub": "kingcard", "iss": "tsmkc.qq.com", "exp": ts + 300, "iat": ts - 10, "iccid": iccid, "userid": "", "usersig": "" } encoded_token = jwt.encode(claims, private_key, algorithm="RS256", headers=headers) get_headers = { 'Content-Type': 'application/json', 'user-agent': 'okhttp/3.5.0', 'Authorization': 'Bearer ' + encoded_token.decode("ascii") } r = requests.get('https://api.tsmkc.qq.com/prd/v1/package/packageinfo', headers=get_headers) print(r.text)
用的jwt做的认证