All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 6m37s
新增苹果IAP相关接口与逻辑,包括产品列表查询、交易绑定、状态查询和恢复购买功能。移除旧的IAP验证逻辑,重构订阅系统以支持苹果IAP交易记录存储和权益计算。 - 新增/pkg/iap/apple包处理JWS解析和产品映射 - 实现GET /products、POST /attach、POST /restore和GET /status接口 - 新增apple_iap_transactions表存储交易记录 - 更新文档说明配置方式和接口规范 - 移除旧的AppleIAP验证和通知处理逻辑
40 lines
922 B
Go
40 lines
922 B
Go
package apple
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type ProductMapping struct {
|
|
DurationDays int64 `json:"durationDays"`
|
|
Tier string `json:"tier"`
|
|
Description string `json:"description"`
|
|
PriceText string `json:"priceText"`
|
|
SubscribeId int64 `json:"subscribeId"`
|
|
}
|
|
|
|
type ProductMap struct {
|
|
Items map[string]ProductMapping `json:"iapProductMap"`
|
|
}
|
|
|
|
func ParseProductMap(customData string) (*ProductMap, error) {
|
|
if customData == "" {
|
|
return &ProductMap{Items: map[string]ProductMapping{}}, nil
|
|
}
|
|
var obj ProductMap
|
|
if err := json.Unmarshal([]byte(customData), &obj); err != nil {
|
|
return &ProductMap{Items: map[string]ProductMapping{}}, nil
|
|
}
|
|
if obj.Items == nil {
|
|
obj.Items = map[string]ProductMapping{}
|
|
}
|
|
return &obj, nil
|
|
}
|
|
|
|
func CalcExpire(start time.Time, days int64) time.Time {
|
|
if days <= 0 {
|
|
return time.UnixMilli(0)
|
|
}
|
|
return start.Add(time.Duration(days) * 24 * time.Hour)
|
|
}
|