Initial restarted commit
This commit is contained in:
62
ChargeTicket.py
Normal file
62
ChargeTicket.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# 倍票相关 API 的实现
|
||||
import json
|
||||
import pytz
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from Static_Settings import *
|
||||
from API_TitleServer import apiSDGB
|
||||
from HelperGetUserThing import apiGetUserData
|
||||
|
||||
def apiQueryTicket(userId:int) -> str:
|
||||
'''查询已有票的 API 请求器,返回 Json String。'''
|
||||
# 构建 Payload
|
||||
data = json.dumps({
|
||||
"userId": userId
|
||||
})
|
||||
# 发送请求
|
||||
userdata_result = apiSDGB(data, "GetUserChargeApi", userId)
|
||||
# 返回响应
|
||||
return userdata_result
|
||||
|
||||
def apiBuyTicket(userId:int, ticketType:int, price:int, playerRating:int, playCount:int) -> str:
|
||||
'''倍票购买 API 的请求器'''
|
||||
# 构造请求数据 Payload
|
||||
data = json.dumps({
|
||||
"userId": userId,
|
||||
"userCharge": {
|
||||
"chargeId": ticketType,
|
||||
"stock": 1,
|
||||
"purchaseDate": (datetime.now(pytz.timezone('Asia/Shanghai')) - timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S.0"),
|
||||
"validDate": (datetime.now(pytz.timezone('Asia/Shanghai')) - timedelta(hours=1) + timedelta(days=90)).replace(hour=4, minute=0, second=0).strftime("%Y-%m-%d %H:%M:%S")
|
||||
},
|
||||
"userChargelog": {
|
||||
"chargeId": ticketType,
|
||||
"price": price,
|
||||
"purchaseDate": (datetime.now(pytz.timezone('Asia/Shanghai')) - timedelta(hours=1)).strftime("%Y-%m-%d %H:%M:%S.0"),
|
||||
"playcount": playCount,
|
||||
"playerRating": playerRating,
|
||||
"placeId": placeId,
|
||||
"regionId": regionId,
|
||||
"clientId": clientId
|
||||
}
|
||||
})
|
||||
# 发送请求,返回最终得到的 Json String 回执
|
||||
return apiSDGB(data, "UpsertUserChargelogApi", userId)
|
||||
|
||||
def implBuyTicket(userId:int, ticketType:int) -> str:
|
||||
'''
|
||||
购买倍票 API 的参考实现。
|
||||
需要事先登录.
|
||||
返回服务器响应的 Json string。
|
||||
'''
|
||||
# 先使用 GetUserData API 请求器,取得 rating 和 pc 数
|
||||
currentUserData = json.loads(apiGetUserData(userId))
|
||||
if currentUserData:
|
||||
playerRating = currentUserData['userData']['playerRating']
|
||||
playCount = currentUserData['userData'].get('playCount', 0)
|
||||
else:
|
||||
return False
|
||||
# 正式买票
|
||||
getTicketResponseStr = apiBuyTicket(userId, ticketType, ticketType-1, playerRating, playCount)
|
||||
# 返回结果
|
||||
return getTicketResponseStr
|
||||
Reference in New Issue
Block a user