feat:商户只有1个支付方式时,收银台返回盖方式不校验环境,自动唤起支付页面增加按钮点击唤起
This commit is contained in:
parent
e043564e96
commit
b91923c44f
|
|
@ -12,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/qit-team/snow-core/log/logger"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -79,6 +80,8 @@ func PayPage(c *gin.Context) {
|
|||
func PayChannelList(c *gin.Context) {
|
||||
req, _ := controllers.GetRequest(c).(*front.PayChannelListRequest)
|
||||
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)
|
||||
|
||||
result := []front.PayChannelListResponse{}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,13 @@ func PayPageChannelList(reqParam front.PayChannelListRequest) (resultPayChannelL
|
|||
code = errorcode.PayChannelNotFound
|
||||
return
|
||||
}
|
||||
|
||||
// 兜底只有1中支付方式,默认返回该支付方式,不校验支付环境
|
||||
if len(payList) == 1 {
|
||||
resultPayChannelList = payList
|
||||
return
|
||||
}
|
||||
|
||||
merchantPayChannelMap := make(map[int]paychannelmodel.PayChannel, 0)
|
||||
for _, pay := range payList {
|
||||
if !pay.ExpireTime.IsZero() && pay.ExpireTime.Unix() < time.Now().Unix() {
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@
|
|||
|
||||
<script>
|
||||
// 支付页面模块化实现
|
||||
const API_BASE_URL = 'https://pay.cdlsxd.cn';
|
||||
const API_BASE_URL = '';
|
||||
// ========== 配置模块 ==========
|
||||
const CONFIG = {
|
||||
API: {
|
||||
|
|
@ -499,8 +499,18 @@
|
|||
|
||||
// 处理支付方式数据
|
||||
processPaymentMethods(data, id) {
|
||||
// 处理返回的数据,例如渲染支付方式列表
|
||||
if (data === null || data.data.length === 0) {
|
||||
// 先关闭loading,再展示内容,确保异常/正常都能让用户看到
|
||||
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");
|
||||
pay.innerHTML = "<h3>支付环境异常,请检查</h3>";
|
||||
} else if (data.data.length === 1) {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,50 @@
|
|||
{{ define "payTemplateDefault.html"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
{{/* <title>Title</title>*/}}
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<!-- 修复荣耀UA识别关键标签 -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
|
||||
<title>支付</title>
|
||||
<style>
|
||||
body { padding: 50px 20px; margin:0; font-family: system-ui; text-align: center; }
|
||||
.desc { font-size:14px; color:#555; margin-bottom:40px; }
|
||||
.wx-pay-btn {
|
||||
width: 90%;
|
||||
padding:14px 0;
|
||||
background:#07C160;
|
||||
color:#fff;
|
||||
border:none;
|
||||
border-radius:8px;
|
||||
font-size:17px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{{ if eq .code 200}}
|
||||
<div class="desc">正在尝试自动唤起支付<br>若未跳转,请点击下方按钮</div>
|
||||
<button class="wx-pay-btn" id="triggerPay">打开支付</button>
|
||||
|
||||
{{ if eq .code 200}}
|
||||
<script>
|
||||
// 网页默认跳转url
|
||||
window.location.href = "{{.payUrl}}";
|
||||
</script>
|
||||
{{else}}
|
||||
<script>
|
||||
alert("{{.code}}" + "{{.message}}");
|
||||
</script>
|
||||
{{end}}
|
||||
</html>
|
||||
<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 }}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue