短信验证

This commit is contained in:
“wanyongkang”
2022-05-13 17:23:31 +08:00
parent 7bf5866d7c
commit 2f3d3e7391
4 changed files with 157 additions and 2 deletions

57
extends/alisms/Sms.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace extend\alisms;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Utils\Utils;
class Sms
{
/**
* 使用AK&SK初始化账号Client
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Dysmsapi Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
$config = new Config([
// 您的AccessKey ID
"accessKeyId" => $accessKeyId,
// 您的AccessKey Secret
"accessKeySecret" => $accessKeySecret
]);
// 访问的域名
$config->endpoint = "dysmsapi.aliyuncs.com";
return new Dysmsapi($config);
}
/**
* @param string[] $args
* @return void
*/
public static function sendVerify($phone,$vcode){
$client = self::createClient("LTAI4FmSkDSwFuXeLxsDB3jB", "r8FfRmoeWcCJyZSqqkQP2G3dKPPl2N");
$sendSmsRequest = new SendSmsRequest([
"phoneNumbers" => $phone,
"signName" => "华连云",
"templateCode" => "SMS_186355045",
"templateParam" => "{\"code\":\"$vcode\"}"
]);
// 复制代码运行请自行打印 API 的返回值
$sendResp = $client->sendSms($sendSmsRequest);
dump($sendResp);
$code = $sendResp->body->code;
if (!Utils::equalString($code, "OK")) {
$return_info = [
'code' => 0,
'msg' => $sendResp->body->message
];
return $return_info;
}
return ['code' => 1];
}
}

30
extends/redis/Redisop.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
namespace extend\redis;
class Redisop {
private $redis;
public function __construct()
{
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
$this->redis->auth('123456');
}
public function setOfTime($key = '', $value = '') {
if (empty($key)) {
die;
}
$this->redis->set( $key , $value);
$this->redis->expire($key,60);
}
public function get($key = '') {
if (empty($key)) {
die;
}
return $this->redis->get( $key );
}
}