PHP Class Toplan\Sms\SmsManager

Show file Open project: toplan/laravel-sms Class Usage Examples

Protected Properties

Property Type Description
$input array 客户端数据
$state array 发送状态
$storage Toplan\Sms\Storage 存储器
$token string | null Access Token

Public Methods

Method Description
__construct ( string | null $token = null, array $input = [] ) Constructor
forgetRule ( string $field, string | null $name = null ) 从存储器中删除指定字段的指定名称的动态验证规则
forgetRules ( string $field ) : array 从存储中获取指定字段的所有验证规则
forgetState ( ) 从存储器中删除发送状态
generateResult ( boolean $pass, string $type, string $message = '', array $data = [] ) : array 合成结果数组
getCanResendTime ( ) : integer 从存储器中获取可再次发送的截止时间
input ( string | integer | null $key = null, mixed $default = null ) : mixed 获取客户端数据
pathOfUrl ( string $url, Closure $onError = null ) : string 获取路径中的path部分
requestVerifySms ( ) : array 请求验证码短信
requestVoiceVerify ( ) : array 请求语音验证码
retrieveAllData ( ) : array 从存储器中获取用户的所有数据
retrieveRule ( string $field, string | null $name = null ) : string | null 从存储器中获取指定字段的指定名称的动态验证规则
retrieveRules ( string $field ) : array 从存储中获取指定字段的所有验证规则
retrieveState ( string | null $name = null ) : array 从存储器中获取发送状态
setCanResendAfter ( integer $interval ) : integer 设置多少秒后才能再次请求
state ( string | integer | null $key = null, mixed $default = null ) : mixed 获取当前的发送状态(非持久化的)
storeRule ( string $field, string $name, string | null $rule = null ) 存储指定字段的指定名称的动态验证规则
updateState ( string | array $name, mixed $value = null ) 更新发送状态
validateFields ( mixed $input = null, Closure $validation = null ) : array 验证数据
validateSendable ( ) : array 验证是否可发送
vsprintf ( string $template, array $data, Closure $onError = null ) : string 根据模版和数据合成字符串

Protected Methods

Method Description
generateCode ( integer | null $length = null, string | null $characters = null ) : string 根据配置文件中的长度生成验证码
generateKey ( ) : string 生成key
generateSmsContent ( string $code, integer $minutes ) : string 生成验证码短信通用内容
generateTemplateData ( string $code, integer $minutes, string $type ) : array 生成模版数据
getCodeValidMinutes ( ) : integer 从配置文件获取验证码有效时间(分钟)
getFields ( ) : array 获取可验证的字段
getInterval ( ) : integer 从配置文件获取可再次请求的最小时间间隔(秒)
getMobileField ( ) : string 获取手机号的字段名
getNameOfDefaultStaticRule ( string $field ) : string 获取指定字段的默认静态规则的名称
getNotifyMessage ( string $name ) : string 从配置文件获取提示信息
getRealRuleByName ( string $field, string $ruleName ) : string 根据规则名获取真实的验证规则
getStaticRule ( $field, $ruleName ) : string | null 获取指定字段的指定名称的静态验证规则
getStorageClassName ( ) : string 获取存储器类名
getTemplatesByKey ( string $key ) : array 从配置信息中获取指定键名的所有模版id
getValidationConfigByField ( string $field ) : array 获取验证配置
reset ( ) 重置发送状态
storage ( ) : Toplan\Sms\Storage 获取存储器
storeState ( ) 存储发送状态
useRule ( string $field, string $name ) 设置指定字段使用的验证规则名称
usedRule ( string $field ) : string 获取设置指定字段使用的验证规则名称
validateFieldName ( $name ) 检查字段名称是否合法
verifyCode ( ) : string 生成待发生的验证码
whetherValidateFiled ( string $field ) : boolean 是否检查指定的数据

Method Details

__construct() public method

Constructor
public __construct ( string | null $token = null, array $input = [] )
$token string | null
$input array

forgetRule() public method

从存储器中删除指定字段的指定名称的动态验证规则
public forgetRule ( string $field, string | null $name = null )
$field string
$name string | null

forgetRules() public method

从存储中获取指定字段的所有验证规则
public forgetRules ( string $field ) : array
$field string
return array

forgetState() public method

从存储器中删除发送状态
public forgetState ( )

generateCode() protected static method

根据配置文件中的长度生成验证码
protected static generateCode ( integer | null $length = null, string | null $characters = null ) : string
$length integer | null
$characters string | null
return string

generateKey() protected method

生成key
protected generateKey ( ) : string
return string

generateResult() public static method

合成结果数组
public static generateResult ( boolean $pass, string $type, string $message = '', array $data = [] ) : array
$pass boolean
$type string
$message string
$data array
return array

generateSmsContent() protected method

生成验证码短信通用内容
protected generateSmsContent ( string $code, integer $minutes ) : string
$code string
$minutes integer
return string

generateTemplateData() protected method

生成模版数据
protected generateTemplateData ( string $code, integer $minutes, string $type ) : array
$code string
$minutes integer
$type string
return array

getCanResendTime() public method

从存储器中获取可再次发送的截止时间
public getCanResendTime ( ) : integer
return integer

getCodeValidMinutes() protected static method

从配置文件获取验证码有效时间(分钟)
protected static getCodeValidMinutes ( ) : integer
return integer

getFields() protected static method

获取可验证的字段
protected static getFields ( ) : array
return array

getInterval() protected static method

从配置文件获取可再次请求的最小时间间隔(秒)
protected static getInterval ( ) : integer
return integer

getMobileField() protected static method

获取手机号的字段名
protected static getMobileField ( ) : string
return string

getNameOfDefaultStaticRule() protected static method

获取指定字段的默认静态规则的名称
protected static getNameOfDefaultStaticRule ( string $field ) : string
$field string
return string

getNotifyMessage() protected static method

从配置文件获取提示信息
protected static getNotifyMessage ( string $name ) : string
$name string
return string

getRealRuleByName() protected method

- 首先尝试使用指定名称的静态验证规则 - 其次尝试使用指定名称的动态验证规则 - 最后尝试使用配置文件中的默认静态验证规则
protected getRealRuleByName ( string $field, string $ruleName ) : string
$field string
$ruleName string
return string

getStaticRule() protected static method

获取指定字段的指定名称的静态验证规则
protected static getStaticRule ( $field, $ruleName ) : string | null
$field
$ruleName
return string | null

getStorageClassName() protected static method

获取存储器类名
protected static getStorageClassName ( ) : string
return string

getTemplatesByKey() protected static method

从配置信息中获取指定键名的所有模版id
protected static getTemplatesByKey ( string $key ) : array
$key string
return array

getValidationConfigByField() protected static method

获取验证配置
protected static getValidationConfigByField ( string $field ) : array
$field string
return array

input() public method

获取客户端数据
public input ( string | integer | null $key = null, mixed $default = null ) : mixed
$key string | integer | null
$default mixed
return mixed

pathOfUrl() public static method

获取路径中的path部分
public static pathOfUrl ( string $url, Closure $onError = null ) : string
$url string
$onError Closure
return string

requestVerifySms() public method

请求验证码短信
public requestVerifySms ( ) : array
return array

requestVoiceVerify() public method

请求语音验证码
public requestVoiceVerify ( ) : array
return array

reset() protected method

重置发送状态
protected reset ( )

retrieveAllData() public method

从存储器中获取用户的所有数据
public retrieveAllData ( ) : array
return array

retrieveRule() public method

从存储器中获取指定字段的指定名称的动态验证规则
public retrieveRule ( string $field, string | null $name = null ) : string | null
$field string
$name string | null
return string | null

retrieveRules() public method

从存储中获取指定字段的所有验证规则
public retrieveRules ( string $field ) : array
$field string
return array

retrieveState() public method

从存储器中获取发送状态
public retrieveState ( string | null $name = null ) : array
$name string | null
return array

setCanResendAfter() public method

设置多少秒后才能再次请求
public setCanResendAfter ( integer $interval ) : integer
$interval integer
return integer

state() public method

获取当前的发送状态(非持久化的)
public state ( string | integer | null $key = null, mixed $default = null ) : mixed
$key string | integer | null
$default mixed
return mixed

storage() protected static method

获取存储器
protected static storage ( ) : Toplan\Sms\Storage
return Toplan\Sms\Storage

storeRule() public method

存储指定字段的指定名称的动态验证规则
public storeRule ( string $field, string $name, string | null $rule = null )
$field string
$name string
$rule string | null

storeState() protected method

存储发送状态
protected storeState ( )

updateState() public method

更新发送状态
public updateState ( string | array $name, mixed $value = null )
$name string | array
$value mixed

useRule() protected method

设置指定字段使用的验证规则名称
protected useRule ( string $field, string $name )
$field string
$name string

usedRule() protected method

获取设置指定字段使用的验证规则名称
protected usedRule ( string $field ) : string
$field string
return string

validateFieldName() protected static method

检查字段名称是否合法
protected static validateFieldName ( $name )
$name

validateFields() public method

验证数据
public validateFields ( mixed $input = null, Closure $validation = null ) : array
$input mixed
$validation Closure
return array

validateSendable() public method

验证是否可发送
public validateSendable ( ) : array
return array

verifyCode() protected method

生成待发生的验证码
protected verifyCode ( ) : string
return string

vsprintf() public static method

根据模版和数据合成字符串
public static vsprintf ( string $template, array $data, Closure $onError = null ) : string
$template string
$data array
$onError Closure
return string

whetherValidateFiled() protected static method

是否检查指定的数据
protected static whetherValidateFiled ( string $field ) : boolean
$field string
return boolean

Property Details

$input protected property

客户端数据
protected array $input
return array

$state protected property

发送状态
protected array $state
return array

$storage protected static property

存储器
protected static Storage,Toplan\Sms $storage
return Toplan\Sms\Storage

$token protected property

Access Token
protected string|null $token
return string | null