feat: improve xiaodian seckill flow
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -171,14 +172,14 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
if category == "76" {
|
||||
switch offset {
|
||||
case "0":
|
||||
items = []map[string]string{{"iGoodsId": "g3", "sGoodsName": "热门商品", "iCategoryId": "76", "iPrice": "30", "iGoodsLeft": "0"}}
|
||||
items = []map[string]string{{"iGoodsId": "g3", "sGoodsName": "热门商品", "iCategoryId": "76", "iPrice": "30", "sPayType": "qpqb", "iGoodsLeft": "0"}}
|
||||
}
|
||||
} else {
|
||||
switch offset {
|
||||
case "0":
|
||||
items = []map[string]string{{"iGoodsId": "g1", "sGoodsName": "商品一", "iCategoryId": "1", "iPrice": "10", "iGoodsLeft": "-1"}, {"iGoodsId": "g2", "sGoodsName": "特惠商品", "iCategoryId": "45", "iPrice": "20", "iGoodsLeft": "3"}}
|
||||
items = []map[string]string{{"iGoodsId": "g1", "sGoodsName": "商品一", "iCategoryId": "1", "iPrice": "10", "sPayType": "qpqb", "iGoodsLeft": "-1"}, {"iGoodsId": "g2", "sGoodsName": "特惠商品", "iCategoryId": "45", "iPrice": "0", "iJb2Price": "20", "sPayType": "jb2", "iGoodsLeft": "3"}}
|
||||
case "2":
|
||||
items = []map[string]string{{"iGoodsId": "g2", "sGoodsName": "重复商品", "iCategoryId": "45", "iPrice": "20", "iGoodsLeft": "3"}, {"iGoodsId": "g4", "sGoodsName": "商品四", "iCategoryId": "1", "iPrice": "40", "iGoodsLeft": "0"}}
|
||||
items = []map[string]string{{"iGoodsId": "g2", "sGoodsName": "重复商品", "iCategoryId": "45", "iPrice": "0", "iJb2Price": "20", "sPayType": "jb2", "iGoodsLeft": "3"}, {"iGoodsId": "g4", "sGoodsName": "商品四", "iCategoryId": "1", "iPrice": "40", "sPayType": "qpqb", "iGoodsLeft": "0"}}
|
||||
}
|
||||
}
|
||||
body, _ := json.Marshal(map[string]any{"data": map[string]any{"client_data": map[string]any{"itemsdetail": items}}})
|
||||
@@ -218,6 +219,9 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
if products[1].Category != "45" || products[3].Score != 30 {
|
||||
t.Fatalf("商品字段 = %#v", products)
|
||||
}
|
||||
if products[0].PayType != 1 || products[0].PayLabel != "点券" || products[1].PayType != 5 || products[1].PayLabel != "扭蛋碎片" || products[1].Score != 20 {
|
||||
t.Fatalf("支付字段 = %#v", products)
|
||||
}
|
||||
if got := strings.Join(goodsRequests, ","); got != ":iCategoryId_76:0,:iCategoryId_76:2,:iCategoryId_76:4,76::0" {
|
||||
t.Fatalf("分类分页请求 = %s", got)
|
||||
}
|
||||
@@ -230,6 +234,72 @@ func TestProductsAutomaticallyResolvesXiaodianRoleAndPaginates(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestXiaodianExchangeProductUsesLiveBuyPayTypes(t *testing.T) {
|
||||
var requests []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/embed":
|
||||
_, _ = w.Write([]byte(`{"error":0,"data":{"txurlH5":"https://app.daoju.qq.com/act/a20260602cjmshop/index.html?gameId=cjm&actId=18882&appId=bp_cf&livePlatId=douyu&code=code×tamp=1&v=2.0&sig=sig"}}`))
|
||||
case "/daoju/igw/livebuy/":
|
||||
requests = append(requests, r.URL.RawQuery)
|
||||
if got := r.URL.Query().Get("_service"); got != "buy.plug.svr.web" {
|
||||
t.Errorf("_service = %q", got)
|
||||
}
|
||||
if got := r.URL.Query().Get("iActionId"); got != "46195" {
|
||||
t.Errorf("iActionId = %q", got)
|
||||
}
|
||||
_, _ = w.Write([]byte(`var buyInfo={"ret":"0","msg":"ok","serial":"CJM-1","sSerialNum":"CJM-1"};`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
act := &activity.Activity{
|
||||
ID: "xiaodian", DisplayName: "和平小店", RoomID: "9263298", ActAlias: "20260623KDQFH",
|
||||
ActID: "46195", RoleParamURL: server.URL + "/embed", RoleURL: server.URL + "/daoju/igw/live", IsXiaodian: true,
|
||||
}
|
||||
cli := New(act, "", &trace.Recorder{})
|
||||
cli.HTTPClient = server.Client()
|
||||
|
||||
got, err := cli.ExchangeProduct("acf_uid=uid; acf_stk=stk; acf_ltkid=ltkid", types.Product{
|
||||
CommodityID: "g-dq", Score: 8800, PayType: 1, Pic: "pic-dq",
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("点券 ExchangeProduct() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(got, "serial=CJM-1") {
|
||||
t.Fatalf("点券返回 = %q", got)
|
||||
}
|
||||
got, err = cli.ExchangeProduct("acf_uid=uid; acf_stk=stk; acf_ltkid=ltkid", types.Product{
|
||||
CommodityID: "g-jb2", Score: 108, PayType: 5, Pic: "pic-jb2",
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("碎片 ExchangeProduct() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(got, "paytype=5") {
|
||||
t.Fatalf("碎片返回 = %q", got)
|
||||
}
|
||||
if len(requests) != 2 {
|
||||
t.Fatalf("请求数量 = %d", len(requests))
|
||||
}
|
||||
first, _ := url.ParseQuery(requests[0])
|
||||
second, _ := url.ParseQuery(requests[1])
|
||||
if first.Get("paytype") != "1" || first.Get("propid") != "g-dq" {
|
||||
t.Fatalf("点券请求 = %s", requests[0])
|
||||
}
|
||||
if second.Get("paytype") != "5" || second.Get("propid") != "g-jb2" {
|
||||
t.Fatalf("碎片请求 = %s", requests[1])
|
||||
}
|
||||
var appext map[string]any
|
||||
if err := json.Unmarshal([]byte(second.Get("appext")), &appext); err != nil {
|
||||
t.Fatalf("appext 解析失败: %v", err)
|
||||
}
|
||||
if appext["user_price"].(float64) != 108 || appext["paytype"].(float64) != 5 {
|
||||
t.Fatalf("碎片 appext = %#v", appext)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXiaodianExchangeListUsesOrderListAndParsesGoods(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
|
||||
Reference in New Issue
Block a user