作者 lyh

gx

@@ -37,6 +37,13 @@ class WebSettingReceivingLogic extends BaseLogic @@ -37,6 +37,13 @@ class WebSettingReceivingLogic extends BaseLogic
37 try { 37 try {
38 $this->model->del(['project_id'=>$this->user['project_id']]); 38 $this->model->del(['project_id'=>$this->user['project_id']]);
39 foreach ($this->param['data'] as $k => $v){ 39 foreach ($this->param['data'] as $k => $v){
  40 + if($v['type'] == 2){
  41 + // 使用正则表达式匹配中国大陆手机号
  42 + $pattern = '/^1[3456789]\d{9}$/';
  43 + if (!preg_match($pattern, $v['values'])) {
  44 + continue;
  45 + }
  46 + }
40 $v['project_id'] = $this->user['project_id']; 47 $v['project_id'] = $this->user['project_id'];
41 $v['created_at'] = date('Y-m-d H:i:s'); 48 $v['created_at'] = date('Y-m-d H:i:s');
42 $v['updated_at'] = date('Y-m-d H:i:s'); 49 $v['updated_at'] = date('Y-m-d H:i:s');
  1 +<?php
  2 +/**
  3 + * @remark :上传文件与图片到亚马逊
  4 + * @name :AmazonS3Service.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/1/23 9:17
  8 + */
  9 +
  10 +namespace App\Services;
  11 +
  12 +use Aws\S3\S3Client;
  13 +use Aws\S3\Exception\S3Exception;
  14 +class AmazonS3Service
  15 +{
  16 + // 替换为你自己的 AWS 访问密钥、区域和存储桶名称
  17 + protected $s3;
  18 + protected $accessKeyId = '';//key
  19 + protected $secretAccessKey = '';//密匙
  20 + protected $region = '';//地址
  21 + protected $bucket = '';//桶子
  22 +
  23 + public function __construct()
  24 + {
  25 + // 创建 S3 客户端
  26 + $this->s3 = new S3Client([
  27 + 'version' => 'latest',
  28 + 'region' => $this->region,
  29 + 'credentials' => [
  30 + 'key' => $this->accessKeyId,
  31 + 'secret' => $this->secretAccessKey,
  32 + ],
  33 + ]);
  34 + }
  35 +
  36 + /**
  37 + * @remark :上传图片与文件
  38 + * @name :uploadImage
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2024/1/23 9:20
  42 + */
  43 + public function uploadFiles($localFilePath, $s3Key)
  44 + {
  45 + try {
  46 + $result = $this->s3->putObject([
  47 + 'Bucket' => $this->bucket,
  48 + 'Key' => $s3Key,
  49 + 'SourceFile' => $localFilePath,
  50 + 'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
  51 + ]);
  52 + return $result['ObjectURL'];
  53 + } catch (S3Exception $e) {
  54 + return false;
  55 + }
  56 + }
  57 +}