From 8a24a07d31931eef9161380833af9b98f9ea4194 Mon Sep 17 00:00:00 2001 From: zuohuaijun Date: Thu, 27 Mar 2025 02:22:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8E=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=8F=97=E9=99=90=E5=88=B6=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=A0=81=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Core/Admin.NET.Core.csproj | 2 +- .../Service/Wechat/Dto/WxOpenInput.cs | 13 ++- .../Service/Wechat/SysWxOpenService.cs | 81 +++++++++++++++- Web/src/api-services/apis/sys-wx-open-api.ts | 92 ++++++++++++++++++- .../models/generate-qrimage-input.ts | 2 +- .../models/generate-qrimage-un-limit-input.ts | 52 +++++++++++ Web/src/api-services/models/index.ts | 1 + Web/src/stores/userInfo.ts | 22 +---- 8 files changed, 235 insertions(+), 30 deletions(-) create mode 100644 Web/src/api-services/models/generate-qrimage-un-limit-input.ts diff --git a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj index e4a17743..0f1ea56a 100644 --- a/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj +++ b/Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj @@ -21,7 +21,7 @@ - + diff --git a/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WxOpenInput.cs b/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WxOpenInput.cs index 2dd4914c..4032b919 100644 --- a/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WxOpenInput.cs +++ b/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WxOpenInput.cs @@ -144,7 +144,7 @@ public class VerifySignatureInput } /// -/// 生成带参数小程序二维码 +/// 生成带参数小程序二维码(总共生成的码数量限制为 100,000) /// public class GenerateQRImageInput { @@ -162,4 +162,15 @@ public class GenerateQRImageInput /// 图片宽度 默认430 /// public int Width { get; set; } = 430; +} + +/// +/// 生成带参数小程序二维码(获取不受限制的小程序码) +/// +public class GenerateQRImageUnLimitInput : GenerateQRImageInput +{ + /// + /// 二维码携带的参数 eg:a=1(最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~) + /// + public string Scene { get; set; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/Wechat/SysWxOpenService.cs b/Admin.NET/Admin.NET.Core/Service/Wechat/SysWxOpenService.cs index 1f5299ab..b690ad8b 100644 --- a/Admin.NET/Admin.NET.Core/Service/Wechat/SysWxOpenService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Wechat/SysWxOpenService.cs @@ -263,11 +263,11 @@ public class SysWxOpenService : IDynamicApiController, ITransient } /// - /// 生成小程序二维码 🔖 + /// 生成带参数小程序二维码(总共生成的码数量限制为 100,000) 🔖 /// /// 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 /// - [DisplayName("生成小程序二维码")] + [DisplayName("生成带参数小程序二维码")] [ApiDescriptionSettings(Name = "GenerateQRImage")] public async Task GenerateQRImageAsync(GenerateQRImageInput input) { @@ -333,6 +333,83 @@ public class SysWxOpenService : IDynamicApiController, ITransient return generateQRImageOutInput; } + /// + /// 生成二维码(获取不受限制的小程序码) + /// + /// 入参 + /// + [DisplayName("生成小程序二维码")] + [ApiDescriptionSettings(Name = "GenerateQRImageUnlimit")] + public async Task GenerateQRImageUnlimitAsync(GenerateQRImageUnLimitInput input) + { + GenerateQRImageOutput generateQRImageOutInput = new GenerateQRImageOutput(); + if (input.PagePath.IsNullOrEmpty()) + { + generateQRImageOutInput.Message = $"生成失败,页面路径不能为空"; + return generateQRImageOutInput; + } + + if (input.Scene.Length > 32) + { + generateQRImageOutInput.Message = $"生成失败,携带的参数长度超过限制"; + return generateQRImageOutInput; + } + + if (input.ImageName.IsNullOrEmpty()) + { + input.ImageName = DateTime.Now.ToString("yyyyMMddHHmmss"); + } + + var accessToken = await GetCgibinToken(); + var request = new WxaGetWxaCodeRequest + { + AccessToken = accessToken, + Width = input.Width, + PagePath = input.PagePath, + }; + var response = await _wechatApiClient.ExecuteWxaGetWxaCodeAsync(request); + + if (response.IsSuccessful()) + { + var QRImagePath = App.GetConfig("Wechat:QRImagePath"); + var relativeImgPath = string.Empty; + + // 判断路径是绝对路径还是相对路径 + var isPathRooted = Path.IsPathRooted(QRImagePath); + if (!isPathRooted) + { + // 相对路径 + relativeImgPath = string.IsNullOrEmpty(QRImagePath) ? Path.Combine("upload", "QRImageUnLimit") : QRImagePath; + QRImagePath = Path.Combine(App.WebHostEnvironment.WebRootPath, relativeImgPath); + } + + //判断文件存放路径是否存在 + if (!Directory.Exists(QRImagePath)) + { + Directory.CreateDirectory(QRImagePath); + } + // 将二维码图片数据保存为文件 + var fileName = $"{input.ImageName.ToUpper()}.png"; + var filePath = Path.Combine(QRImagePath, fileName); + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + File.WriteAllBytes(filePath, response.GetRawBytes()); + + generateQRImageOutInput.Success = true; + generateQRImageOutInput.ImgPath = filePath; + generateQRImageOutInput.RelativeImgPath = Path.Combine(relativeImgPath, fileName); + generateQRImageOutInput.Message = "生成成功"; + } + else + { + // 处理错误情况 + generateQRImageOutInput.Message = $"生成失败 错误代码:{response.ErrorCode} 错误描述:{response.ErrorMessage}"; + } + return generateQRImageOutInput; + } + /// /// 获取Access_token /// diff --git a/Web/src/api-services/apis/sys-wx-open-api.ts b/Web/src/api-services/apis/sys-wx-open-api.ts index aeb9881e..55306722 100644 --- a/Web/src/api-services/apis/sys-wx-open-api.ts +++ b/Web/src/api-services/apis/sys-wx-open-api.ts @@ -24,6 +24,7 @@ import { AdminNETResultSysFile } from '../models'; import { AdminNETResultWxOpenIdOutput } from '../models'; import { AdminNETResultWxPhoneOutput } from '../models'; import { GenerateQRImageInput } from '../models'; +import { GenerateQRImageUnLimitInput } from '../models'; import { SendSubscribeMessageInput } from '../models'; import { SetNickNameInput } from '../models'; import { WxOpenIdLoginInput } from '../models'; @@ -83,7 +84,7 @@ export const SysWxOpenApiAxiosParamCreator = function (configuration?: Configura }, /** * - * @summary 生成小程序二维码 🔖 + * @summary 生成带参数小程序二维码(总共生成的码数量限制为 100,000) 🔖 * @param {GenerateQRImageInput} [body] 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -129,6 +130,54 @@ export const SysWxOpenApiAxiosParamCreator = function (configuration?: Configura options: localVarRequestOptions, }; }, + /** + * + * @summary 生成二维码(获取不受限制的小程序码) + * @param {GenerateQRImageUnLimitInput} [body] 入参 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + apiSysWxOpenGenerateQRImageUnlimitPost: async (body?: GenerateQRImageUnLimitInput, options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/api/sysWxOpen/generateQRImageUnlimit`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, 'https://example.com'); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication Bearer required + // http bearer authentication required + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + localVarHeaderParameter["Authorization"] = "Bearer " + accessToken; + } + + localVarHeaderParameter['Content-Type'] = 'application/json-patch+json'; + + const query = new URLSearchParams(localVarUrlObj.search); + for (const key in localVarQueryParameter) { + query.set(key, localVarQueryParameter[key]); + } + for (const key in options.params) { + query.set(key, options.params[key]); + } + localVarUrlObj.search = (new URLSearchParams(query)).toString(); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; + localVarRequestOptions.data = needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || ""); + + return { + url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash, + options: localVarRequestOptions, + }; + }, /** * * @summary 获取订阅消息模板列表 🔖 @@ -633,7 +682,7 @@ export const SysWxOpenApiFp = function(configuration?: Configuration) { }, /** * - * @summary 生成小程序二维码 🔖 + * @summary 生成带参数小程序二维码(总共生成的码数量限制为 100,000) 🔖 * @param {GenerateQRImageInput} [body] 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -645,6 +694,20 @@ export const SysWxOpenApiFp = function(configuration?: Configuration) { return axios.request(axiosRequestArgs); }; }, + /** + * + * @summary 生成二维码(获取不受限制的小程序码) + * @param {GenerateQRImageUnLimitInput} [body] 入参 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiSysWxOpenGenerateQRImageUnlimitPost(body?: GenerateQRImageUnLimitInput, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise>> { + const localVarAxiosArgs = await SysWxOpenApiAxiosParamCreator(configuration).apiSysWxOpenGenerateQRImageUnlimitPost(body, options); + return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; + return axios.request(axiosRequestArgs); + }; + }, /** * * @summary 获取订阅消息模板列表 🔖 @@ -798,7 +861,7 @@ export const SysWxOpenApiFactory = function (configuration?: Configuration, base }, /** * - * @summary 生成小程序二维码 🔖 + * @summary 生成带参数小程序二维码(总共生成的码数量限制为 100,000) 🔖 * @param {GenerateQRImageInput} [body] 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -806,6 +869,16 @@ export const SysWxOpenApiFactory = function (configuration?: Configuration, base async apiSysWxOpenGenerateQRImagePost(body?: GenerateQRImageInput, options?: AxiosRequestConfig): Promise> { return SysWxOpenApiFp(configuration).apiSysWxOpenGenerateQRImagePost(body, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary 生成二维码(获取不受限制的小程序码) + * @param {GenerateQRImageUnLimitInput} [body] 入参 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async apiSysWxOpenGenerateQRImageUnlimitPost(body?: GenerateQRImageUnLimitInput, options?: AxiosRequestConfig): Promise> { + return SysWxOpenApiFp(configuration).apiSysWxOpenGenerateQRImageUnlimitPost(body, options).then((request) => request(axios, basePath)); + }, /** * * @summary 获取订阅消息模板列表 🔖 @@ -925,7 +998,7 @@ export class SysWxOpenApi extends BaseAPI { } /** * - * @summary 生成小程序二维码 🔖 + * @summary 生成带参数小程序二维码(总共生成的码数量限制为 100,000) 🔖 * @param {GenerateQRImageInput} [body] 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages / index ? id = AY000001 * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -934,6 +1007,17 @@ export class SysWxOpenApi extends BaseAPI { public async apiSysWxOpenGenerateQRImagePost(body?: GenerateQRImageInput, options?: AxiosRequestConfig) : Promise> { return SysWxOpenApiFp(this.configuration).apiSysWxOpenGenerateQRImagePost(body, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary 生成二维码(获取不受限制的小程序码) + * @param {GenerateQRImageUnLimitInput} [body] 入参 + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SysWxOpenApi + */ + public async apiSysWxOpenGenerateQRImageUnlimitPost(body?: GenerateQRImageUnLimitInput, options?: AxiosRequestConfig) : Promise> { + return SysWxOpenApiFp(this.configuration).apiSysWxOpenGenerateQRImageUnlimitPost(body, options).then((request) => request(this.axios, this.basePath)); + } /** * * @summary 获取订阅消息模板列表 🔖 diff --git a/Web/src/api-services/models/generate-qrimage-input.ts b/Web/src/api-services/models/generate-qrimage-input.ts index f625e707..ee64b85f 100644 --- a/Web/src/api-services/models/generate-qrimage-input.ts +++ b/Web/src/api-services/models/generate-qrimage-input.ts @@ -13,7 +13,7 @@ */ /** - * 生成带参数小程序二维码 + * 生成带参数小程序二维码(总共生成的码数量限制为 100,000) * * @export * @interface GenerateQRImageInput diff --git a/Web/src/api-services/models/generate-qrimage-un-limit-input.ts b/Web/src/api-services/models/generate-qrimage-un-limit-input.ts new file mode 100644 index 00000000..77c2a27e --- /dev/null +++ b/Web/src/api-services/models/generate-qrimage-un-limit-input.ts @@ -0,0 +1,52 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Admin.NET 通用权限开发平台 + * 让 .NET 开发更简单、更通用、更流行。整合最新技术,模块插件式开发,前后端分离,开箱即用。
👮不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! + * + * OpenAPI spec version: 1.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + /** + * 生成带参数小程序二维码(获取不受限制的小程序码) + * + * @export + * @interface GenerateQRImageUnLimitInput + */ +export interface GenerateQRImageUnLimitInput { + + /** + * 扫码进入的小程序页面路径,最大长度 128 个字符,不能为空; eg: pages/index?id=0001 + * + * @type {string} + * @memberof GenerateQRImageUnLimitInput + */ + pagePath?: string | null; + + /** + * 文件保存的名称 + * + * @type {string} + * @memberof GenerateQRImageUnLimitInput + */ + imageName?: string | null; + + /** + * 图片宽度 默认430 + * + * @type {number} + * @memberof GenerateQRImageUnLimitInput + */ + width?: number; + + /** + * @type {string} + * @memberof GenerateQRImageUnLimitInput + */ + scene?: string | null; +} diff --git a/Web/src/api-services/models/index.ts b/Web/src/api-services/models/index.ts index ec5df0a9..79debd6e 100644 --- a/Web/src/api-services/models/index.ts +++ b/Web/src/api-services/models/index.ts @@ -241,6 +241,7 @@ export * from './gen-org-input'; export * from './gender-enum'; export * from './generate-qrimage-input'; export * from './generate-qrimage-output'; +export * from './generate-qrimage-un-limit-input'; export * from './generate-signature-input'; export * from './generic-parameter-attributes'; export * from './get-refund-domestic-refund-by-out-refund-number-response'; diff --git a/Web/src/stores/userInfo.ts b/Web/src/stores/userInfo.ts index 1f1a19f3..3f784ba2 100644 --- a/Web/src/stores/userInfo.ts +++ b/Web/src/stores/userInfo.ts @@ -38,20 +38,7 @@ export const useUserInfo = defineStore('userInfo', { var dictList = await getAPI(SysDictTypeApi) .apiSysDictTypeAllDictListGet() .then((res) => res.data.result ?? {}); - var dictListTemp = JSON.parse(JSON.stringify(dictList)); - - // await Promise.all( - // Object.keys(dictList).map(async (key) => { - // dictList[key].forEach((da: any, index: any) => { - // setDictLangMessageAsync(dictListTemp[key][index]); - // }); - // // 如果 key 以 "Enum" 结尾,则转换 value 为数字 - // if (key.endsWith('Enum')) { - // dictListTemp[key].forEach((e: any) => (e.value = Number(e.value))); - // } - // }) - // ); - this.dictList = dictListTemp; + this.dictList = JSON.parse(JSON.stringify(dictList)); }, // 存储用户表格列到浏览器缓存 @@ -178,10 +165,3 @@ export const useUserInfo = defineStore('userInfo', { }, }, }); - -// 处理字典国际化, 默认显示字典中的label值 -const setDictLangMessageAsync = async (dict: any) => { - dict.langMessage = `message.dictType.${dict.typeCode}_${dict.value}`; - const text = t(dict.langMessage); - dict.label = text !== dict.langMessage ? text : dict.label; -};