# NestJS 云之讯短信服务集成插件

注意：<font color="#dd0000">仍在开发中，目前仅在内部使用</font><br /> 

* v2.x 文档待完善
* [v1.x 文档地址](https://docs.iot9x.com/docs/nestjs/8/%E4%BA%91%E4%B9%8B%E8%AE%AF%E5%B9%B3%E5%8F%B0/%E7%9F%AD%E4%BF%A1/)
* [v0.x 文档地址](https://docs.iot9x.com/docs/nestjs/8/%E4%BA%91%E4%B9%8B%E8%AE%AF%E5%B9%B3%E5%8F%B0/%E7%9F%AD%E4%BF%A1/)

## 支持环境

|版本|对应nestjs版本|云之讯平台|
|-----|-----|-----|
| `v0.x` | `v8.x` |旧版（2023年4月30日停止使用）|
| `v1.x` | `v9.x` |旧版（2023年4月30日停止使用）|
| `v2.x` | `v9.x` |新版|

## 安装

```shell
$ npm i @iot9x.com/nestjs-ucpaas-sms

or
$ yarn add @iot9x.com/nestjs-ucpaas-sms

or
$ pnpm add @iot9x.com/nestjs-ucpaas-sms  # 推荐使用pnpm
```

## 配置

### 同步方式

```typescript
import { Module } from '@nestjs/common';
import { UcpaasModule } from '@iot9x.com/nestjs-ucpaas-sms'

@Module({
  imports: [
    UcpaasModule.forRoot({
      clientid: '云之讯平台账户', 
      password: '云之讯平台密码'
    })
  ]
})
export class AppModule { }
```

### 异步方式

```typescript
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigType } from '@nestjs/config';
import { UcpaasModule } from '../src';
import { TestRegister } from './modules/config/registers/test.register';
import { UcpaasRegister } from './modules/config/registers/ucpaas.register';
import { ConfigValidation } from './modules/config/validations/config.validation';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      validationSchema: ConfigValidation,
      validationOptions: {
        allowUnknown: true,
        abortEarly: true
      },
      load: [UcpaasRegister, TestRegister]
    }),
    UcpaasModule.forRootAsync({
      useFactory: (ucpaasConfig: ConfigType<typeof UcpaasRegister>) => ({
        clientid: ucpaasConfig.clientid,
        password: ucpaasConfig.password
      }),
      inject: [UcpaasRegister.KEY]
    })
  ]
})
export class AppModule {}

```

## 文档地址

* v2.x 文档待完善
* [v1.x 文档地址](https://docs.iot9x.com/docs/nestjs/8/%E4%BA%91%E4%B9%8B%E8%AE%AF%E5%B9%B3%E5%8F%B0/%E7%9F%AD%E4%BF%A1/)
* [v0.x 文档地址](https://docs.iot9x.com/docs/nestjs/8/%E4%BA%91%E4%B9%8B%E8%AE%AF%E5%B9%B3%E5%8F%B0/%E7%9F%AD%E4%BF%A1/)
