Commit 005d41e4 by lixinming

no message

parent 76f7a4ee
......@@ -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
......@@ -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:""};
}
......
// 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,49 +12,38 @@ 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({
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
accessKeyId: 'LTAI5tD7Finu3fxFMCi3415S',
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
accessKeySecret: 'sbPR0AdDPfjm7v2NSffk5apPm6UClV',
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
accessKeyId: 'LTAI5tD7Finu3fxFMCi3415S',
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
accessKeySecret: 'sbPR0AdDPfjm7v2NSffk5apPm6UClV',
});
// 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({ });
try {
// 复制代码运行请自行打印 API 的返回值
await client.sendSmsVerifyCodeWithOptions(sendSmsVerifyCodeRequest, runtime);
} catch (error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
console.log(error.message);
// 诊断地址
console.log(error.data["Recommend"]);
}
}
export async function sendALSMS(code:string, phone:string ) {
try {
/**先生成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
......@@ -47,7 +47,10 @@ export enum ERRORENUM {
支付失败,
地址数据错误,
该账号已被冻结,
手机号不正确
手机号不正确,
短信验证码发送失败,
该手机号已被注册,
不存在该手机号的账号
}
export enum ERRORCODEENUM {
......
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();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment