wechat_nuxt_001
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// 创建一个响应式状态并设置默认值
|
||||
import type {SignatureData} from "@wecom/jssdk";
|
||||
|
||||
|
||||
import * as ww from "@wecom/jssdk";
|
||||
|
||||
type 接口回调数据类型 = {}
|
||||
export const wechat_auth = async (): Promise<void> => {
|
||||
if (ww.env.isWeChat) {
|
||||
ww.register({
|
||||
corpId: "wx654fffabd4b1f5cf",
|
||||
jsApiList: ["chooseImage"],
|
||||
getConfigSignature: async (url): Promise<SignatureData> => {
|
||||
return await $fetch<SignatureData>(
|
||||
"https://six.sixgou.com/wechat/auth/signature/",
|
||||
{method: "post", body: {url}});
|
||||
},
|
||||
onConfigSuccess: async (e) => {
|
||||
console.log("config 成功回调", e);
|
||||
},
|
||||
onConfigFail: async (e) => {
|
||||
console.log("config 失败回调", e);
|
||||
},
|
||||
onConfigComplete: async (e) => {
|
||||
console.log("config 完成回调", e);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export function wechat_完速的请求链接(params: {
|
||||
appid?: string; redirectUri?: string; scope?: string; state?: string; agentid?: string;
|
||||
}): string {
|
||||
const url = new URL("https://open.weixin.qq.com/connect/oauth2/authorize");
|
||||
url.searchParams.set("appid", params.appid ?? "wx654fffabd4b1f5cf"); // 测试账号的🆔
|
||||
// url.searchParams.set("appid", params.appid ?? "wwbe6369dc26a9d83a"); // 企业微信号 🆔
|
||||
// url.searchParams.set("appid", params.appid ?? "wwbe6369dc26a9d83a"); // 服务号 🆔
|
||||
url.searchParams.set("redirect_uri", params.redirectUri ?? "https://xiao.sixgou.com/wechat/auth/get_code/");
|
||||
url.searchParams.set("scope", params.scope ?? "snsapi_userinfo");
|
||||
url.searchParams.set("response_type", "code");
|
||||
url.searchParams.set("state", params.state ?? "state");
|
||||
if (params.agentid) {
|
||||
url.searchParams.set("agentid", params.agentid); // 这里的值是 100025(元宝零售)
|
||||
}
|
||||
// 注意:微信要求 #wechat_redirect(单个 #),而非 ##
|
||||
url.hash = "wechat_redirect";
|
||||
return url.href;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user