From 9d90b9910528d22728796a942f382d378d0357d9 Mon Sep 17 00:00:00 2001 From: COOL Date: Mon, 30 Dec 2024 18:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AA=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/user/service/sms.ts | 5 ++++- src/modules/user/service/wx.ts | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/modules/user/service/sms.ts b/src/modules/user/service/sms.ts index 47a22cf..561d4ec 100644 --- a/src/modules/user/service/sms.ts +++ b/src/modules/user/service/sms.ts @@ -50,7 +50,10 @@ export class UserSmsService extends BaseService { // 随机四位验证码 const code = _.random(1000, 9999); const pluginKey = this.config.pluginKey; - if (!this.plugin) throw new CoolCommException('未配置短信插件'); + if (!this.plugin) + throw new CoolCommException( + '未配置短信插件,请到插件市场下载安装配置:https://cool-js.com/plugin?keyWord=短信' + ); try { if (pluginKey == 'sms-tx') { await this.plugin.send([phone], [code]); diff --git a/src/modules/user/service/wx.ts b/src/modules/user/service/wx.ts index 999efa7..7e126db 100644 --- a/src/modules/user/service/wx.ts +++ b/src/modules/user/service/wx.ts @@ -27,12 +27,27 @@ export class UserWxService extends BaseService { @Inject() pluginService: PluginService; + /** + * 获得插件实例 + * @returns + */ + async getPlugin() { + try { + const wxPlugin: any = await this.pluginService.getInstance('wx'); + return wxPlugin; + } catch (error) { + throw new CoolCommException( + '未配置微信插件,请到插件市场下载安装配置:https://cool-js.com/plugin/70' + ); + } + } + /** * 获得小程序实例 * @returns */ async getMiniApp() { - const wxPlugin: any = await this.pluginService.getInstance('wx'); + const wxPlugin: any = await this.getPlugin(); return wxPlugin.MiniApp(); } @@ -41,7 +56,7 @@ export class UserWxService extends BaseService { * @returns */ async getOfficialAccount() { - const wxPlugin: any = await this.pluginService.getInstance('wx'); + const wxPlugin: any = await this.getPlugin(); return wxPlugin.OfficialAccount(); } @@ -50,7 +65,7 @@ export class UserWxService extends BaseService { * @returns */ async getOpenPlatform() { - const wxPlugin: any = await this.pluginService.getInstance('wx'); + const wxPlugin: any = await this.getPlugin(); return wxPlugin.OpenPlatform(); }