feat(企业微信): 支持企业微信内应用自动登录

https://www.tapd.cn/55578866/prong/stories/view/1155578866001010956
This commit is contained in:
wisonic-s 2023-01-19 13:02:35 +08:00
parent 285402a4d7
commit 6927ec1370
3 changed files with 74 additions and 2 deletions

View File

@ -81,8 +81,17 @@ public class XWecomServer {
return wecomXpackService.getQrParam();
}
@GetMapping("/callBackWithoutLogin")
public ModelAndView callBackWithoutLogin(@RequestParam("code") String code,@RequestParam("state") String state) {
return privateCallBack(code, state, true);
}
@GetMapping("/callBack")
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
return privateCallBack(code, state, false);
}
private ModelAndView privateCallBack(String code, String state, Boolean withoutLogin) {
ModelAndView modelAndView = new ModelAndView("redirect:/");
HttpServletResponse response = ServletUtils.response();
WecomXpackService wecomXpackService = null;
@ -123,6 +132,12 @@ public class XWecomServer {
Cookie cookie_token = new Cookie("Authorization", token);
cookie_token.setPath("/");
if (withoutLogin) {
Cookie platformCookie = new Cookie("inOtherPlatform", "true");
platformCookie.setPath("/");
response.addCookie(platformCookie);
}
response.addCookie(cookie_token);
} catch (Exception e) {

View File

@ -116,6 +116,13 @@ export function wecomStatus() {
})
}
export function wecomQrParams() {
return request({
url: '/plugin/wecom/getQrParam',
method: 'post'
})
}
export function dingtalkStatus() {
return request({
url: '/api/auth/isOpenDingtalk',

View File

@ -23,6 +23,15 @@
component-name="LKSWithoutLogin"
/>
<plugin-com
v-else-if="isWecomLink && wecomOpen"
ref="WecomWithoutLogin"
:app-id="appId"
:agent-id="agentId"
:redirect-uri="redirectUri"
component-name="WecomWithoutLogin"
/>
<div
v-if="isDingTalkLink && !loading && !dingtalkOpen"
class="auto-login-missing"
@ -58,12 +67,33 @@
<span>未开启国际飞书</span>
</div>
<div
v-if="isWecomLink && !loading && !wecomOpen"
class="auto-login-missing"
>
<span>未开启企业微信</span>
</div>
<div
v-if="isWecomLink && !loading && !appId"
class="auto-login-missing"
>
<span>缺失企业ID</span>
</div>
<div
v-if="isWecomLink && !loading && !agentId"
class="auto-login-missing"
>
<span>缺失应用ID</span>
</div>
</div>
</template>
<script>
import PluginCom from '@/views/system/plugin/PluginCom'
import { dingtalkStatus, larkStatus, larksuiteStatus, larkAppId } from '@/api/user'
import { dingtalkStatus, larkStatus, larksuiteStatus, larkAppId, wecomStatus, wecomQrParams } from '@/api/user'
export default {
name: 'DeAutoLogin',
components: { PluginCom },
@ -75,7 +105,10 @@ export default {
dingtalkOpen: false,
larkOpen: false,
larksuiteOpen: false,
loading: true
loading: true,
wecomOpen: false,
agentId: null,
redirectUri: null
}
},
computed: {
@ -87,6 +120,9 @@ export default {
},
isLarksuiteLink() {
return this.type === 'larksuite'
},
isWecomLink() {
return this.type === 'wecom'
}
},
created() {
@ -124,6 +160,20 @@ export default {
}).catch(e => {
this.loading = false
})
this.isWecomLink && wecomStatus().then(res => {
if (res.success && res.data) {
wecomQrParams().then(resp => {
this.appId = resp.data.appid
this.agentId = resp.data.agentid
this.redirectUri = resp.data.redirectUri
this.wecomOpen = true
this.loading = false
})
}
}).catch(e => {
this.loading = false
})
},
methods: {