links.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <style>
  2. .test-links {
  3. padding: 20px;
  4. }
  5. .test-links a{
  6. display: block;
  7. line-height: 32px;
  8. font-size: 24px;
  9. margin-bottom: 20px;
  10. text-decoration: underline;
  11. }
  12. </style>
  13. <template>
  14. <div class="test-links">
  15. <mt-button type="default" @click.native="handlePay">支付</mt-button>
  16. </div>
  17. </template>
  18. <script>
  19. import lib from 'lib'
  20. import {Indicator, Toast, MessageBox} from 'mint-ui';
  21. import axios from 'axios'
  22. export default {
  23. data () {
  24. return {
  25. response: ''
  26. }
  27. },
  28. mounted () {
  29. // let code = lib.getParam('code') || '';
  30. // let state = lib.getParam('state') || '';
  31. // $.ajax(`${lib.apiUrl}/auth/authWebAT?code=${code}&state=${state}`, (res) => {
  32. // this.response = JSON.stringify(res);
  33. // })
  34. },
  35. methods: {
  36. async handlePay() {
  37. let configDone = await this.configWX();
  38. let uid = lib.getParam('uid');
  39. let dwAppId = lib.getParam('dwAppId');
  40. if(!configDone) {
  41. MessageBox('提示', '未知错误,请重试');
  42. return;
  43. };
  44. axios.post(`${lib.apiUrl}/order/proxyPay`, {
  45. dwAppId: dwAppId,
  46. uid: uid,
  47. productId: 1,
  48. count: 1
  49. }).then(({data}) => {
  50. let pData = data.data.platformData;
  51. console.log(pData);
  52. wx.chooseWXPay({
  53. timestamp: pData.timestamp,
  54. nonceStr: pData.nonceStr,
  55. package: pData.package,
  56. signType: pData.signType,
  57. paySign: pData.paySign,
  58. success (res) {
  59. // 支付成功后的回调函数
  60. }
  61. })
  62. })
  63. },
  64. configWX() {
  65. return new Promise((resolve, reject) => {
  66. axios.get(`${lib.apiUrl}/auth/jsSign`, {
  67. params: {
  68. url: location.href
  69. }
  70. }).then(({data}) => {
  71. wx.config({
  72. debug: false,
  73. appId: 'wxc137e1554d993f74',
  74. nonceStr: data.data.nonceStr,
  75. signature: data.data.signature,
  76. timestamp: data.data.timestamp,
  77. jsApiList: [
  78. "chooseWXPay"
  79. ]
  80. });
  81. wx.error(function(res){
  82. MessageBox("提示", JSON.stringify(res))
  83. });
  84. wx.ready(() => {
  85. resolve(true)
  86. })
  87. }).catch(({data}) => {
  88. reject(false)
  89. })
  90. })
  91. },
  92. checkOrderState() {
  93. }
  94. }
  95. }
  96. </script>