feat:商户只有1个支付方式时,收银台返回盖方式不校验环境,自动唤起支付页面增加按钮点击唤起
This commit is contained in:
parent
e043564e96
commit
b91923c44f
|
|
@ -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{}
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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; }
|
||||||
|
.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>
|
||||||
<script>
|
const payLink = "{{.payUrl}}";
|
||||||
// 网页默认跳转url
|
const btn = document.getElementById('triggerPay');
|
||||||
window.location.href = "{{.payUrl}}";
|
// 荣耀机型必须靠点击事件才能绕过系统拦截
|
||||||
</script>
|
btn.onclick = function(){
|
||||||
{{else}}
|
window.location.href = payLink;
|
||||||
<script>
|
}
|
||||||
alert("{{.code}}" + "{{.message}}");
|
// DOM加载完成后延时自动跳转(仅作兜底,荣耀大概率拦截,按钮是核心方案)
|
||||||
</script>
|
window.onload = function(){
|
||||||
{{end}}
|
setTimeout(()=>{
|
||||||
</html>
|
window.location.href = payLink;
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{{else}}
|
||||||
|
<script>
|
||||||
|
alert("支付失败:{{.code}} {{.message}}");
|
||||||
|
history.back();
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue