mirror of
https://git.oceanpay.cc/danial/kami_itunes_third_api.git
synced 2025-12-18 21:19:19 +00:00
fix: 修复重试错误
This commit is contained in:
23
assets/json/限额.json
Normal file
23
assets/json/限额.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"dialog": {
|
||||
"cancelButtonString": "进一步了解",
|
||||
"defaultButtonName": "ok",
|
||||
"cancelButtonAction": {
|
||||
"shouldShowTarget": false,
|
||||
"kind": "OpenURL",
|
||||
"action": "OpenURL",
|
||||
"url": "https:\/\/support.apple.com\/zh-cn\/HT207276"
|
||||
},
|
||||
"cancelButtonStringKey": "MZCommerce.NatIdYearlyCapExceededLearnMoreText",
|
||||
"okButtonString": "好",
|
||||
"message": "你已达到充值卡年度兑换限额。",
|
||||
"explanation": "你的兑换限额将于每年1月1日重置。",
|
||||
"okButtonStringKey": "OK",
|
||||
"explanationKey": "MZCommerce.NatIdYearlyCapExceededException_explanation"
|
||||
},
|
||||
"errorMessageKey": "MZCommerce.NatIdYearlyCapExceededException",
|
||||
"errorMessage": "ex.name (com.apple.jingle.foundation.exceptions.MZCodedException) -- ex.message (MZException code = MZCommerce.NatIdYearlyCapExceededException, userInfo = {adjectiveCountryName=中国, OriginationSystem=XCard, AdditionalInfoForSupport=NatIdYearlyCapExceededException})",
|
||||
"userPresentableErrorMessage": "你的兑换限额将于每年1月1日重置。",
|
||||
"errorNumber": 9519,
|
||||
"status": -1
|
||||
}
|
||||
@@ -45,9 +45,7 @@ def run_redeem_task(
|
||||
),
|
||||
)
|
||||
return
|
||||
itunes_service = ItunesService()
|
||||
response_schema = None
|
||||
|
||||
while True:
|
||||
response_schema_from_itunes = redis_client.get(
|
||||
f"apple_account_{master_order.account}"
|
||||
@@ -71,6 +69,7 @@ def run_redeem_task(
|
||||
response_schema = apple_account_schema.login_schema
|
||||
break
|
||||
time.sleep(2)
|
||||
itunes_service = ItunesService()
|
||||
# 设置登录标识
|
||||
if not response_schema_from_itunes:
|
||||
redis_client.setex(
|
||||
|
||||
@@ -5,7 +5,6 @@ import re
|
||||
import requests
|
||||
from loguru import logger
|
||||
from requests.exceptions import ConnectionError
|
||||
from urllib3 import HTTPSConnectionPool
|
||||
|
||||
from src.integrations.itunes.models.login import (
|
||||
ItunesLoginResponse,
|
||||
@@ -23,7 +22,10 @@ from src.integrations.june.models.redeem import AuthenticateModel, ItunesRedeemM
|
||||
|
||||
class AppleClient:
|
||||
def __init__(self):
|
||||
self.session = requests.Session()
|
||||
self.__session = requests.Session()
|
||||
self.__session.adapters.update({
|
||||
"DEFAULT_RETRIES": 5,
|
||||
})
|
||||
|
||||
def query_sign_sap_setup(self, signature: LoginSignatureModel, retries=3) -> str:
|
||||
if retries <= 0:
|
||||
@@ -40,7 +42,7 @@ class AppleClient:
|
||||
cookies["pod"] = signature.serverId
|
||||
cookies["itspod"] = signature.serverId
|
||||
try:
|
||||
response = self.session.post(
|
||||
response = self.__session.post(
|
||||
"https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/signSapSetup",
|
||||
data=signature.signature,
|
||||
headers={
|
||||
@@ -60,7 +62,7 @@ class AppleClient:
|
||||
return response.text
|
||||
|
||||
def login(
|
||||
self, sign_map: AuthenticateModel, server_id: str = "", retries: int = 5
|
||||
self, sign_map: AuthenticateModel, server_id: str = "", retries: int = 5
|
||||
) -> ItunesLoginResponse:
|
||||
headers = {
|
||||
"X-Apple-ActionSignature": sign_map.signature,
|
||||
@@ -87,17 +89,17 @@ class AppleClient:
|
||||
params = {}
|
||||
if server_id != "":
|
||||
url = (
|
||||
"https://p"
|
||||
+ server_id
|
||||
+ "-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
||||
"https://p"
|
||||
+ server_id
|
||||
+ "-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
||||
)
|
||||
params = {"Pod": server_id, "PRH": server_id}
|
||||
else:
|
||||
url = (
|
||||
"https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
||||
)
|
||||
self.session.headers["X-Apple-Store-Front"] = "143465-19,12"
|
||||
response = self.session.post(
|
||||
self.__session.headers["X-Apple-Store-Front"] = "143465-19,12"
|
||||
response = self.__session.post(
|
||||
url,
|
||||
headers=headers,
|
||||
cookies=cookies,
|
||||
@@ -115,14 +117,14 @@ class AppleClient:
|
||||
status = 31
|
||||
# 账户被禁用
|
||||
if (
|
||||
response_dict_data.get("metrics", {}).get("dialogId")
|
||||
== "MZFinance.AccountDisabled"
|
||||
response_dict_data.get("metrics", {}).get("dialogId")
|
||||
== "MZFinance.AccountDisabled"
|
||||
):
|
||||
status = 14
|
||||
# 账户被锁定
|
||||
if (
|
||||
response_dict_data.get("metrics", {}).get("dialogId")
|
||||
== "MZFinance.DisabledAndFraudLocked"
|
||||
response_dict_data.get("metrics", {}).get("dialogId")
|
||||
== "MZFinance.DisabledAndFraudLocked"
|
||||
):
|
||||
status = 14
|
||||
# 密码错误
|
||||
@@ -140,10 +142,10 @@ class AppleClient:
|
||||
)
|
||||
|
||||
def redeem(
|
||||
self,
|
||||
code: str,
|
||||
itunes: ItunesLoginModel,
|
||||
reties=5,
|
||||
self,
|
||||
code: str,
|
||||
itunes: ItunesLoginModel,
|
||||
reties=5,
|
||||
) -> RedeemSuccessResponse | RedeemFailResponseModel:
|
||||
if reties <= 0:
|
||||
logger.error("充值重试次数已用完")
|
||||
@@ -170,10 +172,10 @@ class AppleClient:
|
||||
"Content-Type": "application/x-apple-plist; Charset=UTF-8",
|
||||
"User-Agent": "MacAppStore/2.0 (Macintosh; OS X 12.10) AppleWebKit/600.1.3.41",
|
||||
"Referer": f"https://p{itunes.server_id}-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/com.apple"
|
||||
f".jingle.app.finance.DirectAction/redeemCode?cl=iTunes&pg=Music",
|
||||
f".jingle.app.finance.DirectAction/redeemCode?cl=iTunes&pg=Music",
|
||||
}
|
||||
try:
|
||||
response = self.session.post(
|
||||
response = self.__session.post(
|
||||
url,
|
||||
data=ItunesRedeemModel(
|
||||
attempt_count=1,
|
||||
@@ -188,7 +190,7 @@ class AppleClient:
|
||||
).to_xml(),
|
||||
headers=headers,
|
||||
)
|
||||
except HTTPSConnectionPool as e:
|
||||
except ConnectionError as e:
|
||||
return self.redeem(code, itunes, reties - 1)
|
||||
response.encoding = "utf-8"
|
||||
try:
|
||||
@@ -217,12 +219,16 @@ class AppleClient:
|
||||
result = RedeemFailResponseModel.model_validate(response.json())
|
||||
result.origin_log = response.text
|
||||
if (
|
||||
result.errorMessageKey
|
||||
== "MZCommerce.GiftCertificateAlreadyRedeemed"
|
||||
result.errorMessageKey
|
||||
== "MZCommerce.GiftCertificateAlreadyRedeemed"
|
||||
):
|
||||
result.status = 12
|
||||
if result.errorMessageKey == "MZFreeProductCode.NoSuch":
|
||||
elif result.errorMessageKey == "MZFreeProductCode.NoSuch":
|
||||
result.status = 11
|
||||
elif result.errorMessageKey == "MZCommerce.NatIdYearlyCapExceededException":
|
||||
result.status = 31
|
||||
else:
|
||||
logger.error(f"失败状态未知:{response.json()}")
|
||||
if result.status == -1 or result.status == 0:
|
||||
result.status = 30
|
||||
logger.warning("兑换状态未知:", response.text)
|
||||
@@ -239,7 +245,7 @@ class AppleClient:
|
||||
|
||||
# 导出cookies
|
||||
def export_cookies(self) -> bytes:
|
||||
return pickle.dumps(self.session.cookies)
|
||||
return pickle.dumps(self.__session.cookies)
|
||||
|
||||
def import_cookies(self, cookies: bytes):
|
||||
self.session.cookies.update(pickle.loads(cookies))
|
||||
self.__session.cookies.update(pickle.loads(cookies))
|
||||
|
||||
@@ -23,7 +23,7 @@ from src.integrations.june.utils.utils import ShareCodeUtils, decode_and_decompr
|
||||
|
||||
class SixClient:
|
||||
def __init__(self):
|
||||
self.base_url = "http://43.241.16.229:6113"
|
||||
self.__base_url = "http://43.241.16.229:6113"
|
||||
# self.session = requests.Session()
|
||||
|
||||
def _do_post(
|
||||
@@ -67,7 +67,7 @@ class SixClient:
|
||||
)
|
||||
try:
|
||||
response = requests.post(
|
||||
parse.urljoin(self.base_url, "/AppleClientApi/requestApi"),
|
||||
parse.urljoin(self.__base_url, "/AppleClientApi/requestApi"),
|
||||
data={
|
||||
"authentiString": base64.b64encode(text3.encode("utf-8")).decode(
|
||||
"utf-8"
|
||||
|
||||
Reference in New Issue
Block a user