feat:商户只有1个支付方式时,收银台返回盖方式不校验环境,自动唤起支付页面增加按钮点击唤起

This commit is contained in:
wolter 2026-06-12 16:41:26 +08:00
parent e043564e96
commit b91923c44f
4 changed files with 71 additions and 24 deletions

View File

@ -12,6 +12,7 @@ import (
"fmt" "fmt"
"github.com/ahmetb/go-linq/v3" "github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/qit-team/snow-core/log/logger"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
@ -79,6 +80,8 @@ func PayPage(c *gin.Context) {
func PayChannelList(c *gin.Context) { func PayChannelList(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*front.PayChannelListRequest) req, _ := controllers.GetRequest(c).(*front.PayChannelListRequest)
req.UserAgent = c.Request.UserAgent() req.UserAgent = c.Request.UserAgent()
logger.Info(c, "PayChannelList", fmt.Sprintf("req.OrderId: %s, req.UserAgent: %s", req.OrderId, req.UserAgent))
data, code := services.PayPageChannelList(*req) data, code := services.PayPageChannelList(*req)
result := []front.PayChannelListResponse{} result := []front.PayChannelListResponse{}

View File

@ -48,6 +48,13 @@ func PayPageChannelList(reqParam front.PayChannelListRequest) (resultPayChannelL
code = errorcode.PayChannelNotFound code = errorcode.PayChannelNotFound
return return
} }
// 兜底只有1中支付方式默认返回该支付方式不校验支付环境
if len(payList) == 1 {
resultPayChannelList = payList
return
}
merchantPayChannelMap := make(map[int]paychannelmodel.PayChannel, 0) merchantPayChannelMap := make(map[int]paychannelmodel.PayChannel, 0)
for _, pay := range payList { for _, pay := range payList {
if !pay.ExpireTime.IsZero() && pay.ExpireTime.Unix() < time.Now().Unix() { if !pay.ExpireTime.IsZero() && pay.ExpireTime.Unix() < time.Now().Unix() {

View File

@ -265,7 +265,7 @@
<script> <script>
// 支付页面模块化实现 // 支付页面模块化实现
const API_BASE_URL = 'https://pay.cdlsxd.cn'; const API_BASE_URL = '';
// ========== 配置模块 ========== // ========== 配置模块 ==========
const CONFIG = { const CONFIG = {
API: { API: {
@ -499,8 +499,18 @@
// 处理支付方式数据 // 处理支付方式数据
processPaymentMethods(data, id) { processPaymentMethods(data, id) {
// 处理返回的数据,例如渲染支付方式列表 // 先关闭loading再展示内容确保异常/正常都能让用户看到
if (data === null || data.data.length === 0) { Utils.closeLoading();
// 兼容 data.data 可能为 null / [] / {} 等多种情况
const isEmpty =
data === null ||
data.data === null ||
data.data === undefined ||
(Array.isArray(data.data) && data.data.length === 0) ||
(!Array.isArray(data.data) &&
typeof data.data === "object" &&
Object.keys(data.data).length === 0);
if (isEmpty) {
const pay = document.getElementById("pay"); const pay = document.getElementById("pay");
pay.innerHTML = "<h3>支付环境异常,请检查</h3>"; pay.innerHTML = "<h3>支付环境异常,请检查</h3>";
} else if (data.data.length === 1) { } else if (data.data.length === 1) {

View File

@ -1,23 +1,50 @@
{{ define "payTemplateDefault.html"}} {{ define "payTemplateDefault.html"}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
{{/* <title>Title</title>*/}} <!-- 修复荣耀UA识别关键标签 -->
</head> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
<body> <title>支付</title>
</body> <style>
body { padding: 50px 20px; margin:0; font-family: system-ui; text-align: center; }
{{ if eq .code 200}} .desc { font-size:14px; color:#555; margin-bottom:40px; }
<script> .wx-pay-btn {
// 网页默认跳转url width: 90%;
window.location.href = "{{.payUrl}}"; padding:14px 0;
</script> background:#07C160;
{{else}} color:#fff;
<script> border:none;
alert("{{.code}}" + "{{.message}}"); border-radius:8px;
</script> font-size:17px;
{{end}} }
</html> </style>
{{ end }} </head>
<body>
{{ if eq .code 200}}
<div class="desc">正在尝试自动唤起支付<br>若未跳转,请点击下方按钮</div>
<button class="wx-pay-btn" id="triggerPay">打开支付</button>
<script>
const payLink = "{{.payUrl}}";
const btn = document.getElementById('triggerPay');
// 荣耀机型必须靠点击事件才能绕过系统拦截
btn.onclick = function(){
window.location.href = payLink;
}
// DOM加载完成后延时自动跳转仅作兜底荣耀大概率拦截按钮是核心方案
window.onload = function(){
setTimeout(()=>{
window.location.href = payLink;
}, 500);
}
</script>
{{else}}
<script>
alert("支付失败:{{.code}} {{.message}}");
history.back();
</script>
{{end}}
</body>
</html>
{{ end }}