夺
This commit is contained in:
57
app/tools/Aes.php
Normal file
57
app/tools/Aes.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.vsyo.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 林义满 <steven.lin> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
namespace app\tools;
|
||||
|
||||
class Aes
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param string $string 需要加密的字符串
|
||||
* @param string $key 密钥
|
||||
* @return string
|
||||
*/
|
||||
/*
|
||||
public static function encrypt($string, $key)
|
||||
{
|
||||
$data = openssl_encrypt($string, 'AES-256-ECB', $key, OPENSSL_RAW_DATA, null);
|
||||
return base64_encode($data);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @param string $string 需要解密的字符串
|
||||
* @param string $key 密钥
|
||||
* @return string
|
||||
*/
|
||||
/*
|
||||
public static function decrypt($string, $key)
|
||||
{
|
||||
$string = base64_decode($string);
|
||||
$data = openssl_decrypt($string, 'AES-256-ECB', $key, OPENSSL_RAW_DATA, null);
|
||||
return $data;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* aes加密
|
||||
* AES加密(PHP+FLUTTER)
|
||||
*/
|
||||
public static function encrypt($string ,$key)
|
||||
{
|
||||
return openssl_encrypt($string,"AES-256-CBC",$key,0 ,"0000000000000000");
|
||||
}
|
||||
|
||||
/**
|
||||
* aes解密
|
||||
*/
|
||||
public static function decrypt($string ,$key)
|
||||
{
|
||||
return openssl_decrypt($string,"AES-256-CBC",$key,0,"0000000000000000");
|
||||
}
|
||||
|
||||
}
|
||||
127
app/tools/Sms.php
Normal file
127
app/tools/Sms.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace app\tools;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
// Download:https://github.com/aliyun/openapi-sdk-php
|
||||
// Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
|
||||
|
||||
class Sms
|
||||
{
|
||||
/**
|
||||
* 发送短信验证码,本接只适合发送单个验证码
|
||||
*
|
||||
* @param integer $number 目标用户手机号
|
||||
* @param int $code 短信验证码
|
||||
* @param string $signName 签名如:Knowpia
|
||||
* @param string $template 使用的短信模板
|
||||
* @return array
|
||||
*/
|
||||
public static function sendmsg($number, $code, $signName='', $template='')
|
||||
{
|
||||
if(empty($signName)) $signName = env('aliyunsms.signName');
|
||||
if(empty($template)) $template = env('aliyunsms.TemplateCode');
|
||||
|
||||
if (intval($number) == 0 || $code == "" || $signName == "" || $template == "") {
|
||||
return ['code' => 0, 'message' => '参数不全'];
|
||||
}
|
||||
AlibabaCloud::accessKeyClient(env('aliyunsms.accessKeyId'), env('aliyunsms.accesskey'))
|
||||
->regionId(env('aliyunsms.regionid'))
|
||||
->asDefaultClient();
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Dysmsapi')
|
||||
->version('2017-05-25')
|
||||
->action('SendSms')
|
||||
->method('POST')
|
||||
->host('dysmsapi.aliyuncs.com')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => env('aliyunsms.regionid'),
|
||||
'PhoneNumbers' => $number,
|
||||
'SignName' => $signName,
|
||||
'TemplateCode' => $template,
|
||||
'TemplateParam' => "{\"code\":\"" . $code . "\"}",
|
||||
],
|
||||
])
|
||||
->request();
|
||||
$result = $result->toArray();
|
||||
return ['code' => 1, 'info' => $result];
|
||||
} catch (ClientException $e) {
|
||||
return ['code' => 0, 'message' => $e->getErrorMessage()];
|
||||
} catch (ServerException $e) {
|
||||
return ['code' => 0, 'message' => $e->getErrorMessage()];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获得用户的短信验证码
|
||||
*
|
||||
* @param string $mobile [手机号]
|
||||
* @return array
|
||||
*/
|
||||
public static function getMobileCode($mobile)
|
||||
{
|
||||
$smsExpiration = env('system.smsExpiration');
|
||||
$codeInfo = \app\tools\model\MobileCode::where('state=0 and mobile="'.$mobile.'"')->order('id desc')->find();
|
||||
$notMessage = '请先发送短信再验证';
|
||||
if ($codeInfo) {
|
||||
if ((time() - $codeInfo['create_at']) <= $smsExpiration) {
|
||||
return ['code' => 1, 'MobileCode' => $codeInfo['code'],'check_id'=>$codeInfo['id']];
|
||||
}
|
||||
if ((time() - $codeInfo['create_at']) > $smsExpiration && (time() - $codeInfo['create_at']) <= 60 * 30) {
|
||||
return ['code' => 0, 'message' => '验证码已过期'];
|
||||
}
|
||||
return ['code' => 0, 'message' => $notMessage];
|
||||
}
|
||||
return ['code' => 0, 'message' => $notMessage];
|
||||
}
|
||||
|
||||
/**
|
||||
* 号码认证服务,利用一键登录TOKEN获取手机号
|
||||
*
|
||||
* @param string $token
|
||||
* @return array
|
||||
*/
|
||||
public static function getMobileNumber($token = ''): array
|
||||
{
|
||||
/** back array
|
||||
* {
|
||||
* "GetMobileResultDTO": {
|
||||
* "Mobile": "18620725473"
|
||||
* },
|
||||
* "Message": "OK",
|
||||
* "RequestId": "098CC43B-8006-4127-9DC5-2B30CA741745",
|
||||
* "Code": "OK"
|
||||
* }
|
||||
*/
|
||||
if ($token == '') {
|
||||
return ['code' => 0, 'message' => '参数不全'];
|
||||
}
|
||||
AlibabaCloud::accessKeyClient(env('aliyunsms.accessKeyId'), env('aliyunsms.accesskey'))
|
||||
->regionId('cn-hangzhou')
|
||||
->asDefaultClient();
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Dypnsapi')
|
||||
->scheme('https')
|
||||
->version('2017-05-25')
|
||||
->action('GetMobile')
|
||||
->method('POST')
|
||||
->host('dypnsapi.aliyuncs.com')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => "cn-hangzhou",
|
||||
'AccessToken' => $token,
|
||||
],
|
||||
])->request();
|
||||
return ['code' => 1, 'info' => $result->toArray()];
|
||||
} catch (ClientException $e) {
|
||||
return ['code' => 0, 'message' => $e->getErrorMessage()];
|
||||
} catch (ServerException $e) {
|
||||
return ['code' => 0, 'message' => $e->getErrorMessage()];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user