Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjduan committed Jan 13, 2022
2 parents 55a5686 + 9368ee2 commit b643a4e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"npmClient": "yarn",
"version": "2.13.6"
"version": "2.13.7"
}
2 changes: 1 addition & 1 deletion packages/admin/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
65 changes: 57 additions & 8 deletions packages/admin/src/pages/project/operation/Message/TaskCreator.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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<any>({
task: {},
Expand All @@ -69,6 +78,23 @@ const MessageTask: React.FC = () => {
return <span />
}

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) => {
Expand All @@ -77,6 +103,7 @@ const MessageTask: React.FC = () => {
try {
const result = await callWxOpenAPI('sendSms', {
taskId,
useShortname: !!useShortname,
})

console.log(result)
Expand Down Expand Up @@ -191,13 +218,24 @@ const MessageTask: React.FC = () => {
<Form.Item shouldUpdate className="mb-0">
{() => (
<>
{useShortname && (
<>
<Text type="secondary">
{`短信签名最大支持12个字,小程序名称${setting.miniappName}超过12个字,将通过小程序简称${shortname}发送`}
</Text>
<br />
</>
)}

<Text type="secondary">
短信预览:
{getMessageTemplate(
setting?.miniappName,
form.getFieldValue('content')
form.getFieldValue('content'),
shortname
)}
</Text>
<br />
<Text type="secondary">短信内调整的短链自发送后 30 天有效</Text>
</>
)}
Expand All @@ -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 个字符,无法发送,请精简短信内容')
}
Expand Down Expand Up @@ -369,7 +416,7 @@ const MessageTask: React.FC = () => {
共计 {task?.phoneNumberList?.length || 0} 个号码,是否创建发送任务?
</Modal>
) : (
<SmsFileTaskModal actionRef={modalRef} task={task} />
<SmsFileTaskModal actionRef={modalRef} task={task} useShortname={!!useShortname} />
)}
</Col>
</Row>
Expand All @@ -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({
Expand Down Expand Up @@ -469,6 +517,7 @@ const SmsFileTaskModal: React.FC<{
await callWxOpenAPI('createSendSmsTaskByFile', {
fileUri,
taskId,
useShortname: useShortname,
})
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cms-openapi/package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"private": true,
Expand Down
14 changes: 8 additions & 6 deletions packages/cms-openapi/src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -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)
}

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/cms-openapi/src/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -124,6 +124,7 @@ export class ApiService {
urlLink: urlLink,
templateParamList: [task.content],
templateId: process.env.SMS_TEMPLATE_ID || '844110',
use_short_name: !!useShortname,
})

// 上报短信下发任务
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions sam-wx.yml
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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: [email protected]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
}

Expand Down

0 comments on commit b643a4e

Please sign in to comment.