You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
1.1 KiB

<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\HelperServiceInterface;
class HelperService implements HelperServiceInterface
{
public function makeNumCode($length)
{
// 获取验证码
$codeArr = array_map(function ($item) {
return mt_rand(0,9);
}, array_pad([], $length, 0));
// 返回验证码
return implode('', $codeArr);
}
/**
* 请求参数判空
* @param mixed $var 参数
* @return bool
*/
public function nonempty($var)
{
return ! (
isset($var)
&& $var
&& !empty($var)
&& !is_null($var)
&& $var != 'undefined'
&& $var != 'unknown'
&& $var != 'null'
&& $var != 'false'
);
}
public function filterEmoji($str)
{
$str = preg_replace_callback(
'/./u',
function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0];
},
$str);
return $str;
}
}