PHP code example of alg / sms

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

    

alg / sms example snippets

$xslt
class SMSServices
{
    private $smsServices = 'lk'; //短信服务商

    private $sms; //具体发送短信的服务对象

    public function __construct()
    {
        $this->sms = App::make('sms')->get($this->smsServices);
    }

    /**
     * 发送短信方法
     *
     * @param string $phone       接受短信的手机号
     * @param string $useTemplate 使用的短信模板
     *
     * @return mixed
     */
    public function send($phone, $useTemplate = 'login')
    {
        $templateParamFuncName = $useTemplate . 'SMSTemplateParam';
        $templateParam = $this->$templateParamFuncName(); //获得模板参数

        return $this->sms->useTemplate($useTemplate)
            ->setTemplateParam($templateParam)
            ->send($phone);
    }


    /**
     * 登录短信模板参数
     *
     * @return array
     */
    public function loginSMSTemplateParam()
    {
        return [
            'code' => $this->sms::getRandCode(),
            'time' => date('i', config('sms.EXPIRE')),
            'cache_key1' => 'code' //需要被缓存的键,可以继续增加 如cache_key2...
        ];
    }

}
$xslt
$SMS::setTemplateParam(array $param)  设置模板参数 return $this