From 25f59d613d0163943114ff612a4db4168a71a0de Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Wed, 27 Aug 2025 15:51:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=20=E5=AE=8C=E6=88=90=E9=92=89?= =?UTF-8?q?=E9=92=89=E5=85=8D=E7=99=BB=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E9=AA=8C=E8=AF=81=E9=80=9A=E8=BF=87=E5=90=8E=E5=86=8D?= =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/AuthStore.js | 60 +++++++++++++++++++++++++++++++++ src/views/dingding/AuthCode.jsx | 11 +++++- src/views/dingding/Callback.jsx | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index 5419cfa..665586b 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -107,6 +107,66 @@ const useAuthStore = create(devtools((set, get) => ({ } }, + parseLoginJson: (json) => { + const { setStorage } = usingStorage() + if (json.errcode === 0 && isNotEmpty(json.result.opisn)) { + const waiServer = json.result.whatsappinfo.length > 0 ? json.result.whatsappinfo[0].wai_server : '' + setStorage(WAI_SERVER_KEY, waiServer) + + const parsedUser = { + userId: json.result.opisn, + userIdStr: json.result?.accountlist + .map((acc) => { + return acc.OPI_SN + }) + .join(','), + emailList: json.result?.emaillist.map(item => { + return { + opi_sn: item.opi_sn, + mat_sn: item.mat_sn, + email: item.email, + default: item.Isdefaultemail == 1, + backup: item.Isbakemail == 1, + } + }), + whatsAppBusiness: json.result.whatsappinfo.length > 0 ? json.result.whatsappinfo[0].whatsapp_waba : '', + whatsAppNo: json.result.whatsappinfo.length > 0 ? json.result.whatsappinfo[0].whatsapp_wa : '', + accountName: json.result.opicode, + username: json.result.nick, + avatarUrl: json.result.avatarUrl, + mobile: '+' + json.result.stateCode + '-' + json.result.mobile, + email: json.result.email, + openId: json.result.openId, + accountList: json.result.accountlist, + } + + return parsedUser + } else { return null } + }, + + // 钉钉免登后获取用户信息 + loginByJSAuth: async (authCode) => { + const { saveUserSession, setLoginStatus } = get() + setLoginStatus(200) + + const json = await fetchJSON( + 'https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/Getusers_auth_wa', + { authCode }, + ) + + const parsedUser = parseLoginJson(json) + + if (parsedUser) { + set(() => ({ + loginUser: parsedUser, + })) + saveUserSession() + setLoginStatus(302) + } else { + setLoginStatus(403) + } + }, + getPrimaryEmail: () => { const { loginUser } = get() diff --git a/src/views/dingding/AuthCode.jsx b/src/views/dingding/AuthCode.jsx index 30d2790..0fccc31 100644 --- a/src/views/dingding/AuthCode.jsx +++ b/src/views/dingding/AuthCode.jsx @@ -1,11 +1,14 @@ -import { Flex, Result, Input, Button } from 'antd' +import { Flex, Result, Input, Button, Typography } from 'antd' import { useState, useEffect } from 'react' import * as dd from 'dingtalk-jsapi' +import useAuthStore from '@/stores/AuthStore' // 获取微应用免登授权码 // https://open.dingtalk.com/document/orgapp/jsapi-request-auth-code function AuthCode() { + const loginByJSAuth = useAuthStore((state) => state.loginByJSAuth) + const loginStatus = useAuthStore((state) => state.loginStatus) const [result, setResult] = useState('') const [clientValue, setClientValue] = useState('dingl3jyntkazyg4coxf') const handleRequest = () => { @@ -23,6 +26,10 @@ function AuthCode() { }) } + const handleLogin = () => { + loginByJSAuth(result) + } + useEffect(() => { const dingTalkPlatForm = dd.env.platform setResult(dingTalkPlatForm) @@ -35,8 +42,10 @@ function AuthCode() { title={clientValue} subTitle={result} /> + Login: {loginStatus} setClientValue(e.currentTarget.value)} /> + ) } diff --git a/src/views/dingding/Callback.jsx b/src/views/dingding/Callback.jsx index 4e3eecc..a72518b 100644 --- a/src/views/dingding/Callback.jsx +++ b/src/views/dingding/Callback.jsx @@ -24,6 +24,7 @@ function Callback() { if (isNotEmpty(authCode) && state === 'global-saels') { login(authCode) } else if (isNotEmpty(authCode) && state === 'jsapi-auth') { + // https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/Getusers_auth_wa // loginByJSAuth() } else { console.error('error: ' + error)