king
2020-07-09 89ee68c59cdcaa4b7fa0178be42d58bec651ee73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React, {Component} from 'react'
import moment from 'moment'
import md5 from 'md5'
import QRCode from 'qrcode.react'
import { notification, Radio } from 'antd'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import WeiXinPay from '@/assets/img/weixinpay.jpg'
import WeiXinScan from '@/assets/img/weixinscan.png'
import './index.scss'
 
class Pay extends Component {
  state = {
    orderId: '',
    orderNo: '',
    logo: '',
    name: '',
    copyRight: '',
    icp: '',
    total: '',
    unit: '',
    qrcode: ''
  }
 
  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]
    })
 
    if (!sessionStorage.getItem('LoginUID') && _params.LoginUID) {
      sessionStorage.setItem('LoginUID', _params.LoginUID)
    }
    if (!sessionStorage.getItem('UserID') && _params.userid) {
      sessionStorage.setItem('UserID', _params.userid)
    }
    if (!sessionStorage.getItem('SessionUid') && _params.suid) {
      sessionStorage.setItem('SessionUid', _params.suid)
    }
 
    this.setState({
      orderId: _params.ID,
      logo: _params.logo,
      name: _params.name,
      copyRight: _params.copyRight,
      icp: _params.icp
    })
 
    if (_params.ID) {
      this.getOrder(_params.ID)
    } else {
      notification.warning({
        top: 92,
        message: '未获取到订单ID!',
        duration: 5
      })
    }
  }
 
  getOrder = (Id) => {
    let param = {
      func: 's_get_weixin_pay_native',
      ID: Id,
      sandbox: 'Y'
    }
 
    param.LTextOut = md5(param.ID + window.GLOB.appkey)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
    param.secretkey = Utils.encrypt(param.LTextOut, param.timestamp)
 
    Api.getLocalConfig(param).then(res => {
      if (res.status) {
        this.setState({
          orderNo: res.out_trade_no,
          total: res.amount ? res.amount.total : '',
          unit: res.amount && res.amount.currency === 'CNY' ? '元' : '元',
        })
 
        if (!res.out_trade_no) {
          notification.warning({
            top: 10,
            message: '未获取到订单号!',
            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) {
            this.setState({
              qrcode: result.qrcode
            })
          } else {
            notification.warning({
              top: 10,
              message: result.msg || '未获取到支付码!',
              duration: 5
            })
          }
        })
      } else {
        notification.warning({
          top: 10,
          message: res.message,
          duration: 5
        })
      }
    })
  }
 
  onChange = () => {
 
  }
 
  render () {
    const { logo, name, orderNo, icp, copyRight, total, unit, qrcode } = this.state
 
    return (
      <div className="mk-pay-container">
        <div className="mk-pay-box">
          <header>
            <img className="plat-logo" src={logo} alt=""/>
            <div className="user-name">{name}</div>
          </header>
          <div className="pay-tip">
            <span>请您尽快支付,以便订单快速处理!订单号:{orderNo}</span>
            <span className="pay-total">应付金额<span>{total}</span>{unit}</span>
          </div>
          <div className="mk-pay-content">
            <div className="mk-pay-type">
              <span className="tip">支付方式:</span>
              <Radio.Group onChange={this.onChange} value="weixin">
                <Radio value="weixin">微信支付</Radio>
              </Radio.Group>
            </div>
            <div className="qrcode-box">
              <p>二维码有效时长5分钟,过期后请刷新页面重新获取二维码。</p>
              <QRCode
                value={qrcode}
                size={230}
                fgColor="#000000"
                // imageSettings={{
                //   src: '',
                //   height: 60,
                //   width: 60,
                //   excavate: true
                // }}
              />
              <div className="qrcode-tip">
                <img src={WeiXinScan} alt=""/>
                <div>
                  <p>请使用微信扫一扫</p>
                  <p>扫描二维码支付</p>
                </div>
              </div>
            </div>
            <img className="weixin-scan" src={WeiXinPay} alt=""/>
          </div>
          <div className="mk-pay-bottom">
            {copyRight ? <p dangerouslySetInnerHTML={{ __html: copyRight.replace(/\s/ig, '&nbsp;') }}></p> : null}
            {icp ? <p dangerouslySetInnerHTML={{ __html: icp.replace(/\s/ig, '&nbsp;') }}></p> : null}
          </div>
        </div>
      </div>
    )
  }
}
 
export default Pay