123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <style>
- .test-links {
- padding: 20px;
- }
- .test-links a{
- display: block;
- line-height: 32px;
- font-size: 24px;
- margin-bottom: 20px;
- text-decoration: underline;
- }
- </style>
- <template>
- <div class="test-links">
- <mt-button type="default" @click.native="handlePay">支付</mt-button>
- </div>
- </template>
- <script>
- import lib from 'lib'
- import {Indicator, Toast, MessageBox} from 'mint-ui';
- import axios from 'axios'
- export default {
- data () {
- return {
- response: ''
- }
- },
- mounted () {
- // let code = lib.getParam('code') || '';
- // let state = lib.getParam('state') || '';
- // $.ajax(`${lib.apiUrl}/auth/authWebAT?code=${code}&state=${state}`, (res) => {
- // this.response = JSON.stringify(res);
- // })
- },
- methods: {
- async handlePay() {
- let configDone = await this.configWX();
- let uid = lib.getParam('uid');
- let dwAppId = lib.getParam('dwAppId');
- if(!configDone) {
- MessageBox('提示', '未知错误,请重试');
- return;
- };
-
- axios.post(`${lib.apiUrl}/order/proxyPay`, {
- dwAppId: dwAppId,
- uid: uid,
- productId: 1,
- count: 1
- }).then(({data}) => {
- let pData = data.data.platformData;
- console.log(pData);
- wx.chooseWXPay({
- timestamp: pData.timestamp,
- nonceStr: pData.nonceStr,
- package: pData.package,
- signType: pData.signType,
- paySign: pData.paySign,
- success (res) {
- // 支付成功后的回调函数
- }
- })
- })
- },
- configWX() {
- return new Promise((resolve, reject) => {
- axios.get(`${lib.apiUrl}/auth/jsSign`, {
- params: {
- url: location.href
- }
- }).then(({data}) => {
- wx.config({
- debug: false,
- appId: 'wxc137e1554d993f74',
- nonceStr: data.data.nonceStr,
- signature: data.data.signature,
- timestamp: data.data.timestamp,
- jsApiList: [
- "chooseWXPay"
- ]
- });
- wx.error(function(res){
- MessageBox("提示", JSON.stringify(res))
- });
- wx.ready(() => {
- resolve(true)
- })
- }).catch(({data}) => {
- reject(false)
- })
- })
- },
- checkOrderState() {
-
- }
- }
- }
- </script>
|