# egg-tencent-cloud **Repository Path**: axolo/egg-tencent-cloud ## Basic Information - **Project Name**: egg-tencent-cloud - **Description**: Tencent Cloud SDK4.x plugin for Egg.js. - **Primary Language**: NodeJS - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-01 - **Last Updated**: 2022-05-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # egg-tencent-cloud [腾讯云 SDK] 4.x Egg.js 插件。 ## 安装 ```bash npm i @axolo/egg-tencent-cloud --save ``` ## 开启插件 ```js // config/plugin.js exports.tencentCloud = { enable: true, package: '@axolo/egg-tencent-cloud', }; ``` ## 详细配置 请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。 例如: ```js // {app_root}/config/config.default.js exports.tencentCloud = { client: { // tencentCloud, // 指定tencentcloud-sdk-nodejs // region: 'ap-guangzhou', // reqMethod: 'POST', // reqTimeout: 60, // signMethod: 'HmacSHA256', secretId: 'SECRET_ID', secretKey: 'SECRETK_EY', model: 'sms', version: 'v20190711', action: 'SendStatusStatistics', params: { SmsSdkAppid: 'SMS_SDK_APPID', Limit: 0, Offset: 0, }, }; ``` ## API ### client 腾讯云`Model`客户端。使用示例: ```js 'use strict'; const Controller = require('egg').Controller; class TencentCloudController extends Controller { async index() { const { app, ctx } = this; const smsCount = app.tencentCloud.get('smsCount'); const result = await smsCount.client.SmsPackagesStatistics({ ...smsCount.options.params, Limit: 10, }); ctx.body = result; } } module.exports = TencentCloudController; ``` ### action(params) > 参数 | 参数 | 类型 | 说明 | | ------ | ------ | ---------------------- | | params | object | 腾讯云产品`Action`参数 | > 返回 腾讯云产品`Action`请求结果,`Promise`类型。 ## 使用示例 ```js 'use strict'; const dayjs = require('dayjs'); const Controller = require('egg').Controller; class TencentCloudController extends Controller { async index() { const { app, ctx } = this; const smsCount = app.tencentCloud.get('smsCount'); const now = dayjs(); const lastMonth = now.subtract(1, 'months'); const StartDateTime = lastMonth.format('YYYYMMDDhh'); const EndDataTime = now.format('YYYYMMDDhh'); const result = await smsCount.action({ StartDateTime, EndDataTime }); ctx.body = result; } } module.exports = TencentCloudController; ``` ## 提问交流 请到 [egg issues](https://github.com/axolo/egg-tencent-cloud/issues) 异步交流。 ## License [MIT](LICENSE) [腾讯云 SDK]: https://cloud.tencent.com/document/sdk/Node.js