Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wenHuaBu_adminServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
wenHuaBu_adminServer
Commits
005d41e4
Commit
005d41e4
authored
Mar 31, 2024
by
lixinming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
76f7a4ee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
41 deletions
+42
-41
user.ts
src/biz/member/user.ts
+6
-2
register.ts
src/biz/register.ts
+5
-2
sms.ts
src/biz/sms.ts
+23
-31
errorEnum.ts
src/config/errorEnum.ts
+4
-1
main.ts
src/main.ts
+4
-5
No files found.
src/biz/member/user.ts
View file @
005d41e4
...
...
@@ -11,6 +11,7 @@ import { updateOneData } from "../../data/update";
import
{
generateSMSCode
,
generateToken
,
getTodayMs
,
successResult
}
from
"../../tools/system"
;
import
{
BizError
}
from
"../../util/bizError"
;
import
{
changeEnumValue
}
from
"../../util/verificationEnum"
;
import
{
sendALSMS
}
from
"../sms"
;
...
...
@@ -106,6 +107,8 @@ export async function changePwd({phone, pwd, confirmation, code}) {
* @returns
*/
export
async
function
memberChangePwdSendCode
({
phone
})
{
let
userInfo
=
await
findOnce
(
TABLEENUM
.
用户表
,
{
phone
},
[
"userId"
]);
if
(
!
userInfo
&&
!
userInfo
.
userId
)
throw
new
BizError
(
ERRORENUM
.
不存在该手机号的账号
);
const
NowMs
=
new
Date
().
valueOf
();
let
codeSelectParam
=
{
phone
,
isUse
:
false
,
type
:
CODETYPE
.
修改密码
,
sendMs
:{
"$gt"
:
getTodayMs
()}
}
let
lastCodeInfo
=
await
findOnceToSort
(
TABLEENUM
.
验证码表
,
codeSelectParam
,
{
sendMs
:
-
1
});
...
...
@@ -120,9 +123,9 @@ export async function memberChangePwdSendCode({phone}) {
const
Code
=
generateSMSCode
();
//生成短信验证码
/**发送短信模块 */
await
sendALSMS
(
Code
,
phone
);
let
addInfo
=
{
codeNum
:
Code
,
phone
,
sendMs
:
NowMs
,
type
:
CODETYPE
.
修改密码
,
isUse
:
false
};
await
addOneData
(
TABLEENUM
.
验证码表
,
addInfo
);
return
{
code
:
Code
};
return
{
code
:
""
};
}
\ No newline at end of file
src/biz/register.ts
View file @
005d41e4
...
...
@@ -14,6 +14,7 @@ import { BizError } from "../util/bizError";
import
{
extractData
}
from
"../util/piecemeal"
;
import
{
changeEnumValue
,
eccEnumValue
}
from
"../util/verificationEnum"
;
import
{
eccFormParam
}
from
"../util/verificationParam"
;
import
{
sendALSMS
}
from
"./sms"
;
/**
...
...
@@ -271,6 +272,8 @@ export async function registerFlowType({id}) {
* @returns
*/
export
async
function
memberRegisterSendCode
({
phone
})
{
let
userInfo
=
await
findOnce
(
TABLEENUM
.
用户表
,
{
phone
},
[
"userId"
]);
if
(
userInfo
&&
userInfo
.
userId
)
throw
new
BizError
(
ERRORENUM
.
该手机号已被注册
);
const
NowMs
=
new
Date
().
valueOf
();
let
codeSelectParam
=
{
phone
,
isUse
:
false
,
type
:
CODETYPE
.
用户注册
,
sendMs
:{
"$gt"
:
sysTools
.
getTodayMs
()}
}
let
lastCodeInfo
=
await
findOnceToSort
(
TABLEENUM
.
验证码表
,
codeSelectParam
,
{
sendMs
:
-
1
});
...
...
@@ -285,11 +288,11 @@ export async function memberRegisterSendCode({phone}) {
const
Code
=
sysTools
.
generateSMSCode
();
//生成短信验证码
/**发送短信模块 */
await
sendALSMS
(
Code
,
phone
);
let
addInfo
=
{
codeNum
:
Code
,
phone
,
sendMs
:
NowMs
,
type
:
CODETYPE
.
用户注册
,
isUse
:
false
};
await
addOneData
(
TABLEENUM
.
验证码表
,
addInfo
);
return
{
code
:
Code
};
return
{
code
:
""
};
}
...
...
src/biz/sms.ts
View file @
005d41e4
// This file is auto-generated, don't edit it
import
{
ERRORENUM
}
from
"../config/errorEnum"
;
import
{
BizError
}
from
"../util/bizError"
;
// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
const
Dypnsapi20170525
=
require
(
'@alicloud/dypnsapi20170525'
);
const
OpenApi
=
require
(
'@alicloud/openapi-client'
);
...
...
@@ -8,18 +12,7 @@ const Tea = require('@alicloud/tea-typescript');
let
smsClient
;
function
initSMS
()
{}
class
Client
{
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
static
createClient
()
{
export
async
function
initSMS
()
{
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378664.html。
let
config
=
new
OpenApi
.
Config
({
...
...
@@ -30,27 +23,27 @@ class Client {
});
// Endpoint 请参考 https://api.aliyun.com/product/Dypnsapi
config
.
endpoint
=
`dypnsapi.aliyuncs.com`
;
return
new
Dypnsapi20170525
.
default
(
config
);
}
smsClient
=
new
Dypnsapi20170525
.
default
(
config
);
}
static
async
main
(
args
)
{
let
client
=
Client
.
createClient
();
let
sendSmsVerifyCodeRequest
=
new
Dypnsapi20170525
.
SendSmsVerifyCodeRequest
({
});
let
runtime
=
new
Util
.
RuntimeOptions
({
});
export
async
function
sendALSMS
(
code
:
string
,
phone
:
string
)
{
try
{
// 复制代码运行请自行打印 API 的返回值
await
client
.
sendSmsVerifyCodeWithOptions
(
sendSmsVerifyCodeRequest
,
runtime
);
}
catch
(
error
)
{
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
console
.
log
(
error
.
message
);
// 诊断地址
console
.
log
(
error
.
data
[
"Recommend"
]);
/**先生成request */
let
requstParam
=
new
Dypnsapi20170525
.
SendSmsVerifyCodeRequest
({
phoneNumber
:
phone
,
signName
:
'中国艺术职业教育学会'
,
templateCode
:
'SMS_296230597'
,
templateParam
:
`{"code":"
${
code
}
"}`
,
// templateParam:code
});
//发起调用
let
runtime
=
new
Util
.
RuntimeOptions
({});
const
resp
=
await
smsClient
.
sendSmsVerifyCodeWithOptions
(
requstParam
,
runtime
);
}
catch
(
err
)
{
throw
new
BizError
(
ERRORENUM
.
短信验证码发送失败
,
err
);
}
}
}
exports
.
Client
=
Client
;
Client
.
main
(
process
.
argv
.
slice
(
2
));
\ No newline at end of file
src/config/errorEnum.ts
View file @
005d41e4
...
...
@@ -47,7 +47,10 @@ export enum ERRORENUM {
支付失败
,
地址数据错误
,
该账号已被冻结
,
手机号不正确
手机号不正确
,
短信验证码发送失败
,
该手机号已被注册
,
不存在该手机号的账号
}
export
enum
ERRORCODEENUM
{
...
...
src/main.ts
View file @
005d41e4
import
{
initAdmin
}
from
"./biz/member/rightsMgmt"
;
import
{
initSMS
}
from
"./biz/sms"
;
import
{
initSystemTask
}
from
"./biz/task"
;
import
{
initConfig
,
systemConfig
}
from
"./config/serverConfig"
;
import
{
initDataBaseModel
}
from
"./data/db/db"
;
...
...
@@ -12,13 +13,11 @@ async function lanuch() {
await
initDataBaseModel
();
/**创建http服务 */
httpServer
.
createServer
(
systemConfig
.
port
);
// await smsTask();
console
.
log
(
'This indicates that the server is started successfully.'
);
// await initAdmin
();
// await test1
();
await
initSMS
();
await
initAdmin
();
await
initSystemTask
();
// await initOrderData()
console
.
log
(
"服务初始化成功"
);
}
lanuch
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment