Easy to use, simple configuration can send SMS messages to Phone. Easily expandable gateways, messages customized according to scenarios.
This will add a line like this to your packages pubspec.yaml
(and run an implicit dart pub get
):
dependencies:
easysms: latest
Or install it from the command line:
dart pub add easysms
- Gateway: Support multiple gateways, you can customize the gateway according to your needs.
- Message: Support multiple message templates, you can customize the message according to your needs.
- Universal: Universal design, no need to write separate handlers for each service provider.
- Strategy: Support gateway selection strategy.
- Retry: Support gateway and strategy based retry mechanism.
EasySMS is an BSD-3 Clause licensed 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.
import 'package:easysms/easysms.dart';
final easysms = EasySMS(
gateways: [...] // Gateway list
);
final message = Message.fromValues(
template: '<You template ID>',
data: {
'SignName': "<You sign name>",
'TemplateParamSet': [
'<Param 1>',
'<Param 2>',
// ...
],
},
);
main() async {
final phone = PhoneNumber('<You country code>', '<You phone number>');
final response = await easysms.send([phone], message);
print('Status: ${response.first.success}'); // true or false
}
You can create your own scene messages based on the message:
import 'package:easysms/easysms.dart';
class OneTimePasswordMessage implements Message {
final String password;
final Duration ttl;
OneTimePasswordMessage(this.password, this.ttl);
@override
Future<Map<String, dynamic>> toData(Gateway gateway) {
// ...
}
@override
Future<String> toTemplate(Gateway gateway) {
// ...
}
@override
Future<String> toText(Gateway gateway) {
// ...
}
}
final message = Message.fromValues(
text: '<You message text>',
template: '<You template ID>',
data: {
// ...
},
);
final message = Message.fromCallbacks(
text: (gateway) async => '<You message text>',
template: (gateway) async => '<You template ID>',
data: (gateway) async => {
// ...
},
);
Gateway | Platform | Description |
---|---|---|
TencentCloudSmsGateway |
Tencent Cloud SMS | Tencent Cloud SMS gateway |
SmsBaoGateway |
短信宝 | 短信宝 SMS gateway |
If the platform you need to use is not listed here, you have several ways to support it:
- Create an issue to request support for the platform.
- Create an pull request to add support for the platform.
- You can create a gateway Dart package yourself,
- You can implement the gateway yourself in your project without telling anyone.
You must depend on the easysms
package and implement the Gateway
interface:
import 'package:easysms/easysms.dart';
class MyGateway implements Gateway {
@override
Future<Iterable<Response>> send(
Iterable<PhoneNumber> to, Message message, http.Client client) async {
// ...
}
}
You can refer to all the gateways we have implemented.
EasySMS allows you to customize the gateway selection strategy.
class MyStrategy implements Strategy {
@override
Future<Gateway> select(Iterable<Gateway> gateways) async {
// ...
}
}
We implemented a built-in strategy, for example, you can use the OrderStrategy
:
final easysms = EasySMS(
gateways: [...],
strategy: const OrderStrategy(),
);
Note: The OrderStrategy
will select the gateway in the order of the gateway list.
We welcome contributions! Please read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to EasySMS.
Thank you to all the people who already contributed to Odroe!