From 13d019b1913b672b90d2af0e9e78a1d3a31c5865 Mon Sep 17 00:00:00 2001 From: duanshuwen Date: Thu, 23 Jul 2026 11:57:09 +0800 Subject: [PATCH] feat(aigc): pass wechat login code to generator task requests 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. --- src/pages-aigc/detail/detail.vue | 3 +++ .../recharge/services/wechatVirtualPayment.js | 22 ++-------------- src/pages-aigc/services/wechatLogin.js | 26 +++++++++++++++++++ src/pages-aigc/useTemplate/useTemplate.vue | 3 +++ src/request/api/AigcApi.js | 6 ++++- 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 src/pages-aigc/services/wechatLogin.js diff --git a/src/pages-aigc/detail/detail.vue b/src/pages-aigc/detail/detail.vue index 3c7834e..f9b3558 100644 --- a/src/pages-aigc/detail/detail.vue +++ b/src/pages-aigc/detail/detail.vue @@ -32,6 +32,7 @@ import { onLoad, onShareAppMessage, onShow } from "@dcloudio/uni-app"; import Privacy from "@/components/Privacy/index.vue"; import AigcTopBar from "@/pages-aigc/components/AigcTopBar/index.vue"; import { useCurrentCredit } from "@/pages-aigc/hooks/useCurrentCredit.js"; +import { getWechatLoginCode } from "@/pages-aigc/services/wechatLogin.js"; import { createAigcGeneratorTask, createAigcGeneratorTaskShare, @@ -542,9 +543,11 @@ const handleConfirmRegenerate = async () => { }); try { + const wxLoginCode = await getWechatLoginCode(); const res = await createAigcGeneratorTask({ templateItemId, imageUrlList: [imageResultUrl], + wxLoginCode, }); const nextTaskId = String(res?.data || "").trim(); diff --git a/src/pages-aigc/recharge/services/wechatVirtualPayment.js b/src/pages-aigc/recharge/services/wechatVirtualPayment.js index 6249eb6..a4c9c0f 100644 --- a/src/pages-aigc/recharge/services/wechatVirtualPayment.js +++ b/src/pages-aigc/recharge/services/wechatVirtualPayment.js @@ -3,6 +3,8 @@ import { normalizeWechatClientPlatform, } from "../utils/virtualRecharge.js"; +export { getWechatLoginCode } from "../../services/wechatLogin.js"; + const MIN_VIRTUAL_PAYMENT_SDK_VERSION = "2.19.2"; const getWechatApi = () => { @@ -65,26 +67,6 @@ export function getWechatClientPlatform(wechatApi = getWechatApi()) { return clientPlatform; } -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("微信登录凭证获取失败")), - }); - }); -} - export function requestWechatVirtualPayment(paymentData, wechatApi = getWechatApi()) { assertWechatVirtualPaymentCapability(wechatApi); const order = normalizeVirtualPaymentOrder(paymentData); diff --git a/src/pages-aigc/services/wechatLogin.js b/src/pages-aigc/services/wechatLogin.js new file mode 100644 index 0000000..6403a40 --- /dev/null +++ b/src/pages-aigc/services/wechatLogin.js @@ -0,0 +1,26 @@ +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("微信登录凭证获取失败")), + }); + }); +} diff --git a/src/pages-aigc/useTemplate/useTemplate.vue b/src/pages-aigc/useTemplate/useTemplate.vue index d85d2ee..374c26a 100644 --- a/src/pages-aigc/useTemplate/useTemplate.vue +++ b/src/pages-aigc/useTemplate/useTemplate.vue @@ -46,6 +46,7 @@ import { onLoad, onShow } from "@dcloudio/uni-app"; import Privacy from "@/components/Privacy/index.vue"; import AigcTopBar from "@/pages-aigc/components/AigcTopBar/index.vue"; import { useCurrentCredit } from "@/pages-aigc/hooks/useCurrentCredit.js"; +import { getWechatLoginCode } from "@/pages-aigc/services/wechatLogin.js"; import { createAigcGeneratorTask, getAigcTemplateItemList, @@ -356,9 +357,11 @@ const handleGenerate = async () => { }); try { + const wxLoginCode = await getWechatLoginCode(); const res = await createAigcGeneratorTask({ templateItemId, imageUrlList: [uploadedImageUrl.value], + wxLoginCode, }); const taskId = String(res?.data || "").trim(); diff --git a/src/request/api/AigcApi.js b/src/request/api/AigcApi.js index ccbe941..3808533 100644 --- a/src/request/api/AigcApi.js +++ b/src/request/api/AigcApi.js @@ -17,7 +17,11 @@ function getAigcGeneratorTaskDetail(args) { } function createAigcGeneratorTask(args) { - return request.post("/hotelBiz/aigcGeneratorTask/createAigcGeneratorTask", args); + return request.post( + "/hotelBiz/aigcGeneratorTask/createAigcGeneratorTask", + args, + { sensitive: true } + ); } function getCurrentCredit() {