mirror of
https://git.oceanpay.cc/danial/kami_itunes_third_api.git
synced 2025-12-18 22:20:08 +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
|
return
|
||||||
itunes_service = ItunesService()
|
|
||||||
response_schema = None
|
response_schema = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
response_schema_from_itunes = redis_client.get(
|
response_schema_from_itunes = redis_client.get(
|
||||||
f"apple_account_{master_order.account}"
|
f"apple_account_{master_order.account}"
|
||||||
@@ -71,6 +69,7 @@ def run_redeem_task(
|
|||||||
response_schema = apple_account_schema.login_schema
|
response_schema = apple_account_schema.login_schema
|
||||||
break
|
break
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
itunes_service = ItunesService()
|
||||||
# 设置登录标识
|
# 设置登录标识
|
||||||
if not response_schema_from_itunes:
|
if not response_schema_from_itunes:
|
||||||
redis_client.setex(
|
redis_client.setex(
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import re
|
|||||||
import requests
|
import requests
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from requests.exceptions import ConnectionError
|
from requests.exceptions import ConnectionError
|
||||||
from urllib3 import HTTPSConnectionPool
|
|
||||||
|
|
||||||
from src.integrations.itunes.models.login import (
|
from src.integrations.itunes.models.login import (
|
||||||
ItunesLoginResponse,
|
ItunesLoginResponse,
|
||||||
@@ -23,7 +22,10 @@ from src.integrations.june.models.redeem import AuthenticateModel, ItunesRedeemM
|
|||||||
|
|
||||||
class AppleClient:
|
class AppleClient:
|
||||||
def __init__(self):
|
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:
|
def query_sign_sap_setup(self, signature: LoginSignatureModel, retries=3) -> str:
|
||||||
if retries <= 0:
|
if retries <= 0:
|
||||||
@@ -40,7 +42,7 @@ class AppleClient:
|
|||||||
cookies["pod"] = signature.serverId
|
cookies["pod"] = signature.serverId
|
||||||
cookies["itspod"] = signature.serverId
|
cookies["itspod"] = signature.serverId
|
||||||
try:
|
try:
|
||||||
response = self.session.post(
|
response = self.__session.post(
|
||||||
"https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/signSapSetup",
|
"https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/signSapSetup",
|
||||||
data=signature.signature,
|
data=signature.signature,
|
||||||
headers={
|
headers={
|
||||||
@@ -60,7 +62,7 @@ class AppleClient:
|
|||||||
return response.text
|
return response.text
|
||||||
|
|
||||||
def login(
|
def login(
|
||||||
self, sign_map: AuthenticateModel, server_id: str = "", retries: int = 5
|
self, sign_map: AuthenticateModel, server_id: str = "", retries: int = 5
|
||||||
) -> ItunesLoginResponse:
|
) -> ItunesLoginResponse:
|
||||||
headers = {
|
headers = {
|
||||||
"X-Apple-ActionSignature": sign_map.signature,
|
"X-Apple-ActionSignature": sign_map.signature,
|
||||||
@@ -87,17 +89,17 @@ class AppleClient:
|
|||||||
params = {}
|
params = {}
|
||||||
if server_id != "":
|
if server_id != "":
|
||||||
url = (
|
url = (
|
||||||
"https://p"
|
"https://p"
|
||||||
+ server_id
|
+ server_id
|
||||||
+ "-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
+ "-buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
||||||
)
|
)
|
||||||
params = {"Pod": server_id, "PRH": server_id}
|
params = {"Pod": server_id, "PRH": server_id}
|
||||||
else:
|
else:
|
||||||
url = (
|
url = (
|
||||||
"https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
"https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/authenticate"
|
||||||
)
|
)
|
||||||
self.session.headers["X-Apple-Store-Front"] = "143465-19,12"
|
self.__session.headers["X-Apple-Store-Front"] = "143465-19,12"
|
||||||
response = self.session.post(
|
response = self.__session.post(
|
||||||
url,
|
url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
@@ -115,14 +117,14 @@ class AppleClient:
|
|||||||
status = 31
|
status = 31
|
||||||
# 账户被禁用
|
# 账户被禁用
|
||||||
if (
|
if (
|
||||||
response_dict_data.get("metrics", {}).get("dialogId")
|
response_dict_data.get("metrics", {}).get("dialogId")
|
||||||
== "MZFinance.AccountDisabled"
|
== "MZFinance.AccountDisabled"
|
||||||
):
|
):
|
||||||
status = 14
|
status = 14
|
||||||
# 账户被锁定
|
# 账户被锁定
|
||||||
if (
|
if (
|
||||||
response_dict_data.get("metrics", {}).get("dialogId")
|
response_dict_data.get("metrics", {}).get("dialogId")
|
||||||
== "MZFinance.DisabledAndFraudLocked"
|
== "MZFinance.DisabledAndFraudLocked"
|
||||||
):
|
):
|
||||||
status = 14
|
status = 14
|
||||||
# 密码错误
|
# 密码错误
|
||||||
@@ -140,10 +142,10 @@ class AppleClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def redeem(
|
def redeem(
|
||||||
self,
|
self,
|
||||||
code: str,
|
code: str,
|
||||||
itunes: ItunesLoginModel,
|
itunes: ItunesLoginModel,
|
||||||
reties=5,
|
reties=5,
|
||||||
) -> RedeemSuccessResponse | RedeemFailResponseModel:
|
) -> RedeemSuccessResponse | RedeemFailResponseModel:
|
||||||
if reties <= 0:
|
if reties <= 0:
|
||||||
logger.error("充值重试次数已用完")
|
logger.error("充值重试次数已用完")
|
||||||
@@ -170,10 +172,10 @@ class AppleClient:
|
|||||||
"Content-Type": "application/x-apple-plist; Charset=UTF-8",
|
"Content-Type": "application/x-apple-plist; Charset=UTF-8",
|
||||||
"User-Agent": "MacAppStore/2.0 (Macintosh; OS X 12.10) AppleWebKit/600.1.3.41",
|
"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"
|
"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:
|
try:
|
||||||
response = self.session.post(
|
response = self.__session.post(
|
||||||
url,
|
url,
|
||||||
data=ItunesRedeemModel(
|
data=ItunesRedeemModel(
|
||||||
attempt_count=1,
|
attempt_count=1,
|
||||||
@@ -188,7 +190,7 @@ class AppleClient:
|
|||||||
).to_xml(),
|
).to_xml(),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
except HTTPSConnectionPool as e:
|
except ConnectionError as e:
|
||||||
return self.redeem(code, itunes, reties - 1)
|
return self.redeem(code, itunes, reties - 1)
|
||||||
response.encoding = "utf-8"
|
response.encoding = "utf-8"
|
||||||
try:
|
try:
|
||||||
@@ -217,12 +219,16 @@ class AppleClient:
|
|||||||
result = RedeemFailResponseModel.model_validate(response.json())
|
result = RedeemFailResponseModel.model_validate(response.json())
|
||||||
result.origin_log = response.text
|
result.origin_log = response.text
|
||||||
if (
|
if (
|
||||||
result.errorMessageKey
|
result.errorMessageKey
|
||||||
== "MZCommerce.GiftCertificateAlreadyRedeemed"
|
== "MZCommerce.GiftCertificateAlreadyRedeemed"
|
||||||
):
|
):
|
||||||
result.status = 12
|
result.status = 12
|
||||||
if result.errorMessageKey == "MZFreeProductCode.NoSuch":
|
elif result.errorMessageKey == "MZFreeProductCode.NoSuch":
|
||||||
result.status = 11
|
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:
|
if result.status == -1 or result.status == 0:
|
||||||
result.status = 30
|
result.status = 30
|
||||||
logger.warning("兑换状态未知:", response.text)
|
logger.warning("兑换状态未知:", response.text)
|
||||||
@@ -239,7 +245,7 @@ class AppleClient:
|
|||||||
|
|
||||||
# 导出cookies
|
# 导出cookies
|
||||||
def export_cookies(self) -> bytes:
|
def export_cookies(self) -> bytes:
|
||||||
return pickle.dumps(self.session.cookies)
|
return pickle.dumps(self.__session.cookies)
|
||||||
|
|
||||||
def import_cookies(self, cookies: bytes):
|
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:
|
class SixClient:
|
||||||
def __init__(self):
|
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()
|
# self.session = requests.Session()
|
||||||
|
|
||||||
def _do_post(
|
def _do_post(
|
||||||
@@ -67,7 +67,7 @@ class SixClient:
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
parse.urljoin(self.base_url, "/AppleClientApi/requestApi"),
|
parse.urljoin(self.__base_url, "/AppleClientApi/requestApi"),
|
||||||
data={
|
data={
|
||||||
"authentiString": base64.b64encode(text3.encode("utf-8")).decode(
|
"authentiString": base64.b64encode(text3.encode("utf-8")).decode(
|
||||||
"utf-8"
|
"utf-8"
|
||||||
|
|||||||
Reference in New Issue
Block a user