Home > php教程 > PHP源码 > Use Alibaba Dayu SMS to send verification code

Use Alibaba Dayu SMS to send verification code

大家讲道理
Release: 2016-11-08 13:22:23
Original
1843 people have browsed it

public function index()
{
    $client  = new Client;
    $request = new SmsNumSend;
 
    // 短信内容参数
    $smsParams = [
        'code'    => $this->randString(),
        'product' => '测试的'
    ];
 
    // 设置请求参数,具体参数可以参考官方文档
    $req = $request->setSmsTemplateCode('SMS_6620027')
        ->setRecNum('18600000000')
        ->setSmsParam(json_encode($smsParams))
        ->setSmsFreeSignName('注册验证')
        ->setSmsType('normal')
        ->setExtend('123456');
 
    print_r($client->execute($req));
}
 
/**
 * 获取随机位数数字
 * @param  integer $len 长度
 * @return string      
 */
protected static function randString($len = 6)
{
    $chars = str_repeat('0123456789', $len);
    $chars = str_shuffle($chars);
    $str   = substr($chars, 0, $len);
    return $str;
}
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template