feat: 购买下单透传终端类型,手机端收银台拉起支付宝 App(契约 v1.1.0)

根因:pay 判手机/PC 用下单请求 UA,而下单由 jiu 后端 Go client 发出,
恒被判 PC 扫码页——手机用户拿不到 wap 拉起页。

- backend:/license/purchase 请求体加可选 client_type(oneof=pc mobile),
  缺省按本请求 UA 兜底(官网浏览器购买自动受益);CreatePurchase 透传给 pay;
  单测断言透传 + 既有用例补参
- client:createPurchase 支持 clientType;PurchaseCard 按平台声明
  (iOS/Android=mobile,桌面=pc,Web 不传走 UA),kIsWeb 先于 dart:io;
  launchUrl 外部浏览器不变,wap 收银台自动拉起支付宝
- 配套:pay-contract v1.1.0(744725b)+ pay 侧 resolveIsMobile(dbdadd1)已各自提交

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
wangjia
2026-07-04 10:31:49 +08:00
parent aa3aad417c
commit f3cfdcadca
5 changed files with 64 additions and 15 deletions
+10 -3
View File
@@ -90,7 +90,10 @@ type PurchaseResult struct {
}
// CreatePurchase 建购买记录并调 pay 下单,返回收银台跳转 URL。
func (s *PayService) CreatePurchase(shopID, userID uint64, bizCode string) (*PurchaseResult, error) {
// clientType(契约 v1.1.0"pc"/"mobile"/""):显式端型透传给 pay 决定收银台形态
// (mobile=手机网站支付拉起支付宝 App / pc=电脑扫码页);服务端间调用下单请求 UA
// 是本后端的,不传则 pay 会按 Go client UA 误判为 PC。
func (s *PayService) CreatePurchase(shopID, userID uint64, bizCode, clientType string) (*PurchaseResult, error) {
if !s.Configured() {
return nil, ErrPayNotConfigured
}
@@ -117,12 +120,16 @@ func (s *PayService) CreatePurchase(shopID, userID uint64, bizCode string) (*Pur
return nil, err
}
reqBody, _ := json.Marshal(map[string]any{
payload := map[string]any{
"product_id": productID,
"biz_system": "jiu",
"biz_ref": strconv.FormatUint(p.ID, 10),
"return_url": s.retURL,
})
}
if clientType != "" {
payload["client_type"] = clientType
}
reqBody, _ := json.Marshal(payload)
respBody, err := s.signedPost("/api/v1/orders", reqBody)
if err != nil {
return nil, fmt.Errorf("pay 下单失败: %w", err)