Refactor the shared wechat login code utility by moving it from the recharge service to a standalone module. Add the sensitive request flag to the createAigcGeneratorTask POST API call. Update the aigc detail and template use pages to fetch and pass the wechat login code when creating generation tasks. Remove the redundant login code implementation from the recharge payment service.
27 lines
722 B
JavaScript
27 lines
722 B
JavaScript
const getWechatApi = () => {
|
|
// #ifdef MP-WEIXIN
|
|
if (typeof wx !== "undefined") return wx;
|
|
// #endif
|
|
return null;
|
|
};
|
|
|
|
export function getWechatLoginCode(wechatApi = getWechatApi()) {
|
|
if (!wechatApi || typeof wechatApi.login !== "function") {
|
|
return Promise.reject(new Error("当前环境无法获取微信登录凭证"));
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
wechatApi.login({
|
|
success: (result) => {
|
|
const code = String(result?.code || "").trim();
|
|
if (code) {
|
|
resolve(code);
|
|
return;
|
|
}
|
|
reject(new Error("微信登录凭证获取失败"));
|
|
},
|
|
fail: () => reject(new Error("微信登录凭证获取失败")),
|
|
});
|
|
});
|
|
}
|