From 6ca240a14ccf55d4e0a94fff77e95f64db2cdfcc Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 11 十月 2024 17:34:25 +0800 Subject: [PATCH] 2024-10-11 --- src/views/pay/index.jsx | 113 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/views/pay/index.jsx b/src/views/pay/index.jsx index 788a5c5..b01f691 100644 --- a/src/views/pay/index.jsx +++ b/src/views/pay/index.jsx @@ -17,54 +17,56 @@ state = { orderId: '', orderNo: '', - appid: '', - logo: '', - name: '', - copyRight: '', - icp: '', + logo: window.GLOB.doclogo || '', + name: sessionStorage.getItem('Full_Name') || '', + copyRight: window.GLOB.copyRight || '', + icp: window.GLOB.ICP || '', total: '', unit: '', qrcode: '', second: 60, overdue: false, - overdone: false + overdone: false, + appId: '', + merchId: '' } UNSAFE_componentWillMount () { - let _urlparam = window.decodeURIComponent(window.atob(this.props.match.params.param)) - let _params = {} - _urlparam.split('&').forEach(cell => { - let _cell = cell.split('=') - _params[_cell[0]] = _cell[1] - }) + let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param))) - if (!sessionStorage.getItem('LoginUID') && _params.LoginUID) { - sessionStorage.setItem('LoginUID', _params.LoginUID) - } - if (!sessionStorage.getItem('UserID') && _params.userid) { - sessionStorage.setItem('UserID', _params.userid) - } + let appId = param.appId || window.GLOB.WXAppID || window.GLOB.WXminiAppID || '' + let merchId = param.merchId || window.GLOB.WXMerchID || '' this.setState({ - orderId: _params.ID, - logo: _params.logo, - name: _params.name, - copyRight: _params.copyRight, - icp: _params.icp + orderId: param.ID, + appId: appId, + merchId: merchId }) - if (_params.ID) { - this.getOrder(_params.ID) - } else { + if (param.ID && appId && merchId) { + this.getOrder(param.ID, appId, merchId) + } else if (!param.ID) { notification.warning({ top: 92, message: '鏈幏鍙栧埌璁㈠崟ID锛�', duration: 5 }) + } else if (!appId) { + notification.warning({ + top: 92, + message: '鏈幏鍙栧埌搴旂敤ID锛�', + duration: 5 + }) + } else if (!merchId) { + notification.warning({ + top: 92, + message: '鏈幏鍙栧埌鍟嗘埛鍙凤紒', + duration: 5 + }) } } - getOrder = (Id) => { + getOrder = (Id, appId, merchId) => { let param = { func: 's_get_weixin_pay_native', ID: Id @@ -85,7 +87,6 @@ } this.setState({ - appid: res.appid, orderNo: res.out_trade_no, total: _total, unit: res.amount && res.amount.currency === 'CNY' ? '鍏�' : '鍏�', @@ -114,19 +115,12 @@ duration: 5 }) return - } else if (!res.appid) { - notification.warning({ - top: 10, - message: '鏈幏鍙栧埌搴旂敤ID锛�', - duration: 5 - }) - return } - Api.getWxNativePay({ 'out_biz_no': res.out_trade_no, 'out_open_id': res.appid }).then(result => { - if (result.qrcode) { + Api.getWxNativePay({ 'out_biz_no': res.out_trade_no, app_id: appId, mchid: merchId }).then(result => { + if (result.status && result.code_url) { this.setState({ - qrcode: result.qrcode + qrcode: result.code_url }) setTimeout(this.resetSecond, 1000) } else { @@ -135,7 +129,7 @@ }) notification.warning({ top: 10, - message: result.msg || '鏈幏鍙栧埌鏀粯鐮侊紒', + message: result.message || '鏈幏鍙栧埌鏀粯鐮侊紒', duration: 5 }) } @@ -198,7 +192,7 @@ } resetQrcode = () => { - const { appid, orderNo } = this.state + const { orderNo, appId, merchId } = this.state if (!orderNo) { notification.warning({ @@ -207,12 +201,26 @@ duration: 5 }) return + } else if (!appId) { + notification.warning({ + top: 10, + message: '鏈幏鍙栧埌搴旂敤ID锛�', + duration: 5 + }) + return + } else if (!merchId) { + notification.warning({ + top: 10, + message: '鏈幏鍙栧埌鍟嗘埛鍙凤紒', + duration: 5 + }) + return } - Api.getWxNativePay({ 'out_biz_no': orderNo, 'out_open_id': appid }).then(result => { - if (result.qrcode) { + Api.getWxNativePay({ 'out_biz_no': orderNo, app_id: appId, mchid: merchId }).then(result => { + if (result.status && result.code_url) { this.setState({ - qrcode: result.qrcode, + qrcode: result.code_url, overdue: false, second: 60 }) @@ -220,16 +228,16 @@ } else { notification.warning({ top: 10, - message: result.msg || '鏈幏鍙栧埌鏀粯鐮侊紒', + message: result.message || '鏈幏鍙栧埌鏀粯鐮侊紒', duration: 5 }) } }) } - onChange = () => { + // onChange = () => { - } + // } render () { const { logo, name, orderNo, icp, copyRight, total, unit, qrcode, second, overdue, overdone } = this.state @@ -251,17 +259,8 @@ {!overdone ? <div className="qrcode-box"> {!overdue ? <p>璺濈浜岀淮鐮佽繃鏈熻繕鍓�<span>{second}</span>绉掞紝杩囨湡鍚庤鍒锋柊椤甸潰閲嶆柊鑾峰彇浜岀淮鐮併��</p> : null} {overdue ? <p className="overdue">浜岀淮鐮佸凡杩囨湡锛�<span onClick={this.resetQrcode}>鍒锋柊</span>椤甸潰閲嶆柊鑾峰彇浜岀淮鐮併��</p> : null} - <QRCode - value={qrcode} - size={250} - fgColor="#000000" - // imageSettings={{ - // src: '', - // height: 60, - // width: 60, - // excavate: true - // }} - /> + <QRCode value={qrcode} size={250} fgColor="#000000"/> + {!overdue && !qrcode ? <div className="qr-mask"></div> : null} {overdue ? <div className="overdue-mask"><p onClick={this.resetQrcode}>鑾峰彇澶辫触 鐐瑰嚮閲嶆柊鑾峰彇浜岀淮鐮�</p></div> : null} <div className="qrcode-tip"> <img src={WeiXinScan} alt=""/> -- Gitblit v1.8.0