feat: 增加token获取
parent
48fe17a4cb
commit
87ffa1d4f9
|
|
@ -74,3 +74,19 @@ export const fetchWishList = async ({
|
||||||
return { result: [], message: response.message };
|
return { result: [], message: response.message };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCozeToken = async({
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
|
||||||
|
options?: { signal?: AbortSignal; headers?: Record<string, string> };
|
||||||
|
}) => {
|
||||||
|
const response = await getRequest("https:///api.v3.ycymedu.com/api/sysDictData/secrtToken", {Id:740405293269061}, options);
|
||||||
|
|
||||||
|
if (response.code === 200) {
|
||||||
|
return { result: response.result };
|
||||||
|
} else {
|
||||||
|
return { result: [], message: response.message };
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,9 @@ import {
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import { MessageHandlerStrategy } from "@/hooks/useRealtimeClient";
|
import { MessageHandlerStrategy } from "@/hooks/useRealtimeClient";
|
||||||
|
import { useAbortController } from "@/hooks/useAbortController";
|
||||||
|
import { useSearchParams } from "react-router-dom";
|
||||||
|
import { getCozeToken } from "@/apis/user";
|
||||||
|
|
||||||
type RoomInfo = {
|
type RoomInfo = {
|
||||||
appId: string;
|
appId: string;
|
||||||
|
|
@ -69,7 +72,7 @@ export const RealtimeClientProvider = ({
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
const token = import.meta.env.VITE_COZE_TOKEN;
|
let token = "";
|
||||||
const botId = import.meta.env.VITE_COZE_BOT_ID;
|
const botId = import.meta.env.VITE_COZE_BOT_ID;
|
||||||
const voiceId = import.meta.env.VITE_COZE_VOICE_ID;
|
const voiceId = import.meta.env.VITE_COZE_VOICE_ID;
|
||||||
const connectorId = "1024";
|
const connectorId = "1024";
|
||||||
|
|
@ -97,6 +100,9 @@ export const RealtimeClientProvider = ({
|
||||||
|
|
||||||
const messageHandlerStrategy = useRef(new MessageHandlerStrategy());
|
const messageHandlerStrategy = useRef(new MessageHandlerStrategy());
|
||||||
|
|
||||||
|
const { getSignal } = useAbortController();
|
||||||
|
const [searchParams]= useSearchParams();
|
||||||
|
const userToken = searchParams.get("token") || '';
|
||||||
/** 初始化客户端并设置监听 */
|
/** 初始化客户端并设置监听 */
|
||||||
const initClient = async ({
|
const initClient = async ({
|
||||||
initMessage,
|
initMessage,
|
||||||
|
|
@ -105,6 +111,11 @@ export const RealtimeClientProvider = ({
|
||||||
initMessage?: string;
|
initMessage?: string;
|
||||||
fileInfo?: FileInfo;
|
fileInfo?: FileInfo;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
|
if(token === ''){
|
||||||
|
const resp = await getCozeToken({options:{signal:getSignal(),headers: { Authorization: `Bearer ${userToken}` }}})
|
||||||
|
token = resp.result as string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const client = new RealtimeClient({
|
const client = new RealtimeClient({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue