PHP code example of sunsgne / webman-sms-send

1. Go to this page and download the library: Download sunsgne/webman-sms-send 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/ */

    

sunsgne / webman-sms-send example snippets


return [
    # 腾讯云-短信发送配置
    'tencent' => [
        'secretId'  => 'AKIDNaXEeoiLhma7NM4WhaDZeutb3E8l9G6e',
        'secretKey' => 'JL6anlSs1tUorMaXDcldEYbNt86nDMEq',
        'sdkAppId'  => '1400696413',
        'signName'  => 'BeiWorld',  //默认的短信签名
        'region'    => 'ap-guangzhou' // 默认的发送区域
    ]
];

return [
    'enable' => true,

    'sms'     => [
        # 是否发送短信
        'sendSms'            => true,
        # 验证码长度
        'length'             => 4,
        # 根据以下字符生成验证码
        'rule'               => '0123456789',
        # 默认的短信过期时间
        'expiredTime'        => 5 * 60,
        # 是否使用默认模板
        'useDefaultTemp'     => true,
        # 默认的发送模板ID
        'defaultTempId'      => 1534804,
        # 默认的地区码
        'defaultCountryCode' => '86',

    ],
    'limitIp' => [
        # 是否开启ip发送次数验证
        'enable'     => true,
        # 验证周期(24小时不能超过maxSendNum)
        'duration'   => 60 * 60 * 24,
        # 周期内最大次数
        'maxSendNum' => 10
    ]
];

use Sunsgne\WebmanSmsSend\App;
App::GetCountryCodeList()

use Sunsgne\WebmanSmsSend\App;
App::GetCountryCodeAsKeyList()

$status = App::VerifyLegalMobile('86' , '3255214');//bool

use Sunsgne\WebmanSmsSend\App;
try {
    App::SendSmsCodeByTencent(
        mobileNum: '15998908728',
        countryCode: '86',
        clientIp: $request->getRealIp(false)
    );
} catch (\RedisException|SmsAppException $e) {
    dump($e->getMessage());
}

use Sunsgne\WebmanSmsSend\App;
try {
    App::VerifyMobileCode(
        countryCode: '86',  // 国家地区编码
        mobileNum: '13012345678', //手机号码
        scenes: 'register', //发送场景
        vCode: '2154' // 验证码
    );
} catch (RedisException|SmsAppException $e) {
    //验证失败
}