feat(iap): 移除苹果IAP商品列表接口并添加接入指南文档
Build docker and publish / build (20.15.1) (push) Successful in 6m44s
Build docker and publish / build (20.15.1) (push) Successful in 6m44s
移除不再使用的苹果IAP商品列表相关代码,包括handler、logic和测试文件 新增详细的iOS内购接入指南文档,包含StoreKit2使用流程和接口规范
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package apple
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
appleLogic "github.com/perfect-panel/server/internal/logic/public/iap/apple"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
func GetAppleProductsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
l := appleLogic.NewGetProductsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetProducts()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package apple
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/config"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
)
|
||||
|
||||
// TestGetAppleProductsHandler 用于验证产品列表接口
|
||||
// 参数:无
|
||||
// 返回:无;断言接口返回的产品数量与字段正确性
|
||||
func TestGetAppleProductsHandler(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
cd := `{
|
||||
"iapProductMap": {
|
||||
"com.airport.vpn.pass.30d": {
|
||||
"description": "30天通行证",
|
||||
"priceText": "¥28.00",
|
||||
"durationDays": 30,
|
||||
"tier": "Basic",
|
||||
"subscribeId": 1001
|
||||
},
|
||||
"com.airport.vpn.pass.90d": {
|
||||
"description": "90天通行证",
|
||||
"priceText": "¥68.00",
|
||||
"durationDays": 90,
|
||||
"tier": "Pro",
|
||||
"subscribeId": 1002
|
||||
}
|
||||
},
|
||||
"iapBundleId": "co.airoport.app.ios"
|
||||
}`
|
||||
s := &svc.ServiceContext{
|
||||
Config: config.Config{
|
||||
Site: config.SiteConfig{
|
||||
CustomData: cd,
|
||||
},
|
||||
},
|
||||
}
|
||||
r := gin.New()
|
||||
r.GET("/v1/public/iap/apple/products", GetAppleProductsHandler(s))
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest(http.MethodGet, "/v1/public/iap/apple/products", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status != 200, got %d", w.Code)
|
||||
}
|
||||
type wrap struct {
|
||||
Code uint32 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data types.GetAppleProductsResponse `json:"data"`
|
||||
}
|
||||
var resp wrap
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("unmarshal error: %v", err)
|
||||
}
|
||||
if resp.Code != 200 {
|
||||
t.Fatalf("code != 200, got %d", resp.Code)
|
||||
}
|
||||
if len(resp.Data.List) != 2 {
|
||||
t.Fatalf("expect 2 products, got %d", len(resp.Data.List))
|
||||
}
|
||||
if resp.Data.List[0].ProductId == "" || resp.Data.List[0].DurationDays == 0 || resp.Data.List[0].SubscribeId == 0 {
|
||||
t.Fatalf("invalid fields in product item")
|
||||
}
|
||||
}
|
||||
@@ -723,7 +723,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
iapAppleGroupRouter := router.Group("/v1/public/iap/apple")
|
||||
iapAppleGroupRouter.Use(middleware.AuthMiddleware(serverCtx), middleware.DeviceMiddleware(serverCtx))
|
||||
{
|
||||
iapAppleGroupRouter.GET("/products", publicIapApple.GetAppleProductsHandler(serverCtx))
|
||||
iapAppleGroupRouter.GET("/status", publicIapApple.GetAppleStatusHandler(serverCtx))
|
||||
iapAppleGroupRouter.POST("/transactions/attach", publicIapApple.AttachAppleTransactionHandler(serverCtx))
|
||||
iapAppleGroupRouter.POST("/restore", publicIapApple.RestoreAppleTransactionsHandler(serverCtx))
|
||||
|
||||
Reference in New Issue
Block a user