|
1 |
| -## EasySMS |
| 1 | +# EasySMS |
2 | 2 |
|
3 |
| -Easy to use, simple configuration can send SMS messages to Phone. |
| 3 | +Easy to use, simple configuration can send SMS messages to Phone. |
4 | 4 | Easily expandable gateways, messages customized according to scenarios.
|
5 | 5 |
|
6 |
| -## Readmap |
| 6 | +## Installation |
7 | 7 |
|
8 |
| -- [x] Tencent Cloud SMS |
9 |
| -- [ ] Aliyun SMS |
10 |
| -- [ ] Yunpian SMS |
| 8 | +This will add a line like this to your packages `pubspec.yaml` (and run an implicit `dart pub get`): |
11 | 9 |
|
12 |
| -## Installation |
| 10 | +```yaml |
| 11 | +dependencies: |
| 12 | + easysms: latest |
| 13 | +``` |
| 14 | +
|
| 15 | +Or install it from the command line: |
13 | 16 |
|
14 |
| -```bash |
15 |
| -pub add easysms |
| 17 | +```shell |
| 18 | +dart pub add easysms |
16 | 19 | ```
|
17 | 20 |
|
| 21 | +## Features |
| 22 | + |
| 23 | +- **Gateway**: Support multiple gateways, you can customize the gateway according to your needs. |
| 24 | +- **Message**: Support multiple message templates, you can customize the message according to your needs. |
| 25 | +- **Universal**: Universal design, no need to write separate handlers for each service provider. |
| 26 | +- **Strategy**: Support gateway selection strategy. |
| 27 | +- **Retry**: Support gateway and strategy based retry mechanism. |
| 28 | + |
| 29 | +## Sponsors |
| 30 | + |
| 31 | +EasySMS is an [BSD-3 Clause licensed](LICENSE) open source project with its ongoing development made possible entirely by the support of these awesome backers. If you'd like to join them, please consider [sponsoring Odroe development](https://github.com/sponsors/odroe). |
| 32 | + |
| 33 | +<p align="center"> |
| 34 | + <a target="_blank" href="https://github.com/sponsors/odroe#sponsors"> |
| 35 | + <img alt="sponsors" src="https://github.com/odroe/.github/raw/main/sponsors.svg"> |
| 36 | + </a> |
| 37 | +</p> |
| 38 | + |
18 | 39 | ## Usage
|
19 | 40 |
|
20 | 41 | ```dart
|
21 | 42 | import 'package:easysms/easysms.dart';
|
22 | 43 |
|
23 |
| -final response = await geteway.send(phone, message); |
| 44 | +final easysms = EasySMS( |
| 45 | + gateways: [...] // Gateway list |
| 46 | +); |
| 47 | +
|
| 48 | +final message = Message.fromValues( |
| 49 | + template: '<You template ID>', |
| 50 | + data: { |
| 51 | + 'SignName': "<You sign name>", |
| 52 | + 'TemplateParamSet': [ |
| 53 | + '<Param 1>', |
| 54 | + '<Param 2>', |
| 55 | + // ... |
| 56 | + ], |
| 57 | + }, |
| 58 | +); |
| 59 | +
|
| 60 | +main() async { |
| 61 | + final phone = PhoneNumber('<You country code>', '<You phone number>'); |
| 62 | + final response = await easysms.send([phone], message); |
| 63 | +
|
| 64 | + print('Status: ${response.first.success}'); // true or false |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +## Message |
| 69 | + |
| 70 | +You can create your own scene messages based on the message: |
| 71 | + |
| 72 | +```dart |
| 73 | +import 'package:easysms/easysms.dart'; |
| 74 | +
|
| 75 | +class OneTimePasswordMessage implements Message { |
| 76 | + final String password; |
| 77 | + final Duration ttl; |
| 78 | +
|
| 79 | + OneTimePasswordMessage(this.password, this.ttl); |
| 80 | +
|
| 81 | + @override |
| 82 | + Future<Map<String, dynamic>> toData(Gateway gateway) { |
| 83 | + // ... |
| 84 | + } |
| 85 | +
|
| 86 | + @override |
| 87 | + Future<String> toTemplate(Gateway gateway) { |
| 88 | + // ... |
| 89 | + } |
| 90 | +
|
| 91 | + @override |
| 92 | + Future<String> toText(Gateway gateway) { |
| 93 | + // ... |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Built-in Message |
| 99 | + |
| 100 | +#### `formValues` |
| 101 | + |
| 102 | +```dart |
| 103 | +final message = Message.fromValues( |
| 104 | + text: '<You message text>', |
| 105 | + template: '<You template ID>', |
| 106 | + data: { |
| 107 | + // ... |
| 108 | + }, |
| 109 | +); |
| 110 | +``` |
| 111 | + |
| 112 | +#### `fromCallbacks` |
| 113 | + |
| 114 | +```dart |
| 115 | +final message = Message.fromCallbacks( |
| 116 | + text: (gateway) async => '<You message text>', |
| 117 | + template: (gateway) async => '<You template ID>', |
| 118 | + data: (gateway) async => { |
| 119 | + // ... |
| 120 | + }, |
| 121 | +); |
| 122 | +``` |
| 123 | + |
| 124 | +## Gateways |
| 125 | + |
| 126 | +| Gateway | Platform | Description | |
| 127 | +| ------------------------ | ---------------------------------------------------------- | ------------------------- | |
| 128 | +| `TencentCloudSmsGateway` | [Tencent Cloud SMS](https://cloud.tencent.com/product/sms) | Tencent Cloud SMS Gateway | |
| 129 | + |
| 130 | +**If the platform you need to use is not listed here, you have several ways to support it:** |
| 131 | + |
| 132 | +1. Create an [issue](https://github.com/odroe/easysms/issues/new) to request support for the platform. |
| 133 | +2. Create an [pull request](https://github.com/odroe/easysms/pulls) to add support for the platform. |
| 134 | +3. You can create a gateway Dart package yourself, |
| 135 | +4. You can implement the gateway yourself in your project without telling anyone. |
| 136 | + |
| 137 | +### How to create a gateway |
| 138 | + |
| 139 | +You must depend on the `easysms` package and implement the `Gateway` interface: |
| 140 | + |
| 141 | +```dart |
| 142 | +import 'package:easysms/easysms.dart'; |
| 143 | +
|
| 144 | +class MyGateway implements Gateway { |
| 145 | + @override |
| 146 | + Future<Iterable<Response>> send( |
| 147 | + Iterable<PhoneNumber> to, Message message, http.Client client) async { |
| 148 | + // ... |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +You can refer to [all the gateways](/lib/) we have implemented. |
| 154 | + |
| 155 | +## Strategies |
| 156 | + |
| 157 | +EasySMS allows you to customize the gateway selection strategy. |
| 158 | + |
| 159 | +```dart |
| 160 | +class MyStrategy implements Strategy { |
| 161 | + @override |
| 162 | + Future<Gateway> select(Iterable<Gateway> gateways) async { |
| 163 | + // ... |
| 164 | + } |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +We implemented a built-in strategy, for example, you can use the `OrderStrategy`: |
24 | 169 |
|
25 |
| -/// More see example/main.dart |
| 170 | +```dart |
| 171 | +final easysms = EasySMS( |
| 172 | + gateways: [...], |
| 173 | + strategy: const OrderStrategy(), |
| 174 | +); |
26 | 175 | ```
|
27 | 176 |
|
28 |
| -## License |
| 177 | +**Note**: The `OrderStrategy` will select the gateway in the order of the gateway list. |
| 178 | + |
| 179 | +## Contributing |
| 180 | + |
| 181 | +We welcome contributions! Please read our [contributing guide](CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to EasySMS. |
| 182 | + |
| 183 | +Thank you to all the people who already contributed to Odroe! |
| 184 | + |
| 185 | +[](https://github.com/odroe/prisma-dart/graphs/contributors) |
29 | 186 |
|
30 |
| -BSD 3-Clause License. |
| 187 | +## Stay in touch |
31 | 188 |
|
32 |
| -Copyright (c) 2021, Odroe Inc. All rights reserved. |
| 189 | +- [Website](https://odroe.com) |
| 190 | +- [Twitter](https://twitter.com/odroeinc) |
| 191 | +- [Discord](https://discord.gg/r27AjtUUbV) |
0 commit comments