Home > php教程 > PHP源码 > 使用阿里大鱼短信发送验证码

使用阿里大鱼短信发送验证码

PHP中文网
Release: 2016-05-22 17:22:30
Original
1155 people have browsed it

php代码

    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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template