Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
兑换请求增加设置x-rpc-device_fp #132 #129 #125 #121 #116 #114
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljzd-PRO committed Jul 7, 2023
1 parent dc7926e commit e940930
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions mys_goods_tool/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,11 +1258,12 @@ async def good_exchange(plan: ExchangePlan) -> Tuple[ExchangeStatus, Optional[Ex
"""
headers = HEADERS_EXCHANGE
headers["x-rpc-device_id"] = plan.account.device_id_ios
headers["x-rpc-device_fp"] = plan.account.device_fp or generate_seed_id(6)
content = {
"app_id": 1,
"point_sn": "myb",
"goods_id": plan.good.goods_id,
"exchange_num": 1,
"exchange_num": 1
}
if plan.address is not None:
content.setdefault("address_id", plan.address.id)
Expand All @@ -1276,7 +1277,7 @@ async def good_exchange(plan: ExchangePlan) -> Tuple[ExchangeStatus, Optional[Ex
async with httpx.AsyncClient() as client:
res = await client.post(
URL_EXCHANGE, headers=headers, json=content,
cookies=plan.account.cookies.dict(v2_stoken=True, cookie_type=True),
cookies=plan.account.cookies.dict(cookie_type=True),
timeout=conf.preference.timeout)
api_result = ApiResultHandler(res.json())
if api_result.login_expired:
Expand Down Expand Up @@ -1314,11 +1315,12 @@ def good_exchange_sync(plan: ExchangePlan) -> Tuple[ExchangeStatus, Optional[Exc
"""
headers = HEADERS_EXCHANGE
headers["x-rpc-device_id"] = plan.account.device_id_ios
headers["x-rpc-device_fp"] = plan.account.device_fp or generate_seed_id(6)
content = {
"app_id": 1,
"point_sn": "myb",
"goods_id": plan.good.goods_id,
"exchange_num": 1,
"exchange_num": 1
}
if plan.address is not None:
content.setdefault("address_id", plan.address.id)
Expand All @@ -1332,7 +1334,7 @@ def good_exchange_sync(plan: ExchangePlan) -> Tuple[ExchangeStatus, Optional[Exc
with httpx.Client() as client:
res = client.post(
URL_EXCHANGE, headers=headers, json=content,
cookies=plan.account.cookies.dict(v2_stoken=True, cookie_type=True),
cookies=plan.account.cookies.dict(cookie_type=True),
timeout=conf.preference.timeout)
api_result = ApiResultHandler(res.json())
if api_result.login_expired:
Expand Down
2 changes: 2 additions & 0 deletions mys_goods_tool/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class UserAccount(BaseModelWithSetter, extra=Extra.ignore):
"""iOS设备用 deviceID"""
device_id_android: str
"""安卓设备用 deviceID"""
device_fp: Optional[str]
"""iOS设备用 deviceFp"""

def __init__(self, **data: Any):
if not data.get("device_id_ios") or not data.get("device_id_android"):
Expand Down
6 changes: 4 additions & 2 deletions mys_goods_tool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,13 @@ def generate_ds(data: Union[str, dict, list, None] = None, params: Union[str, di
return f"{t},{r},{c}"


async def generate_seed_id() -> str:
async def generate_seed_id(length: int = 8) -> str:
"""
生成随机的 seed_id(即长度为8的十六进制数)
:param length: 16进制数长度
"""
max_num = int("FF" * 8, 16)
max_num = int("FF" * length, 16)
return hex(random.randint(0, max_num))[2:]


Expand Down

0 comments on commit e940930

Please sign in to comment.