作者 lyh

gx

... ... @@ -37,6 +37,13 @@ class WebSettingReceivingLogic extends BaseLogic
try {
$this->model->del(['project_id'=>$this->user['project_id']]);
foreach ($this->param['data'] as $k => $v){
if($v['type'] == 2){
// 使用正则表达式匹配中国大陆手机号
$pattern = '/^1[3456789]\d{9}$/';
if (!preg_match($pattern, $v['values'])) {
continue;
}
}
$v['project_id'] = $this->user['project_id'];
$v['created_at'] = date('Y-m-d H:i:s');
$v['updated_at'] = date('Y-m-d H:i:s');
... ...
<?php
/**
* @remark :上传文件与图片到亚马逊
* @name :AmazonS3Service.php
* @author :lyh
* @method :post
* @time :2024/1/23 9:17
*/
namespace App\Services;
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
class AmazonS3Service
{
// 替换为你自己的 AWS 访问密钥、区域和存储桶名称
protected $s3;
protected $accessKeyId = '';//key
protected $secretAccessKey = '';//密匙
protected $region = '';//地址
protected $bucket = '';//桶子
public function __construct()
{
// 创建 S3 客户端
$this->s3 = new S3Client([
'version' => 'latest',
'region' => $this->region,
'credentials' => [
'key' => $this->accessKeyId,
'secret' => $this->secretAccessKey,
],
]);
}
/**
* @remark :上传图片与文件
* @name :uploadImage
* @author :lyh
* @method :post
* @time :2024/1/23 9:20
*/
public function uploadFiles($localFilePath, $s3Key)
{
try {
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $s3Key,
'SourceFile' => $localFilePath,
'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
]);
return $result['ObjectURL'];
} catch (S3Exception $e) {
return false;
}
}
}
... ...