diff --git a/lerna.json b/lerna.json index b129d6a4..8d8c59db 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "packages": ["packages/*"], "npmClient": "yarn", - "version": "2.13.6" + "version": "2.13.7" } diff --git a/packages/admin/package.json b/packages/admin/package.json index efa194a9..33b411a2 100644 --- a/packages/admin/package.json +++ b/packages/admin/package.json @@ -1,6 +1,6 @@ { "name": "cloudbase-cms-admin", - "version": "2.13.6", + "version": "2.13.7", "private": true, "description": "An out-of-box UI solution for enterprise applications", "scripts": { diff --git a/packages/admin/src/pages/project/operation/Message/TaskCreator.tsx b/packages/admin/src/pages/project/operation/Message/TaskCreator.tsx index 3973b570..8c2e2c82 100644 --- a/packages/admin/src/pages/project/operation/Message/TaskCreator.tsx +++ b/packages/admin/src/pages/project/operation/Message/TaskCreator.tsx @@ -1,4 +1,4 @@ -import React, { MutableRefObject, useEffect, useRef } from 'react' +import React, { MutableRefObject, useEffect, useState, useRef } from 'react' import { useRequest, history } from 'umi' import ProCard from '@ant-design/pro-card' import { PageContainer } from '@ant-design/pro-layout' @@ -40,10 +40,18 @@ interface Task { } // 短信模板 -const getMessageTemplate = (miniappName = '', content = '') => `【${ - miniappName || '小程序名称' -}】${content},跳转小程序 wxaurl.cn/xxxxxxxxxxx -回T退订` +const getMessageTemplate = (miniappName = '', content = '', miniappShortname = '') => { + let finalTempStr = `【${miniappName || '小程序名称'}】${content},跳转小程序 wxaurl.cn/xxxxxxxxxxx + 回T退订` + if (miniappName.length > 12) { + if (miniappShortname) { + finalTempStr = `【${miniappShortname}】${content},跳转小程序 wxaurl.cn/xxxxxxxxxxx + 回T退订` + } + } + + return finalTempStr +} // 号码包文件最大值:30M const MAX_FILE_SIZE = 30 * 1024 * 1024 @@ -55,6 +63,7 @@ const MessageTask: React.FC = () => { const projectId = getProjectId() const globalCtx = useConcent<{}, GlobalCtx>('global') const { setting } = globalCtx.state || {} + const [shortname, setShortname] = useState('') const [{ visible, task, activityId, sendMessageType }, setState] = useSetState({ task: {}, @@ -69,6 +78,23 @@ const MessageTask: React.FC = () => { return } + let { data } = useRequest(async () => { + let shortname = '' + try { + const data = await callWxOpenAPI('getAppBasicInfo') + shortname = data.shortname + setShortname(shortname) + } catch (e) { + console.log('获取小程序简称异常', e.message) + } + + return shortname + }) + + console.log('shortname', shortname) + + const useShortname = setting?.miniappName && setting?.miniappName.length > 12 && shortname + // 创建发送任务 const { run, loading } = useRequest( async (payload: any) => { @@ -77,6 +103,7 @@ const MessageTask: React.FC = () => { try { const result = await callWxOpenAPI('sendSms', { taskId, + useShortname: !!useShortname, }) console.log(result) @@ -191,13 +218,24 @@ const MessageTask: React.FC = () => { {() => ( <> + {useShortname && ( + <> + + {`短信签名最大支持12个字,小程序名称${setting.miniappName}超过12个字,将通过小程序简称${shortname}发送`} + +
+ + )} + 短信预览: {getMessageTemplate( setting?.miniappName, - form.getFieldValue('content') + form.getFieldValue('content'), + shortname )} +
短信内调整的短链自发送后 30 天有效 )} @@ -212,6 +250,15 @@ const MessageTask: React.FC = () => { validator: (_, value) => { const template = getMessageTemplate(setting.miniappName) + // 检查小程序名称是否超过12个字符,超过则检测是否设置过简称 + if (setting.miniappName && setting.miniappName.length > 12) { + if (!shortname) { + return Promise.reject( + `短信签名最大支持12个字,小程序名称${setting.miniappName}超过12个字,请前往设置“小程序简称”以发送短信` + ) + } + } + if (template.length + (value?.length || 0) > 70) { return Promise.reject('短信超出 70 个字符,无法发送,请精简短信内容') } @@ -369,7 +416,7 @@ const MessageTask: React.FC = () => { 共计 {task?.phoneNumberList?.length || 0} 个号码,是否创建发送任务? ) : ( - + )} @@ -389,7 +436,8 @@ const SmsFileTaskModal: React.FC<{ phoneNumberFile: any activityId: string } -}> = ({ actionRef, task = {} }) => { + useShortname: boolean +}> = ({ actionRef, task = {}, useShortname = false }) => { const projectId = getProjectId() const { phoneNumberFile, activityId } = task const [{ visible, uploadPercent }, setState] = useSetState({ @@ -469,6 +517,7 @@ const SmsFileTaskModal: React.FC<{ await callWxOpenAPI('createSendSmsTaskByFile', { fileUri, taskId, + useShortname: useShortname, }) }, { diff --git a/packages/cms-openapi/package.json b/packages/cms-openapi/package.json index 6c3ab009..63b2ee2a 100644 --- a/packages/cms-openapi/package.json +++ b/packages/cms-openapi/package.json @@ -1,6 +1,6 @@ { "name": "cloudbase-cms-openapi", - "version": "2.13.6", + "version": "2.13.7", "description": "CloudBase content manager system service restful api", "author": "cwuyiqing@gmail.com", "private": true, diff --git a/packages/cms-openapi/src/api/api.controller.ts b/packages/cms-openapi/src/api/api.controller.ts index f1710ee8..915321c5 100644 --- a/packages/cms-openapi/src/api/api.controller.ts +++ b/packages/cms-openapi/src/api/api.controller.ts @@ -51,10 +51,10 @@ export class ApiController { */ @UseGuards(PermissionGuard('operation')) @Post('sendSms') - async createSendSmsTask(@Body() body: { taskId: string }) { + async createSendSmsTask(@Body() body: { taskId: string; useShortname: boolean }) { console.log('使用 OpenAPI 发送短信') - const { taskId } = body - return this.apiService.sendSmsByNumbers(taskId) + const { taskId, useShortname = false } = body + return this.apiService.sendSmsByNumbers(taskId, useShortname) } /** @@ -136,10 +136,12 @@ export class ApiController { */ @UseGuards(PermissionGuard('operation')) @Post('createSendSmsTaskByFile') - async createSendSmsTaskByFile(@Body() body: { fileUri: string; taskId: string }) { - const { fileUri, taskId } = body + async createSendSmsTaskByFile( + @Body() body: { fileUri: string; taskId: string; useShortname: boolean } + ) { + const { fileUri, taskId, useShortname = false } = body - return this.apiService.sendSmsByFile(fileUri, taskId) + return this.apiService.sendSmsByFile(fileUri, taskId, useShortname) } /** diff --git a/packages/cms-openapi/src/api/api.service.ts b/packages/cms-openapi/src/api/api.service.ts index 65b5b298..c726bb56 100644 --- a/packages/cms-openapi/src/api/api.service.ts +++ b/packages/cms-openapi/src/api/api.service.ts @@ -65,7 +65,7 @@ export class ApiService { * 通过号码列表,发送短信 * @param taskId */ - async sendSmsByNumbers(taskId: string) { + async sendSmsByNumbers(taskId: string, useShortname: boolean) { const wxCloudApp = getWxCloudApp() const { ENV } = wxCloudApp.getWXContext() @@ -124,6 +124,7 @@ export class ApiService { urlLink: urlLink, templateParamList: [task.content], templateId: process.env.SMS_TEMPLATE_ID || '844110', + use_short_name: !!useShortname, }) // 上报短信下发任务 @@ -203,7 +204,7 @@ export class ApiService { /** * 通过号码包文件创建发送短信的任务 */ - async sendSmsByFile(fileUri: string, taskId: string) { + async sendSmsByFile(fileUri: string, taskId: string, useShortname: boolean) { const wxCloudApp = getWxCloudApp() const envId = getEnvIdString() @@ -225,6 +226,7 @@ export class ApiService { is_url_link: true, file_url: fileUri, template_id: process.env.SMS_TEMPLATE_ID || '844110', + use_short_name: useShortname, }) console.log('发送结果', result) diff --git a/sam-wx.yml b/sam-wx.yml index b4e526b1..0e622fb4 100644 --- a/sam-wx.yml +++ b/sam-wx.yml @@ -1,7 +1,7 @@ TCBSAMFormatVersion: '2020-10-20' Name: wx-ext-cms SpecVersion: v1beta -Version: 2.13.4 +Version: 2.13.5 License: Apache-2.0 Category: CloudApp DisplayName: 内容管理(CMS) @@ -19,11 +19,9 @@ IconUrl: https://main.qcloudimg.com/raw/f87b49914efe502722f9aa128f5d8865/hello_w IntroUrl: https://docs.cloudbase.net/cms/intro.html # 更新日志 ChangeLog: - - Title: 2.13.4 + - Title: 2.13.5 Content: - - 静态托管部署脚本加重试 - - 修复生成短链缺appPath问题 - - 修复营销活动中间页跳转拼接参数缺&问题 + - 短信内容支持使用小程序简称(小程序名称大于12且存在简称场景) Author: AuthorName: TCB Email: cloudbase@tencent.com @@ -60,7 +58,7 @@ Resources: Type: CloudBase::Function Properties: FunctionName: wx-ext-cms-init - CodeUri: extension://80733ff5cf07425b929c31ae677ae45b.zip + CodeUri: extension://4a752079637a413ba97f7fcb27eb2f8d.zip InstallDependency: true Description: 提供初始化应用功能,安装扩展后,会通过该函数来进行静态资源的部署和密码的生成和设置,修改账号密码或者部署路径等扩展参数都会再次执行该函数来进行更新 MemorySize: 256 @@ -116,7 +114,7 @@ Resources: Type: CloudBase::Function Properties: FunctionName: wx-ext-cms-openapi - CodeUri: extension://0b99d04447774c1e9a0732f6f206d405.zip + CodeUri: extension://04031b6d3a164757a21b1af279abbfdc.zip InstallDependency: true Description: 提供调用微信 Openapi 接口的能力 MemorySize: 2048 diff --git a/scripts/zip.sh b/scripts/zip.sh index c92a1625..d4c7c7e7 100644 --- a/scripts/zip.sh +++ b/scripts/zip.sh @@ -29,7 +29,7 @@ zipFunction() { DEST_FILE="$__ABS_PATH__/build/$1.zip" rm -rf $DEST_FILE - zip -r $DEST_FILE . -x 'node_modules/*' -x '.DS_Store' -x 'src/*' -x yarn.lock -x .env.local + zip -r $DEST_FILE . -x 'node_modules/*' -x '.DS_Store' -x 'src/*' -x yarn.lock -x .env.local -x .env.wx.local cd - }