2017 © Pedro Peláez
 

yii2-extension yii2-alisms

阿里大于发送短信 yii2扩展

image

zc/yii2-alisms

阿里大于发送短信 yii2扩展

  • Monday, May 21, 2018
  • by davidfang
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 13 % Grown

The README.md

阿里大于发送短信 yii2扩展

阿里大于发送短信 yii2扩展, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist zc/yii2-alisms "*"

or add, (*4)

"zc/yii2-alisms": "*"

to the require section of your composer.json file., (*5)

Usage

Once the extension is installed, simply use it in your code by :, (*6)

<?= \zc\yii2Alisms\AutoloadExample::widget(); ?>

管理后台

  • 配置文件
'modules'=>[
            "sms" => [
                        "class" => "zc\yii2Alisms\Module",
                    ]
       ] 
  • 后台管理访问地址 模板 http://backend.example.dev/sms/sms-template 日志 http://backend.example.dev/sms/sms-log

前台访问

  • 配置文件
'controllerMap' => [
            'sms-api' => [
                            'class' => 'zc\yii2Alisms\controllers\ApiController',
                            'exitTime' => 300
                        ],
            ]
  • 发验证码api访问地址 http://example.dev/sms-api/get-code?mobile=15699999999&id=1&captcha=sdfwf 参数:, (*7)

    • mobile: 手机
    • id:短信模板ID
    • captcha:可选 ,在需要图形验证码的时候使用,是否需要图形验证码在后台设置

    返回:, (*8)

    • status: true,
    • code: "7025",
    • hash1: "7025",原hash
    • hash2: "7025",小写hash
    • msg: "短信发送成功"

    说明: hash1、hash2可以用于客户端的验证,验证方法参考下面, (*9)

    /** 生成方法
     * Generates a hash code that can be used for client-side validation.
     * @param string $code the CAPTCHA code
     * @return string a hash code generated from the CAPTCHA code
     * /
    public function generateValidationHash($code)
    {
        for ($h = 0, $i = strlen($code) - 1; $i >= 0; --$i) {
            $h += ord($code[$i]);
        }
    
        return $h;
    } 
    
  • 校验验证码api访问地址 (可以不用了) http://example.dev/sms-api/check-code?mobile=15699999999&code=1&id=1, (*10)

    • mobile: 手机
    • id:短信模板ID
    • code:验证码

校验验证码

在需要的model里面添加rule规则, (*11)

['code', 'required'],
            //['code', 'checkCode'],
            ['code',  function ($attribute, $params) {
                $smsType = 1;//跟前台访问验证码的id一致
                if(!\zc\yii2Alisms\Sms::checkCode($this->mobile,$this->code,$smsType)){
                    $this->addError('code','手机验证码不正确');
                    return false;
                }
            }],

The Versions

21/05 2018

dev-master

9999999-dev

阿里大于发送短信 yii2扩展

  Sources   Download

Apache-2.0

The Requires

 

extension yii2 alisms