(self, endpoint: str, params: dict)
| 224 | return response.json() |
| 225 | |
| 226 | def request_encrypted(self, endpoint: str, params: dict) -> dict: |
| 227 | self.session.headers["imencrypt"] = "1" |
| 228 | imrandomnum = generate_random_string(16) |
| 229 | imtimestamp = str(int(time.time() * 1000)) |
| 230 | imencryptkey = encryptmd5(imtimestamp, imrandomnum) |
| 231 | |
| 232 | form_data = {"channelId": CHANNEL_ID, "portal": "45"} |
| 233 | form_data.update(params) |
| 234 | encrypted_form = encrypt_request(form_data, imrandomnum, imtimestamp, imencryptkey) |
| 235 | |
| 236 | headers = { |
| 237 | "imencryptkey": imencryptkey, |
| 238 | "imrandomnum": imrandomnum, |
| 239 | "imtimestamp": imtimestamp, |
| 240 | } |
| 241 | url = f"{self.BASE_URL}{endpoint}" |
| 242 | response = self.session.post(url, params={"formData": encrypted_form}, headers=headers, timeout=30) |
| 243 | |
| 244 | new_auth = response.headers.get("Authorization") |
| 245 | if new_auth: |
| 246 | self.token = new_auth |
| 247 | self.session.headers["Authorization"] = f"Bearer {new_auth}" |
| 248 | |
| 249 | try: |
| 250 | return decrypt_response(response.text, imrandomnum, imtimestamp, imencryptkey) |
| 251 | except: |
| 252 | return {"raw": response.text} |
| 253 | |
| 254 | def get_user_info(self, mobile: str) -> dict: |
| 255 | params = {"channelId": CHANNEL_ID, "portal": "45", "mobile": mobile} |
no test coverage detected