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,54 +6,58 @@ | ||
6 | import ServiceBasekq from './ServiceBaseKQ.vue' | 6 | import ServiceBasekq from './ServiceBaseKQ.vue' |
7 | export default { | 7 | export default { |
8 | name: 'ServiceKQ', | 8 | name: 'ServiceKQ', |
9 | - data () { | 9 | + data() { |
10 | return { | 10 | return { |
11 | centerNo: '', | 11 | centerNo: '', |
12 | } | 12 | } |
13 | }, | 13 | }, |
14 | 14 | ||
15 | - mounted () { | 15 | + mounted() { |
16 | console.log('xst mounted') | 16 | console.log('xst mounted') |
17 | this.checkAuth() | 17 | this.checkAuth() |
18 | - | ||
19 | }, | 18 | }, |
20 | - activated () { | 19 | + activated() { |
21 | console.log('KQ activated') | 20 | console.log('KQ activated') |
22 | this.checkAuth() | 21 | this.checkAuth() |
23 | }, | 22 | }, |
24 | methods: { | 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 | if (centerNo) { | 30 | if (centerNo) { |
31 | + alert('有中台编号:' + centerNo) | ||
29 | this.centerNo = centerNo | 32 | this.centerNo = centerNo |
30 | - localStorage.setItem('centerNo', centerNo); | 33 | + localStorage.setItem('centerNo', centerNo) |
31 | this.getUserInfo() | 34 | this.getUserInfo() |
32 | } else if (ticket) { | 35 | } else if (ticket) { |
33 | this.getCenterByTicket(ticket) | 36 | this.getCenterByTicket(ticket) |
37 | + } else if (ticketId) { | ||
38 | + alert('调用getCenterByTicket') | ||
39 | + this.getCenterByTicketId(ticketId) | ||
34 | } else { | 40 | } else { |
35 | const sUserAgent = window.navigator.userAgent.toLowerCase() | 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 | if (dtdreamweb) { | 44 | if (dtdreamweb) { |
39 | // alert('浙里办') | 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 | // alert('支付宝') | 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 | alert('非浙里办渠道访问,显示测试用户数据') | 51 | alert('非浙里办渠道访问,显示测试用户数据') |
48 | console.log('非浙里办渠道访问,显示测试用户数据') | 52 | console.log('非浙里办渠道访问,显示测试用户数据') |
49 | this.centerNo = '2021111017103639979048000010279' | 53 | this.centerNo = '2021111017103639979048000010279' |
50 | - localStorage.setItem('centerNo', '2021111017103639979048000010279'); | 54 | + localStorage.setItem('centerNo', '2021111017103639979048000010279') |
51 | this.getUserInfo() | 55 | this.getUserInfo() |
52 | } | 56 | } |
53 | } | 57 | } |
54 | }, | 58 | }, |
55 | // 通过ticket获取centerNo | 59 | // 通过ticket获取centerNo |
56 | - getCenterByTicket (ticket) { | 60 | + getCenterByTicket(ticket) { |
57 | this.mgop({ | 61 | this.mgop({ |
58 | api: 'mgop.sz.hswsy.getCenterNo', // 必须 | 62 | api: 'mgop.sz.hswsy.getCenterNo', // 必须 |
59 | host: 'https://mapi.zjzwfw.gov.cn/', | 63 | host: 'https://mapi.zjzwfw.gov.cn/', |
@@ -64,48 +68,62 @@ export default { | @@ -64,48 +68,62 @@ export default { | ||
64 | // 'isTestUrl': '1' | 68 | // 'isTestUrl': '1' |
65 | }, | 69 | }, |
66 | data: { | 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 | if (res.data.code == 200) { | 76 | if (res.data.code == 200) { |
72 | this.centerNo = res.data.message | 77 | this.centerNo = res.data.message |
73 | - localStorage.setItem('centerNo', res.data.message); | 78 | + localStorage.setItem('centerNo', res.data.message) |
74 | this.getUserInfo() | 79 | this.getUserInfo() |
75 | } else { | 80 | } else { |
76 | this.reLoad() | 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 | this.reLoad() | 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 | console.log('reload') | 107 | console.log('reload') |
87 | ZWJSBridge.confirm({ | 108 | ZWJSBridge.confirm({ |
88 | - "title": "警告", | ||
89 | - "buttonLabels": [ | ||
90 | - "重新载入" | ||
91 | - ], | ||
92 | - "message": "用户身份验证失败,请重新加载" | ||
93 | - }).then(res => { | 109 | + title: '警告', |
110 | + buttonLabels: ['重新载入'], | ||
111 | + message: '用户身份验证失败,请重新加载', | ||
112 | + }).then((res) => { | ||
94 | const sUserAgent = window.navigator.userAgent.toLowerCase() | 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 | if (dtdreamweb) { | 116 | if (dtdreamweb) { |
98 | // alert('浙里办') | 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 | // alert('支付宝') | 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 | this.mgop({ | 127 | this.mgop({ |
110 | api: 'mgop.sz.hswsy.getPortalUserByNum', // 必须 | 128 | api: 'mgop.sz.hswsy.getPortalUserByNum', // 必须 |
111 | // host: 'https://mapi.zjzwfw.gov.cn/', | 129 | // host: 'https://mapi.zjzwfw.gov.cn/', |
@@ -116,22 +134,22 @@ export default { | @@ -116,22 +134,22 @@ export default { | ||
116 | // 'isTestUrl': '1' | 134 | // 'isTestUrl': '1' |
117 | }, | 135 | }, |
118 | data: { | 136 | data: { |
119 | - "userNum": this.centerNo | 137 | + userNum: this.centerNo, |
120 | }, | 138 | }, |
121 | - onSuccess: res => { | 139 | + onSuccess: (res) => { |
122 | console.log('getUserInfo', res) | 140 | console.log('getUserInfo', res) |
123 | if (res.data.code == 200) { | 141 | if (res.data.code == 200) { |
124 | localStorage.setItem('userInfo', JSON.stringify(res.data.data.userInfo)) | 142 | localStorage.setItem('userInfo', JSON.stringify(res.data.data.userInfo)) |
125 | } | 143 | } |
126 | }, | 144 | }, |
127 | - onFail: err => { | 145 | + onFail: (err) => { |
128 | console.log('err', err) | 146 | console.log('err', err) |
129 | - } | ||
130 | - }); | 147 | + }, |
148 | + }) | ||
131 | }, | 149 | }, |
132 | }, | 150 | }, |
133 | components: { | 151 | components: { |
134 | - ServiceBasekq | ||
135 | - } | 152 | + ServiceBasekq, |
153 | + }, | ||
136 | } | 154 | } |
137 | </script> | 155 | </script> |