index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script setup>
  6. import {
  7. onLoad
  8. } from "@dcloudio/uni-app"
  9. const APPKEY = '4AA7B3944BDF3739'
  10. const APPID = 'wxd87cbe1db0437303'
  11. const ocode = '1015730314'
  12. const SCOPE = 'snsapi_base'
  13. const URL = 'https://chtech.ncjti.edu.cn/jiaofei/jiaofeiManage/'
  14. const URL2 = 'http://192.168.161.78:5173/#/pages/index/index'
  15. onLoad(() => {
  16. // loginFilter()
  17. uni.switchTab({
  18. url: "/pages/home/home"
  19. })
  20. })
  21. const loginFilter = () => {
  22. const wxcode = uni.getStorageSync('wxcode')
  23. if (!wxcode) {
  24. const wxcode = getQueryString('wxcode')
  25. if (!wxcode) {
  26. getWxcodeURL()
  27. } else {
  28. alert(wxcode)
  29. uni.setStorageSync('wxcode', wxcode)
  30. getCode()
  31. }
  32. } else {
  33. getCode()
  34. }
  35. }
  36. const getCode = () => {
  37. const code = uni.getStorageSync('code');
  38. if (!code) {
  39. const code = getQueryString('code')
  40. if (!code) {
  41. alert(666)
  42. getCodeURL()
  43. } else {
  44. alert(code)
  45. uni.setStorageSync('code', code)
  46. uni.switchTab({
  47. url: "/pages/home/home"
  48. })
  49. }
  50. } else {
  51. uni.switchTab({
  52. url: "/pages/home/home"
  53. })
  54. }
  55. }
  56. const getWxcodeURL = () => {
  57. window.
  58. location.href =
  59. `https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${encodeURIComponent(URL2)}`
  60. }
  61. const getCodeURL = () => {
  62. window.
  63. location.href =
  64. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${encodeURIComponent(URL)}&response_type=code&scope=${SCOPE}#wechat_redirect`
  65. }
  66. //获取当前URL指定参数
  67. const getQueryString = (name) => {
  68. // 获取URL
  69. let url = window.location.href;
  70. // 正则匹配URL
  71. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
  72. let matcher = pattern.exec(url);
  73. if (matcher == null || matcher.length < 1) {
  74. return false;
  75. }
  76. // 输出指定的参数值
  77. return decodeURIComponent(matcher[1]);
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. </style>