data 透传闭环:发货数据回显、回调带回,并限制 2KB
- 「查询发货数据」响应新增 data(下单透传原样回显,供自建发货页预填/展示) - 回调 payload 带回 data(下单传 → 回调收,商户对接免回查) - 创建订单 data 限制最长 2048 字节 - 文档更新:data 用途(自建页预填/回调/上游查单约定字段)、发货数据与回调示例 - 单测覆盖 data 回显
This commit is contained in:
@@ -58,6 +58,11 @@ func (h *OpenV1Handler) CreateOrder(c *gin.Context) {
|
||||
}
|
||||
var data interface{}
|
||||
if len(req.Data) > 0 {
|
||||
if len(req.Data) > 2048 {
|
||||
openlog.Warn(c, "create_order data_too_large size=%d", len(req.Data))
|
||||
response.BadRequest(c, "data 最长 2048 字节")
|
||||
return
|
||||
}
|
||||
var decoded interface{}
|
||||
if err := json.Unmarshal(req.Data, &decoded); err != nil {
|
||||
openlog.Warn(c, "create_order bad_data err=%v", err)
|
||||
|
||||
@@ -113,6 +113,7 @@ type DeliveryOrderInfo struct {
|
||||
GameUID string `json:"game_uid,omitempty"`
|
||||
RoleName string `json:"role_name,omitempty"`
|
||||
PayScore int `json:"pay_score,omitempty"`
|
||||
Data map[string]interface{} `json:"data,omitempty"`
|
||||
Good map[string]interface{} `json:"good,omitempty"`
|
||||
}
|
||||
|
||||
@@ -558,6 +559,7 @@ func (s *DeliveryService) buildDeliveryState(openOrder *OpenOrderQuery, order *m
|
||||
GameUID: openOrder.GameUID,
|
||||
RoleName: openOrder.RoleName,
|
||||
PayScore: openOrder.PayScore,
|
||||
Data: requestDataMap(order.RequestData),
|
||||
Good: good,
|
||||
}
|
||||
return info, order, goodID, nil
|
||||
@@ -767,6 +769,7 @@ func (s *DeliveryService) prepareOrder(orderNo string, requireCanShip bool, auth
|
||||
GameUID: openOrder.GameUID,
|
||||
RoleName: openOrder.RoleName,
|
||||
PayScore: openOrder.PayScore,
|
||||
Data: requestDataMap(order.RequestData),
|
||||
Good: good,
|
||||
}
|
||||
return info, order, goodID, nil
|
||||
|
||||
@@ -221,6 +221,10 @@ func TestDeliveryMerchantApiBindAndSubmit(t *testing.T) {
|
||||
APIClientID: 1,
|
||||
ClientOrderNo: "delivery-api-001",
|
||||
SKU: "suit_alan_walker",
|
||||
RequestData: map[string]interface{}{
|
||||
"game_account": "4808146277",
|
||||
"game_channel": "ios-wechat",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create order: %v", err)
|
||||
@@ -234,6 +238,9 @@ func TestDeliveryMerchantApiBindAndSubmit(t *testing.T) {
|
||||
if !info.CanShip || info.Product == nil || info.Product.Image == "" {
|
||||
t.Fatalf("merchant order should include delivery data: %+v", info)
|
||||
}
|
||||
if info.Data["game_account"] != "4808146277" || info.Data["game_channel"] != "ios-wechat" {
|
||||
t.Fatalf("delivery order should echo request data: %+v", info.Data)
|
||||
}
|
||||
|
||||
bind, err := deliverySvc.BindForMerchant(merchantID, created.Order.OrderNo, "4808146277")
|
||||
if err != nil {
|
||||
|
||||
@@ -772,7 +772,7 @@ func CanFulfill(order *model.FulfillmentOrder) (bool, string) {
|
||||
|
||||
func orderCallbackData(order *model.FulfillmentOrder) map[string]interface{} {
|
||||
canShip, cannotShipReason := CanFulfill(order)
|
||||
return map[string]interface{}{
|
||||
data := map[string]interface{}{
|
||||
"order_no": order.OrderNo,
|
||||
"client_order_no": order.ClientOrderNo,
|
||||
"product_sku": order.ProductSKU,
|
||||
@@ -788,6 +788,10 @@ func orderCallbackData(order *model.FulfillmentOrder) map[string]interface{} {
|
||||
"provider_order_no": order.ProviderOrderNo,
|
||||
"failure_reason": order.FailureReason,
|
||||
}
|
||||
if requestData := requestDataMap(order.RequestData); len(requestData) > 0 {
|
||||
data["data"] = requestData
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// ----- 仪表盘统计 -----
|
||||
@@ -1309,6 +1313,15 @@ func resultDataMap(raw string) map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
// requestDataMap 解析下单透传的 data(RequestData),非法或为空时返回空 map。
|
||||
func requestDataMap(raw string) map[string]interface{} {
|
||||
m := map[string]interface{}{}
|
||||
if raw != "" && json.Valid([]byte(raw)) {
|
||||
_ = json.Unmarshal([]byte(raw), &m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func resultDataString(raw, key string) string {
|
||||
if v, ok := resultDataMap(raw)[key].(string); ok {
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user