Files
kami_spider_monorepo/apps/jd/services/goods_apple_card.py
danial 6c768b6e7b feat(jd): 添加京东相关路由及苹果权益充值功能
- 新增jd模块基础路由,整合app_store和payment子路由
- 实现苹果权益充值接口,支持苹果、携程及沃尔玛多个渠道
- 实现卡号密码查询接口,支持不同类别订单查询
- 新增短信认证相关接口,实现短信验证码发送及短信登录
- 新增商品管理接口,支持SKU详情查询及账号类下单功能
- 新增订单管理接口,实现订单删除功能
- 实现支付相关接口,增加刷新支付参数功能
- 定义完整请求及响应数据模型,确保接口数据规范
- 编写AppStoreSpider类,封装苹果应用内订单处理逻辑
- 引入多种代理池及请求重试机制,增强接口稳定性
- 添加详细日志记录,便于请求追踪与错误排查
2025-11-03 19:35:39 +08:00

146 lines
7.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from curl_cffi import requests
from apps.jd.services.app_store import AppStoreSpider
from observability.logging import get_logger_with_trace
logger = get_logger_with_trace(__name__)
class GoodsAppleCard(AppStoreSpider):
def __init__(
self,
cookies,
order_num,
brand_id,
face_price,
sku_id,
username,
game_srv=None,
game_area=None,
recharge_type=1,
):
super(GoodsAppleCard, self).__init__(cookies, order_num, face_price=face_price)
self.sku_id = sku_id
self.brand_id = brand_id
self.username = username
self.game_srv = game_srv
self.game_area = game_area
self.face_price = face_price
self.recharge_type = recharge_type
def encrypt_username(self, username):
key = "2E1ZMAF88CCE5EBE551FR3E9AA6FF322"
username = self.js.call("encryptDes", username, key)
return username
def submit_gp_order(self):
headers = {
"Host": "api.m.jd.com",
"pragma": "no-cache",
"cache-control": "no-cache",
"user-agent": self.__user_client,
"accept": "application/json, text/plain, */*",
"x-referer-page": "https://recharge.m.jd.com/cardSettlement",
"content-type": "application/x-www-form-urlencoded",
"x-rp-client": "h5_1.0.0",
"origin": "https://recharge.m.jd.com",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "https://recharge.m.jd.com/",
"accept-language": "zh-CN,zh;q=0.9",
"priority": "u=1, i",
"cookie": self.cookies,
}
username = self.encrypt_username(self.username)
data = {}
if self.recharge_type == 1:
data = {
"appid": "tsw-m",
"functionId": "submitGPOrder",
"t": f"{self.time_stamp}",
"body": '{"skuId":"%s","brandId":"%s","type":2,"buyNum":1,"payMode":"0","totalPrice":"%s","username":"%s","appKey":"apple","source":41,"version":"1.10","orderSource":41}'
% (self.sku_id, self.brand_id, self.face_price, username),
"client": "iPhone",
"uuid": "1731377463937218663686",
"osVersion": "16.6",
"screen": "1170.000046491623*2532.0001006126404",
# "h5st": "20241112141707038;l055lflh9lr1i4k8;8e94a;tk03w92d21bda18nCxAp7H5xKn6xhgPjl2DU239CUZMhS1OwR9VyMZc5hQGRyFwDwYV8pE9DyQ7wpjquSVNSz5Kj3B5v;8effdf684f396d5889d2bde7e769f965;4.9;1731392227038;pjbMhjpdAaYR6jkQyLlQF6Ve2roQJrJdJrESJrpjh7Jf6rJdJz1TIipjLDrgJTISJSVS6PYd1jof0bFTKqIfJqoe1rYTImFf1LofzfITJrJdJrEa-OFTGOEjLrJp-jJS5ToeyT4e6nodGSld4j4TJeYe7PYS4bVT6T1fFSYTyjpjxj5PKSEQKeFjLrJp-jJf9HIg3T0UG6VRFuWeDipjxjJOJrpjh7JjxOYRhiFPyK3Z2f2XJrJdJ31QHyVT5ipjLDrgJj4f9G1WJrJdJTlPJrpjh7ZMLrJp7rJdJLYOJipjLrpjh7JjJrJdJPYOJipjLrpjh7ZeLDIj1XETJrpjLrJp-rojxjZe2iFjLrpjLDrg7rJdJbYOJipjLrpjh75e2rJdJfYOJipjLrpjh7Jf_rJdJjYOJipjLrpjh7Jj2zZf9rIjLDIj6XETJrpjLrJp-rojxj5R0ipjLrpjh7pfLDIj46FjLrpjLDrg7rJdJ7FjLrpjLDrg7rJdJb1OJrpjLrJpwqJdJbFQGakNGipjLDrguqpjhjZVl6VS5C2OqmHXi_1UHCFjLDIj6rEjLrpjLD7NLDIj7qEjLrJp-jpVLf2YLfVTeqZSAGlQLT4U1nojYunjGy1QDqWRLXmXoq5dGy1QDqWRJrJdJnVO4ipjLD7N;204790ef3f0380d87102b52131fd50d7",
"x-api-eid-token": "jdd03MOMPSVKGBFF6WCM3KNQK34LGPGSCNKB2WACDOVKFUNXQWAWDEVXSHMGQEQLJ6EUKKXZ7ARQA4CPF6EMRRUP5P7ETLEAAAAMTDYRX6SIAAAAACB66T3PYQZLCEEX",
}
if self.recharge_type == 2:
data = {
"appid": "tsw-m",
"functionId": "submitGPOrder",
"t": f"{self.time_stamp}",
"body": '{"skuId":"%s","brandId":"%s","type":2,"buyNum":1,"payMode":"0","totalPrice":"%s","gamesrv":"%s","gamearea":"%s","username":"%s","appKey":"apple","source":41,"version":"1.10","orderSource":41}'
% (
self.sku_id,
self.brand_id,
self.face_price,
self.game_srv,
self.game_area,
username,
),
"client": "iPhone",
"uuid": "1731377463937218663686",
"osVersion": "16.6",
"screen": "1170.000046491623*2532.0001006126404",
# "h5st": "20241112172954252;l055lflh9lr1i4k8;8e94a;tk03w92d21bda18nCxAp7H5xKn6xhgPjl2DU239CUZMhS1OwR9VyMZc5hQGRyFwDwYV8pE9DyQ7wpjquSVNSz5Kj3B5v;dcf2dab0edd6fadd62550cc4ca5e28c4;4.9;1731403794252;pjbMhjpdAaYR6jkQyLlQF6Ve2roQJrJdJrESJrpjh7Jf6rJdJz1TIipjLDrgJTISJSVS6PYd1jof0bFTKqIfJqoe1rYTImFf1LofzfITJrJdJrEa-OFTGOEjLrJp-jJS5ToeyT4e6nodGSld4j4TJeYe7PYS4bVT6T1fFSYTyjpjxj5PKSEQKeFjLrJp-jJf9HIg3T0UG6VRFuWeDipjxjJOJrpjh7JjWW1f5LnageHNqSEOJrJdJ31QHyVT5ipjLDrgJj4f9G1WJrJdJTlPJrpjh7ZMLrJp7rJdJLYOJipjLrpjh7JjJrJdJPYOJipjLrpjh7ZeLDIj1XETJrpjLrJp-rojxjZe2iFjLrpjLDrg7rJdJbYOJipjLrpjh75e2rJdJfYOJipjLrpjh7Jf_rJdJjYOJipjLrpjh7Jj2zZf9rIjLDIj6XETJrpjLrJp-rojxj5R0ipjLrpjh7pfLDIj46FjLrpjLDrg7rJdJ7FjLrpjLDrg7rJdJb1OJrpjLrJpwqJdJbFQGakNGipjLDrguqpjhjZVl6VS5C2OqmHXi_1UHCFjLDIj6rEjLrpjLD7NLDIj7qEjLrJp-jpVLf2YLfVTeqZSAGlQLT4U1nojYunjGy1QDqWRLXmXoq5dGy1QDqWRJrJdJnVO4ipjLD7N;651ee3204b43d0d514092fa61f5629f1",
"x-api-eid-token": "jdd03MOMPSVKGBFF6WCM3KNQK34LGPGSCNKB2WACDOVKFUNXQWAWDEVXSHMGQEQLJ6EUKKXZ7ARQA4CPF6EMRRUP5P7ETLEAAAAMTD6ZVZVQAAAAADSCNVUR4IR7W54X",
}
response = requests.post(self.jd_api, headers=headers, data=data)
return response.json()
def run(self):
# 提交预付款订单
gp_order_res = self.submit_gp_order()
# gp_order_res = {'result': {'orderId': 304636667875, 'paySuccessUrl': ''}, 'code': '0'}
logger.info(
f"订单号:{self.order_num},商品下单提交预付款订单返回:{gp_order_res}"
)
if gp_order_res.get("code") != "0":
return 110, gp_order_res
order_id = gp_order_res["result"]["orderId"]
# 获取支付信息
pay_res_ = self.get_pay_res(order_id)
logger.info(f"订单号:{self.order_num},商品下单获取支付信息返回:{pay_res_}")
if pay_res_.get("code") != "0":
return 110, pay_res_
pay_id = pay_res_["body"]["payId"]
# 获取微信支付信息
pay_channel_res = self.plat_pay_channel_res(pay_id)
logger.info(
f"订单号:{self.order_num},商品下单请求微信渠道返回:{pay_channel_res}"
)
if pay_channel_res.get("code") != "0":
return 110, pay_channel_res
wx_pay_res = self.plat_wx_pay_res(pay_id)
logger.info(
f"订单号:{self.order_num},商品下单获取微信支付信息返回:{wx_pay_res}"
)
if wx_pay_res.get("code") != "0":
return 110, wx_pay_res
if wx_pay_res.get("errorCode") == "-1":
wx_pay_res["order_id"] = order_id
wx_pay_res["pay_id"] = pay_id
wx_pay_res["face_price"] = self.face_price
return 110, wx_pay_res
mweb_url = wx_pay_res["payInfo"]["mweb_url"]
# 获取支付链接信息
deep_link_res = self.get_deep_link_res(mweb_url)
logger.info(
f"订单号:{self.order_num}商品下单获取支付链接deep_link信息返回{deep_link_res}"
)
if deep_link_res.get("retcode") != 1:
return 110, deep_link_res
return 100, {
"deeplink": deep_link_res["deeplink"],
"order_id": pay_channel_res["orderId"],
"pay_id": pay_id,
"face_price": self.face_price,
}