guest-reception-system/src/api/wecom.ts

19 lines
783 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { postRequest, type ApiResponse } from "./customFetch";
import { getWecomSignatureUrl } from "./fetchUrl";
import type { SignatureData } from "@wecom/jssdk";
/**
* 向后端换取企业微信 JS-SDK 签名。
* - type=config企业级wx.config
* - type=agent应用级agentConfig
* 后端用 jsapi_ticket 对传入的 url 计算 { timestamp, nonceStr, signature }。
*/
export const getWecomSignature = async (url: string, type: "config" | "agent"): Promise<SignatureData> => {
const res: ApiResponse = await postRequest(getWecomSignatureUrl(), { url, type });
const result = (res.code === 200 ? res.result : null) as SignatureData | null;
if (!result) {
throw new Error("获取企业微信 JS-SDK 签名失败");
}
return result;
};