New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

midway-tencent-cloud-sms

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

midway-tencent-cloud-sms - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

2

dist/config/config.default.d.ts

@@ -1,4 +0,4 @@

import { MidwayConfig } from '@midwayjs/core';
import { MidwayConfig } from "@midwayjs/core";
declare const _default: MidwayConfig;
export default _default;
//# sourceMappingURL=config.default.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
key: 'tencent-cloud-sms-default',
tencentCloudSms: {},
};
//# sourceMappingURL=config.default.js.map

@@ -1,4 +0,6 @@

export declare class TencentCloudSmsConfiguration {
onReady(): Promise<void>;
import { ILifeCycle, IMidwayContainer } from "@midwayjs/core";
export declare class TencentCloudSmsConfiguration implements ILifeCycle {
smsConfig: any;
onReady(applicationContext: IMidwayContainer): Promise<void>;
}
//# sourceMappingURL=configuration.d.ts.map

@@ -8,20 +8,43 @@ "use strict";

};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TencentCloudSmsConfiguration = void 0;
// src/components/book/src/bookConfiguration.ts
const core_1 = require("@midwayjs/core");
const DefaultConfig = require("./config/config.default");
const sms_client_1 = require("tencentcloud-sdk-nodejs-sms/tencentcloud/services/sms/v20210111/sms_client");
const defaultConfig = require("./config/config.default");
let TencentCloudSmsConfiguration = class TencentCloudSmsConfiguration {
async onReady() {
// ...
async onReady(applicationContext) {
console.log("TencentCloudSmsConfiguration:onReady", this.smsConfig);
const client = new sms_client_1.Client({
credential: {
secretId: this.smsConfig.secretId,
secretKey: this.smsConfig.secretKey,
},
region: this.smsConfig.region,
profile: {
signMethod: "HmacSHA256",
httpProfile: {
reqMethod: "POST",
reqTimeout: 30,
endpoint: "sms.tencentcloudapi.com",
},
},
});
applicationContext.registerObject("tencentCloudSmsClient", client);
}
};
__decorate([
(0, core_1.Config)("tencentCloudSms"),
__metadata("design:type", Object)
], TencentCloudSmsConfiguration.prototype, "smsConfig", void 0);
TencentCloudSmsConfiguration = __decorate([
(0, core_1.Configuration)({
namespace: "tencent-cloud-sms",
namespace: "tencentCloudSms",
importConfigs: [
{
default: DefaultConfig
}
]
default: defaultConfig,
},
],
})

@@ -28,0 +51,0 @@ ], TencentCloudSmsConfiguration);

@@ -0,1 +1,9 @@

export interface TencentCloudSmsConfig {
secretId: string;
secretKey: string;
region: string;
SmsSdkAppId: string;
SignName: string;
TemplateId: string;
}
export interface ISendSmsParam {

@@ -2,0 +10,0 @@ SmsSdkAppId: string;

@@ -0,5 +1,7 @@

import { Client } from "tencentcloud-sdk-nodejs-sms/tencentcloud/services/sms/v20210111/sms_client";
import { TencentCloudSmsConfig } from "../interface";
export declare class SmsService {
sendSms(): Promise<{
data: string;
}>;
smsConfig: TencentCloudSmsConfig;
client: Client;
sendSms(code: string, phone: string): Promise<import("tencentcloud-sdk-nodejs-sms/tencentcloud/services/sms/v20210111/sms_models").SendSmsResponse>;
pullSmsSendStatus(): Promise<void>;

@@ -6,0 +8,0 @@ sendStatusStatistics(): Promise<void>;

@@ -8,18 +8,53 @@ "use strict";

};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmsService = void 0;
const core_1 = require("@midwayjs/core");
const sms_client_1 = require("tencentcloud-sdk-nodejs-sms/tencentcloud/services/sms/v20210111/sms_client");
let SmsService = class SmsService {
async sendSms() {
return {
data: "hello world",
async sendSms(code, phone) {
if (!this.client) {
console.warn("client not exit");
return;
}
if (!this.smsConfig) {
console.warn("config is not correact");
return;
}
const params = {
SmsSdkAppId: this.smsConfig.SmsSdkAppId,
/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
// 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
SignName: this.smsConfig.SignName,
/* 模板 ID: 必须填写已审核通过的模板 ID */
// 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
TemplateId: this.smsConfig.TemplateId,
/* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
TemplateParamSet: [code],
/* 下发手机号码,采用 e.164 标准,+[国家或地区码][手机号]
* 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
PhoneNumberSet: [`+86${phone}`],
/* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
SessionContext: "",
/* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
ExtendCode: "",
/* 国际/港澳台短信 senderid(无需要可忽略): 国内短信填空,默认未开通,如需开通请联系 [腾讯云短信小助手] */
SenderId: "",
};
return this.client.SendSms(params);
}
async pullSmsSendStatus() {
}
async sendStatusStatistics() {
}
async addSmsTemplate() {
}
async pullSmsSendStatus() { }
async sendStatusStatistics() { }
async addSmsTemplate() { }
};
__decorate([
(0, core_1.Config)("tencentCloudSms"),
__metadata("design:type", Object)
], SmsService.prototype, "smsConfig", void 0);
__decorate([
(0, core_1.Inject)("tencentCloudSmsClient"),
__metadata("design:type", sms_client_1.Client)
], SmsService.prototype, "client", void 0);
SmsService = __decorate([

@@ -26,0 +61,0 @@ (0, core_1.Provide)()

@@ -5,3 +5,3 @@ export * from './dist/index';

interface MidwayConfig {
tencentCloudSms?: PowerPartial<{
tencentCloudSms: {
secretId: string;

@@ -13,4 +13,4 @@ secretKey: string;

TemplateId:string;
}>;
};
}
}
{
"name": "midway-tencent-cloud-sms",
"version": "0.0.1",
"version": "0.1.0",
"description": "midwayjs tencent cloud sms component",

@@ -40,3 +40,13 @@ "main": "dist/index.js",

"typescript": "~4.8.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wflixu/midway-tencent-cloud-sms.git"
},
"peerDependencies": {
"@midwayjs/core": "^3.0.0"
},
"dependencies": {
"tencentcloud-sdk-nodejs-sms": "^4.0.586"
}
}
# midway-tencent-cloud-sms midway 腾讯云短信组件
封装 tencentcloud-sdk-nodejs-sms 成组件,命名空间是 tencentCloudSms
# 使用
## 安装
```
npm i midway-tencent-cloud-sms
```
## 配置
在 config/\* 中配置
```
tencentCloudSms: {
secretId: '',//
secretKey: '',
region: '',
SmsSdkAppId: '',
TemplateId: '',
SignName: '',
},
```
具体配置的含义,请
[参考腾讯云文档](https://cloud.tencent.com/document/product/382/43197)
## Controller 中使用
```
// 引入
import { SmsService } from 'midway-tencent-cloud-sms';
class SomeController {
// 注入
@Inject()
smsService: SmsService;
@Post('/sms')
async sms(@Body('phone') phone: string) {
const code = _.random(100000, 999999);
// 使用
const res = await this.smsService.sendSms(code.toString(), phone);
this.ctx.logger.info('sms', phone, res);
}
}
```
# 贡献
👏 欢迎提 issue 或 pr
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc