PHP code example of zacksleo / easy-sms-mw

1. Go to this page and download the library: Download zacksleo/easy-sms-mw library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zacksleo / easy-sms-mw example snippets



use Overtrue\EasySms\EasySms;
use zacksleo\easysms\Gateways\MwGateway;

$config = [
    ...
    'default' => [
        'gateways' => [
            'mw', // 配置自定义网关
        ],
    ],
    'gateways' => [
        'mw' => [
            'userId' => 'your-api-key',
            'password' => 'your-api-password',
            'pszSubPort' => 'psz-sub-port',
        ],
    ],
];

$easySms = new EasySms($config);

// 注册
$easySms->extend('mw', function($gatewayConfig){
    // $gatewayConfig 来自配置文件里的 `gateways.mygateway`
    return new MwGateway($gatewayConfig);
});

$res = $easySms->send(13188888888, [
    'content'  => '您的验证码为: 6379',
]);

if ($res['mw']['status'] == 'success') {
    throw new Exception('发送失败');
}