index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view>
  3. <!-- 签约页面 -->
  4. </view>
  5. </template>
  6. <script>
  7. // md5加密文件
  8. import md5 from '@/js_sdk/js-md5/src/md5.js'
  9. // base64加密文件
  10. import { Base64 } from '@/js_sdk/js-base64/base64.js'
  11. export default {
  12. data() {
  13. return {
  14. newTime: '',
  15. requestUrl: 'https://chtech.ncjti.edu.cn/jiaofei/jiaofei-api/tuitionpayment/WeiXiaoAuth/authentication'
  16. }
  17. },
  18. onLoad() {
  19. this.getIdCard()
  20. },
  21. methods: {
  22. // 获取用户身份证
  23. getIdCard() {
  24. let idCard = sessionStorage.getItem('idCard')
  25. if (!idCard) {
  26. let idCard = this.getQueryString('idCard')
  27. if (!idCard) {
  28. window.location.href = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=EE28EE2C93296F4E&response_type=code&scope=snsapi_base&ocode=1015730314&redirect_uri=${this.requestUrl}&state=${this.requestUrl}`
  29. } else {
  30. sessionStorage.setItem('idCard', idCard)
  31. this.getName()
  32. }
  33. } else {
  34. this.getName()
  35. }
  36. },
  37. // 获取用户姓名
  38. getName() {
  39. let name = sessionStorage.getItem('name')
  40. if (!name) {
  41. let name = this.getQueryString('name')
  42. if (!name) {
  43. window.location.href = `https://open.wecard.qq.com/connect/oauth/authorize?app_key=EE28EE2C93296F4E&response_type=code&scope=snsapi_base&ocode=1015730314&redirect_uri=${this.requestUrl}&state=${this.requestUrl}`
  44. } else {
  45. sessionStorage.setItem('name', name)
  46. this.getUrl()
  47. }
  48. } else {
  49. this.getUrl()
  50. }
  51. },
  52. // 获取跳转地址
  53. getUrl() {
  54. // md5加密 处理token参数
  55. this.getTime()
  56. let token = md5(md5('JANCJTISCHOOLSIGNING' + this.newTime))
  57. // base64加密 处理data参数
  58. let student_id = sessionStorage.getItem('idCard')
  59. let student_name = sessionStorage.getItem('name')
  60. let id_number = sessionStorage.getItem('idCard')
  61. // 收集参数
  62. let data = {
  63. student_id,
  64. student_name,
  65. id_number
  66. }
  67. // 把参数转换成JSON格式
  68. data = JSON.stringify(data)
  69. // 加密处理
  70. data = Base64.encode(encodeURIComponent(data))
  71. // // 获取授权签约地址
  72. let newUrl = `https://sa.jxnxs.com/SchoolAgreement/index?token=${token}&data=${data}`
  73. // // 跳转授权签约地址
  74. window.location.href = newUrl
  75. },
  76. // 获取当前时间
  77. getTime() {
  78. // 获取当前时间戳
  79. var date = new Date()
  80. // 获取年份
  81. var year = date.getFullYear()
  82. // 获取月份并补0
  83. var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  84. // 获取日期并补0
  85. var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  86. // 获取小时并补0
  87. var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  88. // 拼接后赋值
  89. this.newTime = String(year) + String(month) + String(day) + String(hours) + '00' + '00'
  90. },
  91. //获取当前URL指定参数
  92. getQueryString(name) {
  93. // 获取URL
  94. let url = window.location.href
  95. // 正则匹配URL
  96. let pattern = new RegExp('[?&]' + name + '=([^&]+)', 'i')
  97. let matcher = pattern.exec(url)
  98. if (matcher == null || matcher.length < 1) {
  99. return false
  100. }
  101. // 输出指定的参数值中文也可以
  102. return decodeURIComponent(matcher[1])
  103. }
  104. }
  105. }
  106. </script>
  107. <style></style>