Skip to content

📲 一款满足你的多种发送需求的短信发送组件

Notifications You must be signed in to change notification settings

loktarjugg/easy-sms

 
 

Repository files navigation

Easy SMS

📲 一款满足你的多种发送需求的短信发送组件

Build Status Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Code Coverage Total Downloads License

环境需求

  • PHP >= 5.6

安装

$ composer require "overtrue/easy-sms"

使用

use Overtrue\EasySms\EasySms;

$config = [
    'timeout' => 5.0,
    'default' => [
        'gateways' => [
            'yunpian', 'alidayu',
        ],
    ],
    'gateways' => [
        'errorlog' => [
            'file' => '/tmp/easy-sms.log',
        ],
        'yunpian' => [
            'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
        ],
        'alidayu' => [
            //...
        ],
    ],
];

$easySms = new EasySms($config);
$easySms->send(13188888888, 'hello world!');

定义短信

你可以根本发送场景的不同,定义不同的短信类,从而实现一处定义多处调用,你可以继承 Overtrue\EasySms\Message 来定义短信模型:

<?php

use Overtrue\EasySms\Message;

class OrderPaidMessage extends Messeage
{
    protected $order;
    protected $gateways = ['alidayu', 'yunpian']; // 定义本短信的适用平台,覆盖全局配置中的 `enabled_gateways`

    public function __construct($order)
    {
        $this->order = $order;
    }
        
    // 定义直接使用内容发送平台的内容
    public function getContent()
    {
        return sprintf('您的订单:%s, 已经完成付款', $this->order->no);    
    }
    
    // 定义使用模板发送方式平台所需要的模板 ID
    public function getTemplate()
    {
        return 'SMS_003'; 
    }
        
    // 模板参数
    public function getData()
    {
        return [
            'order_no' => $this->order->no    
        ];    
    }
}

更多自定义方式请参考:Overtrue\EasySms\Message

发送自定义短信:

$order = ...;
$message = new OrderPaidMessage($order);

$easySms->send(13188888888, $message);

平台支持

License

MIT

About

📲 一款满足你的多种发送需求的短信发送组件

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%