Commit ebb601aa925630a4513ea557bc80e5eb0d315202
1 parent
d571c8f3
Exists in
master
feat:微信小程序单点登录对接
Showing
1 changed file
with
63 additions
and
45 deletions
Show diff stats
src/views/Service/ServiceKQ.vue
... | ... | @@ -6,54 +6,58 @@ |
6 | 6 | import ServiceBasekq from './ServiceBaseKQ.vue' |
7 | 7 | export default { |
8 | 8 | name: 'ServiceKQ', |
9 | - data () { | |
9 | + data() { | |
10 | 10 | return { |
11 | 11 | centerNo: '', |
12 | 12 | } |
13 | 13 | }, |
14 | 14 | |
15 | - mounted () { | |
15 | + mounted() { | |
16 | 16 | console.log('xst mounted') |
17 | 17 | this.checkAuth() |
18 | - | |
19 | 18 | }, |
20 | - activated () { | |
19 | + activated() { | |
21 | 20 | console.log('KQ activated') |
22 | 21 | this.checkAuth() |
23 | 22 | }, |
24 | 23 | methods: { |
25 | - checkAuth () { | |
26 | - let centerNo = localStorage.getItem('centerNo'); | |
27 | - let ticket = this.common.getUrlParam('ticket'); | |
24 | + checkAuth() { | |
25 | + let centerNo = localStorage.getItem('centerNo') | |
26 | + let ticket = this.common.getUrlParam('ticket') //浙里办app访问 | |
27 | + let ticketId = this.common.getUrlParam('ticketId') //浙里办微信小程序访问 | |
28 | + alert(location.href) | |
29 | + alert(ticketId) | |
28 | 30 | if (centerNo) { |
31 | + alert('有中台编号:' + centerNo) | |
29 | 32 | this.centerNo = centerNo |
30 | - localStorage.setItem('centerNo', centerNo); | |
33 | + localStorage.setItem('centerNo', centerNo) | |
31 | 34 | this.getUserInfo() |
32 | 35 | } else if (ticket) { |
33 | 36 | this.getCenterByTicket(ticket) |
37 | + } else if (ticketId) { | |
38 | + alert('调用getCenterByTicket') | |
39 | + this.getCenterByTicketId(ticketId) | |
34 | 40 | } else { |
35 | 41 | const sUserAgent = window.navigator.userAgent.toLowerCase() |
36 | - const dtdreamweb = sUserAgent.indexOf("dtdreamweb") > -1 | |
37 | - const miniprogram = sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1 | |
42 | + const dtdreamweb = sUserAgent.indexOf('dtdreamweb') > -1 | |
43 | + const miniprogram = sUserAgent.indexOf('miniprogram') > -1 && sUserAgent.indexOf('alipay') > -1 | |
38 | 44 | if (dtdreamweb) { |
39 | 45 | // alert('浙里办') |
40 | - window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy`; | |
41 | - } | |
42 | - else if (miniprogram) { | |
46 | + window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy` | |
47 | + } else if (miniprogram) { | |
43 | 48 | // alert('支付宝') |
44 | - window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy`; | |
45 | - } | |
46 | - else { | |
49 | + window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy` | |
50 | + } else { | |
47 | 51 | alert('非浙里办渠道访问,显示测试用户数据') |
48 | 52 | console.log('非浙里办渠道访问,显示测试用户数据') |
49 | 53 | this.centerNo = '2021111017103639979048000010279' |
50 | - localStorage.setItem('centerNo', '2021111017103639979048000010279'); | |
54 | + localStorage.setItem('centerNo', '2021111017103639979048000010279') | |
51 | 55 | this.getUserInfo() |
52 | 56 | } |
53 | 57 | } |
54 | 58 | }, |
55 | 59 | // 通过ticket获取centerNo |
56 | - getCenterByTicket (ticket) { | |
60 | + getCenterByTicket(ticket) { | |
57 | 61 | this.mgop({ |
58 | 62 | api: 'mgop.sz.hswsy.getCenterNo', // 必须 |
59 | 63 | host: 'https://mapi.zjzwfw.gov.cn/', |
... | ... | @@ -64,48 +68,62 @@ export default { |
64 | 68 | // 'isTestUrl': '1' |
65 | 69 | }, |
66 | 70 | data: { |
67 | - "ticket": ticket, | |
71 | + ticket: ticket, | |
68 | 72 | }, |
69 | - onSuccess: res => { | |
70 | - console.log('通过ticket获取centerNo成功', res) | |
73 | + onSuccess: (res) => { | |
74 | + console.log('通过ticket获取centerNo成功:', res) | |
75 | + alert('通过ticket获取centerNo成功:' + res.data.message) | |
71 | 76 | if (res.data.code == 200) { |
72 | 77 | this.centerNo = res.data.message |
73 | - localStorage.setItem('centerNo', res.data.message); | |
78 | + localStorage.setItem('centerNo', res.data.message) | |
74 | 79 | this.getUserInfo() |
75 | 80 | } else { |
76 | 81 | this.reLoad() |
77 | 82 | } |
78 | 83 | }, |
79 | - onFail: err => { | |
80 | - console.log('通过ticket获取centerNo成功失败', err) | |
84 | + onFail: (err) => { | |
85 | + alert('通过ticket获取centerNo失败:' + JSON.stringify(err)) | |
86 | + console.log('通过ticket获取centerNo成功失败:', JSON.stringify(err)) | |
81 | 87 | this.reLoad() |
88 | + }, | |
89 | + }) | |
90 | + }, | |
91 | + // 通过ticketId获取centerNo | |
92 | + getCenterByTicketId(ticketId) { | |
93 | + this.yxAxios.get(`${this.proxyUrl}/api/zlb/auth/getCenterNoWx?ticket=${ticketId}`).then((res) => { | |
94 | + alert('res:', JSON.stringify(res)) | |
95 | + if (res.data.code == 200) { | |
96 | + this.centerNo = res.data.message | |
97 | + localStorage.setItem('centerNo', res.data.message) | |
98 | + this.getUserInfo() | |
99 | + } else { | |
100 | + alert('通过ticketId获取centerNo失败:' + JSON.stringify(res.data.message)) | |
101 | + console.log('通过ticket获取centerNo成功失败:', JSON.stringify(res.data.message)) | |
102 | + // this.reLoad() | |
82 | 103 | } |
83 | 104 | }) |
84 | 105 | }, |
85 | - reLoad () { | |
106 | + reLoad() { | |
86 | 107 | console.log('reload') |
87 | 108 | ZWJSBridge.confirm({ |
88 | - "title": "警告", | |
89 | - "buttonLabels": [ | |
90 | - "重新载入" | |
91 | - ], | |
92 | - "message": "用户身份验证失败,请重新加载" | |
93 | - }).then(res => { | |
109 | + title: '警告', | |
110 | + buttonLabels: ['重新载入'], | |
111 | + message: '用户身份验证失败,请重新加载', | |
112 | + }).then((res) => { | |
94 | 113 | const sUserAgent = window.navigator.userAgent.toLowerCase() |
95 | - const dtdreamweb = sUserAgent.indexOf("dtdreamweb") > -1 | |
96 | - const miniprogram = sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1 | |
114 | + const dtdreamweb = sUserAgent.indexOf('dtdreamweb') > -1 | |
115 | + const miniprogram = sUserAgent.indexOf('miniprogram') > -1 && sUserAgent.indexOf('alipay') > -1 | |
97 | 116 | if (dtdreamweb) { |
98 | 117 | // alert('浙里办') |
99 | - window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy`; | |
100 | - } | |
101 | - else if (miniprogram) { | |
118 | + window.location.href = `https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=hswsy` | |
119 | + } else if (miniprogram) { | |
102 | 120 | // alert('支付宝') |
103 | - window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy`; | |
121 | + window.location.href = `https://puser.zjzwfw.gov.cn/sso/alipay.do?action=ssoLogin&servicecode=hswsy` | |
104 | 122 | } |
105 | 123 | }) |
106 | 124 | }, |
107 | 125 | // 获取用户信息 |
108 | - getUserInfo: function () { | |
126 | + getUserInfo: function() { | |
109 | 127 | this.mgop({ |
110 | 128 | api: 'mgop.sz.hswsy.getPortalUserByNum', // 必须 |
111 | 129 | // host: 'https://mapi.zjzwfw.gov.cn/', |
... | ... | @@ -116,22 +134,22 @@ export default { |
116 | 134 | // 'isTestUrl': '1' |
117 | 135 | }, |
118 | 136 | data: { |
119 | - "userNum": this.centerNo | |
137 | + userNum: this.centerNo, | |
120 | 138 | }, |
121 | - onSuccess: res => { | |
139 | + onSuccess: (res) => { | |
122 | 140 | console.log('getUserInfo', res) |
123 | 141 | if (res.data.code == 200) { |
124 | 142 | localStorage.setItem('userInfo', JSON.stringify(res.data.data.userInfo)) |
125 | 143 | } |
126 | 144 | }, |
127 | - onFail: err => { | |
145 | + onFail: (err) => { | |
128 | 146 | console.log('err', err) |
129 | - } | |
130 | - }); | |
147 | + }, | |
148 | + }) | |
131 | 149 | }, |
132 | 150 | }, |
133 | 151 | components: { |
134 | - ServiceBasekq | |
135 | - } | |
152 | + ServiceBasekq, | |
153 | + }, | |
136 | 154 | } |
137 | 155 | </script> | ... | ... |