1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #!/usr/bin/env python # -*- encoding: utf-8 -*-
import uuid import time import hmac import hashlib import base64 import httpx import json
class PICACG: api_key = 'C69BAF41DA5ABD1FFEDC6D2FEA56B' secret_key = 'fmR9JFE3JGVJbmk9Vik5XFJLL1AuUk00OzlbN3xAL0NBfWJ+T1chMz9FVmA6PD5NN3BkZFVCTDVufDAvKkNu' base_url = 'https://picaapi.picacomic.com/' headers = { 'user-agent': 'okhttp/3.8.1', 'Accept-Encoding': 'gzip, deflate', 'accept': 'application/vnd.picacomic.com.v1+json', 'api-key': api_key, 'app-channel': '3', 'app-uuid': 'defaultUuid', 'app-version': '2.2.1.3.3.4', 'image-quality': 'original', 'app-platform': 'android', 'app-build-version': '45', 'Host': 'picaapi.picacomic.com', 'Content-Type': 'application/json; charset=UTF-8', #'application/x-www-form-urlencoded' }
@staticmethod def _proxy(proxy):
if isinstance(proxy, dict): proxies = proxy elif proxy == 'Clash': proxies = { 'http': 'http://localhost:7890', 'https': 'http://localhost:7890', } elif proxy == 'BurpSuite': proxies = { 'http': 'http://localhost:8080', 'https': 'http://localhost:8080', } else: proxies = {} return proxies
def __init__(self, proxy=False): self.client = httpx.Client( base_url=self.base_url, proxies=self._proxy(proxy))
@staticmethod def _nonce() -> str: nonce = uuid.uuid4().hex return nonce
@staticmethod def _timestamp() -> str: timestamp = time.time()
return str(int(timestamp))
def _signature(self, path, method) -> dict: """Signature encrypter""" time = self._timestamp() nonce = self._nonce() api_key = self.api_key key = base64.b64decode(self.secret_key.encode())
formater = path + time + nonce + method + api_key msg = formater.lower().encode()
encrypter = hmac.new(key, msg, digestmod=hashlib.sha256) signature = encrypter.hexdigest()
varibals = { 'time': time, 'nonce': nonce, 'signature': signature }
headers = self.headers.copy() headers.update(varibals) return headers
def login(self, uid: str, pwd: str): url = 'auth/sign-in' method = 'POST' headers = self._signature(url, method) data = { 'email': uid, 'password': pwd }
res = self.client.post(url=url, headers=headers, data=json.dumps(data)) print(res.json()) token = res.json()['data'].get('token')
return token
pica = PICACG(proxy= 'Clash') token = pica.login('uid','pwd')
|