fix: Native展示码改用HTTPS中转+手动点支付,绕开相册拦付款码
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
be42721fe6
commit
46763493f9
2 files changed
+37
-26
No files matched your search
@@ -25,20 +25,31 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
CACHE_KEY_PREFIX = 'wx_native_code_'
|
||||
CACHE_TTL_SECONDS = 60 * 30
|
||||
# 展示用二维码用 HTTPS(相册可识别);复制/点支付仍用官方 weixin:// code_url
|
||||
BRIDGE_URL_BASE = 'https://www.abas.asia/hqhd/dingdan/wx-native-pay/'
|
||||
|
||||
|
||||
def _cache_key(dingdanid: str) -> str:
|
||||
return f'{CACHE_KEY_PREFIX}{dingdanid}'
|
||||
|
||||
|
||||
def _native_pay_response(code_url: str) -> dict:
|
||||
"""二维码必须直接编码官方 code_url(weixin://wxpay/bizpayurl?...),
|
||||
微信扫后才能直接弹出付款密码;禁止再套 HTTPS 中转页。
|
||||
def build_native_bridge_url(dingdanid: str) -> str:
|
||||
from urllib.parse import quote
|
||||
return f'{BRIDGE_URL_BASE}?out_trade_no={quote(dingdanid, safe="")}'
|
||||
|
||||
|
||||
def _native_pay_response(dingdanid: str, code_url: str) -> dict:
|
||||
"""双轨:
|
||||
- qr_image:HTTPS 中转页(绕开「相册不支持识别付款码」)
|
||||
- qr_code:官方 weixin://(复制链接 / 中转页「立即支付」按钮)
|
||||
微信规定:扫一扫从相册识别 weixin://wxpay 付款码会被安全拦截,无商户可关。
|
||||
"""
|
||||
from jituan.services.alipay_pay import qr_link_to_base64
|
||||
bridge = build_native_bridge_url(dingdanid)
|
||||
return {
|
||||
'qr_code': code_url,
|
||||
'qr_image': qr_link_to_base64(code_url),
|
||||
'qr_image': qr_link_to_base64(bridge),
|
||||
'bridge_url': bridge,
|
||||
'pay_method': PAY_METHOD_WECHAT_NATIVE,
|
||||
}
|
||||
|
||||
@@ -73,7 +84,7 @@ def generate_wechat_native_pay_params(
|
||||
'[WX_NATIVE] reuse code_url dingdan=%s club=%s scene=%s',
|
||||
dingdanid, club_id, scene,
|
||||
)
|
||||
return _native_pay_response(cached_url)
|
||||
return _native_pay_response(dingdanid, cached_url)
|
||||
|
||||
pay_cfg = get_wechat_v2_config(club_id)
|
||||
log_wechat_v2_pay_diag(
|
||||
@@ -137,4 +148,4 @@ def generate_wechat_native_pay_params(
|
||||
'[WX_NATIVE] unifiedorder ok dingdan=%s club=%s mch=%s scene=%s',
|
||||
dingdanid, pay_cfg.get('club_id'), mch_id, scene,
|
||||
)
|
||||
return _native_pay_response(code_url)
|
||||
return _native_pay_response(dingdanid, code_url)
|
||||
@@ -6,31 +6,31 @@
|
||||
<title>微信支付</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f5f5f5; }
|
||||
.container { max-width: 420px; margin: 0 auto; padding: 48px 20px; text-align: center; }
|
||||
.icon { width: 72px; height: 72px; margin: 0 auto 20px; border: 4px solid #ddd; border-top-color: #07c160; border-radius: 50%; animation: spin 1s linear infinite; }
|
||||
.title { font-size: 18px; color: #333; margin-bottom: 12px; }
|
||||
.subtitle { font-size: 14px; color: #999; margin-bottom: 28px; line-height: 1.5; }
|
||||
.btn { display: inline-block; width: 100%; padding: 14px; font-size: 16px; border: none; border-radius: 8px; background: #07c160; color: #fff; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f7f7f7; }
|
||||
.wrap { max-width: 420px; margin: 0 auto; padding: 56px 24px; text-align: center; }
|
||||
.logo { width: 64px; height: 64px; margin: 0 auto 20px; border-radius: 14px; background: #07c160; color: #fff; font-size: 34px; line-height: 64px; font-weight: 700; }
|
||||
.title { font-size: 20px; font-weight: 600; color: #111; margin-bottom: 10px; }
|
||||
.sub { font-size: 14px; color: #888; line-height: 1.6; margin-bottom: 36px; }
|
||||
.btn {
|
||||
display: block; width: 100%; padding: 16px; font-size: 17px; font-weight: 600;
|
||||
border: none; border-radius: 10px; background: #07c160; color: #fff; text-decoration: none;
|
||||
}
|
||||
.btn:active { opacity: 0.9; }
|
||||
.hint { margin-top: 20px; font-size: 13px; color: #aaa; line-height: 1.5; }
|
||||
.err .title { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="wrap {% if not code_url %}err{% endif %}">
|
||||
{% if code_url %}
|
||||
<div class="icon"></div>
|
||||
<div class="title">正在打开微信支付...</div>
|
||||
<div class="subtitle">若未自动跳转,请点击下方按钮</div>
|
||||
<a class="btn" id="payBtn" href="{{ code_url }}">立即支付</a>
|
||||
<script>
|
||||
(function () {
|
||||
var url = '{{ code_url|escapejs }}';
|
||||
setTimeout(function () { window.location.href = url; }, 80);
|
||||
})();
|
||||
</script>
|
||||
<div class="logo">微</div>
|
||||
<div class="title">微信支付</div>
|
||||
<div class="sub">请点击下方按钮完成支付<br>点击后将调起付款密码</div>
|
||||
<a class="btn" href="{{ code_url }}">立即支付</a>
|
||||
<div class="hint">若点击无反应,请返回小程序使用「复制支付链接」</div>
|
||||
{% else %}
|
||||
<div class="title">支付链接无效或已过期</div>
|
||||
<div class="subtitle">请返回小程序重新发起支付</div>
|
||||
<div class="title">支付已失效</div>
|
||||
<div class="sub">链接无效或已过期,请返回小程序重新发起支付</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user