index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.getItem("card_number")
  23. let card_number = localStorage.card_number
  24. if (!card_number) {
  25. let cardNumber = this.getQueryString("cardNumber");
  26. if (!cardNumber) {
  27. window.location.href =
  28. `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`;
  29. } else {
  30. // localStorage.setItem("card_number", cardNumber)
  31. localStorage.card_number = cardNumber
  32. this.getStudentName()
  33. }
  34. } else {
  35. this.getStudentName()
  36. }
  37. },
  38. // 获取学生姓名
  39. getStudentName() {
  40. // let studentName = localStorage.getItem("studentName")
  41. let studentName = localStorage.studentName
  42. if (!studentName) {
  43. let studentName = this.getQueryString("name");
  44. if (!studentName) {
  45. window.location.href =
  46. `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`;
  47. } else {
  48. localStorage.studentName = studentName
  49. this.getOpenId()
  50. }
  51. } else {
  52. this.getOpenId()
  53. }
  54. },
  55. // 获取学生手机号
  56. // getStudentPhone() {
  57. // let studentPhone = localStorage.studentPhone
  58. // if (!studentPhone) {
  59. // let studentPhone = this.getQueryString("name");
  60. // if (!studentPhone) {
  61. // window.location.href =
  62. // `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/&connect=curLogin&state=${this.homeUrl}/tuitionpayment/wechat/weixiao/auth/`;
  63. // } else {
  64. // localStorage.studentPhone = studentPhone
  65. // this.getOpenId()
  66. // }
  67. // } else {
  68. // this.getOpenId()
  69. // }
  70. // },
  71. //获取openId
  72. getOpenId() {
  73. // 从缓存获取openId,如果有的话
  74. let openId = localStorage.getItem("openId")
  75. if (!openId) {
  76. // 从url链接中获取openId,如果有的话
  77. let openId = this.getQueryString("openId");
  78. // 缓存中和url参数中度没有获取到openId,则请求授权地址发起授权
  79. if (!openId) {
  80. window.location.href =
  81. `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`;
  82. return
  83. } else {
  84. // 获取到openId,存入缓存
  85. localStorage.setItem("openId", openId)
  86. // 跳转到缴费信息列表页面
  87. this.goPageHome();
  88. }
  89. } else {
  90. // 跳转到缴费信息列表页面
  91. this.goPageHome();
  92. }
  93. },
  94. //获取当前URL指定参数
  95. getQueryString(name) {
  96. // 获取URL
  97. let url = window.location.href;
  98. // 正则匹配URL
  99. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
  100. let matcher = pattern.exec(url);
  101. if (matcher == null || matcher.length < 1) {
  102. return false;
  103. }
  104. // 输出指定的参数值
  105. return decodeURIComponent(matcher[1]);
  106. },
  107. //跳转到支付信息列表页
  108. goPageHome() {
  109. uni.reLaunch({
  110. url: "/pages/home/home"
  111. });
  112. },
  113. }
  114. }
  115. </script>
  116. <style>
  117. </style>