index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view>
  3. <!-- 登陆拦截页面 -->
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. //线上服务器域名
  11. homeUrl: "https://chtech.ncjti.edu.cn/jiaofei/jiaofei-api",
  12. // homeUrl: "http://192.168.161.34:9999",
  13. }
  14. },
  15. onLoad() {
  16. //获取cardNumber
  17. this.loginFilter();
  18. },
  19. methods: {
  20. //获取cardNumber
  21. loginFilter() {
  22. let card_number = localStorage.card_number
  23. if (!card_number) {
  24. let cardNumber = this.getQueryString("cardNumber");
  25. if (!cardNumber) {
  26. window.location.href =
  27. `https://open.wecard.qq.com/connect/oauth/authorize?app_key=580DBB565097446B&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/hjh/&connect=curLogin&state=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/hjh/`;
  28. } else {
  29. localStorage.card_number = cardNumber
  30. this.getStudentName()
  31. }
  32. } else {
  33. this.getStudentName()
  34. }
  35. },
  36. // 获取学生姓名
  37. getStudentName() {
  38. let studentName = localStorage.studentName
  39. if (!studentName) {
  40. let studentName = this.getQueryString("name");
  41. if (!studentName) {
  42. window.location.href =
  43. `https://open.wecard.qq.com/connect/oauth/authorize?app_key=580DBB565097446B&response_type=code&scope=snsapi_userinfo&ocode=1015730314&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/hjh/&connect=curLogin&state=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/hjh/`;
  44. } else {
  45. localStorage.studentName = studentName
  46. this.getOpenId()
  47. }
  48. } else {
  49. this.getOpenId()
  50. }
  51. },
  52. //获取openId
  53. getOpenId() {
  54. // 从缓存获取openId,如果有的话
  55. let openId = localStorage.getItem("openId")
  56. if (!openId) {
  57. // 从url链接中获取openId,如果有的话
  58. let openId = this.getQueryString("openId");
  59. // 缓存中和url参数中度没有获取到openId,则请求授权地址发起授权
  60. if (!openId) {
  61. window.location.href =
  62. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd87cbe1db0437303&redirect_uri=${this.homeUrl}/tuitionpayment/wechat/pub/auth/hjh&response_type=code&scope=snsapi_base&state=pages/index/index#wechat_redire`;
  63. return
  64. } else {
  65. // 获取到openId,存入缓存
  66. localStorage.setItem("openId", openId)
  67. // 跳转到缴费信息列表页面
  68. this.goPageHome();
  69. }
  70. } else {
  71. // 跳转到缴费信息列表页面
  72. this.goPageHome();
  73. }
  74. },
  75. //获取当前URL指定参数
  76. getQueryString(name) {
  77. // 获取URL
  78. let url = window.location.href;
  79. // 正则匹配URL
  80. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
  81. let matcher = pattern.exec(url);
  82. if (matcher == null || matcher.length < 1) {
  83. return false;
  84. }
  85. // 输出指定的参数值
  86. return decodeURIComponent(matcher[1]);
  87. },
  88. //跳转到支付信息列表页
  89. goPageHome() {
  90. uni.reLaunch({
  91. url: "/pages/home/home"
  92. });
  93. },
  94. }
  95. }
  96. </script>
  97. <style>
  98. </style>