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验证和通知处理逻辑
36 lines
907 B
Go
36 lines
907 B
Go
package apple
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParseTransactionJWS(t *testing.T) {
|
|
payload := map[string]interface{}{
|
|
"bundleId": "co.airoport.app.ios",
|
|
"productId": "com.airport.vpn.pass.30d",
|
|
"transactionId": "1000000000001",
|
|
"originalTransactionId": "1000000000000",
|
|
"purchaseDate": float64(time.Now().UnixMilli()),
|
|
}
|
|
data, _ := json.Marshal(payload)
|
|
b64 := base64.RawURLEncoding.EncodeToString(data)
|
|
jws := "header." + b64 + ".signature"
|
|
p, err := ParseTransactionJWS(jws)
|
|
if err != nil {
|
|
t.Fatalf("parse error: %v", err)
|
|
}
|
|
if p.ProductId != payload["productId"] {
|
|
t.Fatalf("productId not match")
|
|
}
|
|
if p.BundleId != payload["bundleId"] {
|
|
t.Fatalf("bundleId not match")
|
|
}
|
|
if p.OriginalTransactionId != payload["originalTransactionId"] {
|
|
t.Fatalf("originalTransactionId not match")
|
|
}
|
|
}
|
|
|