fix(card): 修复cgc搜卡5s盾验证

This commit is contained in:
xingc
2025-08-18 01:59:01 +08:00
parent 5f1ed61536
commit cddb0ab0dd
4 changed files with 32 additions and 13 deletions

View File

@@ -58,6 +58,10 @@ class UpdateCard(BaseModel):
display_price: condecimal(max_digits=10, decimal_places=2)
class PlatformSessionsIn(BaseModel):
data: dict
class SearchCardOut(Card):
pass

View File

@@ -15,9 +15,9 @@ from parsel import Selector
from simple_spider_tool import jsonpath, regx_match, format_json
from config import settings
from core.db.engine import get_cache
from core.base.exceptions import SearchCardRetry, SearchCardRetryFail, SearchCardHandlerFail
from core.utils.helper import async_retry
from core.utils.helper import decrypt_aes_cbc
from core.utils.helper import async_retry, decrypt_aes_cbc, generate_keyname
logger = logging.getLogger(__name__)
@@ -49,14 +49,17 @@ class SiteApi:
data=None,
json=None,
use_abroad_proxy: bool = False,
use_random_ua: bool = True,
retry_num: int = 3,
**kwargs
):
headers = {
**self.headers,
'User-Agent': self.user_agent.random,
**(headers or {}),
}
if use_random_ua:
headers['User-Agent'] = self.user_agent.random
# 境外代理
if use_abroad_proxy:
kwargs['proxies'] = {
@@ -69,7 +72,11 @@ class SiteApi:
r = await self.session.request(
method, url, headers=headers, params=params, data=data, json=json, **kwargs
)
logger.debug(f'耗时:{url} {r.elapsed}')
chck_string = 'Just a moment...'
if chck_string in r.text:
raise SearchCardRetry(chck_string)
return r
except CurlError as e:
@@ -95,9 +102,6 @@ class SiteApi:
'Referer': f'https://www.psacard.com/cert/{cert_number}',
}
r = await self.get(url, headers=headers, impersonate="chrome110")
chck_string = 'Just a moment...'
if chck_string in r.text:
raise SearchCardRetry(chck_string)
return r
async def psa_images(self, cert_number: str | int, images_id: str | int):
@@ -126,10 +130,15 @@ class SiteApi:
async def cgc(self, cert_number: str | int):
"""CGC"""
url = f'https://www.cgccards.com/certlookup/{cert_number}/'
headers = {
'referer': 'https://www.cgccards.com/'
}
return await self.get(url, headers=headers, impersonate="chrome110")
redis_conn = await get_cache()
async with redis_conn:
cache_session_str = await redis_conn.get(generate_keyname('session:cgc'))
if isinstance(cache_session_str, str):
headers = ujson.decode(cache_session_str)
else:
headers = {}
return await self.get(url, headers=headers, use_random_ua=False, use_abroad_proxy=True)
async def gbtc(self, cert_number: str | int):
"""北京公博"""