weChatPay.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <div>
  3. </div>
  4. </template>
  5. <script>
  6. import { onMounted } from "vue";
  7. import { useRoute } from "vue-router";
  8. export default {
  9. name: 'weChatPay',
  10. setup() {
  11. const route = useRoute();
  12. console.log(route.query.id);
  13. const id = route.query.id;
  14. const appId = "wxcd5b1b2636c9f611";
  15. onMounted(() => {
  16. wxPay();
  17. });
  18. const wxPay = () => {
  19. // 处理回调接口
  20. const redirectUri = encodeURIComponent('http://szwlh.sunzee.com.cn/PAY-SERVER/tOrder/callback');
  21. // const redirectUri = encodeURIComponent('http://szwltest.sunzee.com.cn/PAY-SERVER/tOrder/callback');
  22. const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=${id}&connect_redirect=1#wechat_redirect`;
  23. console.log(url)
  24. window.location.replace(url);
  25. };
  26. return {
  27. wxPay
  28. };
  29. }
  30. };
  31. </script>