Merge branch 'main' of https://git.mowei.com.cn/wyh/gan into main
commit
e8f04adf9f
|
|
@ -93,10 +93,20 @@
|
|||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>4.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,27 @@
|
|||
package com.ruoyi.app.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/app")
|
||||
@Api(
|
||||
tags = "APP-登录接口"
|
||||
)
|
||||
public class AppLoginController {
|
||||
|
||||
|
||||
@PostMapping("/register")
|
||||
@ApiOperation(value = "注册" , notes = "注册")
|
||||
public void register(RegisterForm registerForm) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
|
|||
* @date 2024-04-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/school")
|
||||
@Api(tags = "学校配置接口" , description = "学校配置接口")
|
||||
@RequestMapping("/api/school")
|
||||
@Api(tags = "学校配置" , description = "学校配置")
|
||||
public class AppSchoolController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.ruoyi.app.controller;
|
||||
|
||||
import com.ruoyi.app.service.OssService;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/oss")
|
||||
@Api(tags = "文件上传" , description = "文件上传")
|
||||
public class OssController {
|
||||
|
||||
@Autowired
|
||||
OssService ossService;
|
||||
|
||||
//1、上传文件到oss: 接收客户端上传的文件流和文件名称 上传到oss之后 返回上传成功的文件路径
|
||||
@PostMapping("upload")
|
||||
@ApiOperation(value = "上传文件" , notes = "上传文件", produces = "file" , response = R.class)
|
||||
public R uploadFile(@RequestBody MultipartFile file, HttpServletRequest request
|
||||
) {
|
||||
return ossService.uploadFile(file);
|
||||
}
|
||||
|
||||
//2、删除oss中的文件
|
||||
@DeleteMapping("delete")
|
||||
@ApiOperation("删除文件")
|
||||
public R deleteFile(@RequestParam("path") String path
|
||||
) {
|
||||
return ossService.deleteFile(path);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.ruoyi.app.service;
|
||||
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface OssService {
|
||||
|
||||
R uploadFile(MultipartFile file);
|
||||
|
||||
R deleteFile(String path);
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
//package com.ruoyi.app.service.impl;
|
||||
//
|
||||
//import com.aliyun.dysmsapi20170525.models.*;
|
||||
//import com.ruoyi.app.service.MsmService;
|
||||
//
|
||||
//
|
||||
//public class MsmServiceImpl implements MsmService {
|
||||
// @Override
|
||||
// public Boolean send(String phoneNum, String code) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
// Config config = new Config();
|
||||
// config.accessKeyId = accessKeyId;
|
||||
// config.accessKeySecret = accessKeySecret;
|
||||
// return new com.aliyun.dysmsapi20170525.Client(config);
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args_) throws Exception {
|
||||
// java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
// com.aliyun.dysmsapi20170525.Client client = MsmServiceImpl.createClient(com.aliyun.darabonba.env.EnvClient.getEnv("ACCESS_KEY_ID"), com.aliyun.darabonba.env.EnvClient.getEnv("ACCESS_KEY_SECRET"));
|
||||
// // 1.发送短信
|
||||
// SendSmsRequest sendReq = new SendSmsRequest()
|
||||
// .setPhoneNumbers(args.get(0))
|
||||
// .setSignName(args.get(1))
|
||||
// .setTemplateCode(args.get(2))
|
||||
// .setTemplateParam(args.get(3));
|
||||
// SendSmsResponse sendResp = client.sendSms(sendReq);
|
||||
// String code = sendResp.body.code;
|
||||
// if (!com.aliyun.teautil.Common.equalString(code, "OK")) {
|
||||
// com.aliyun.teaconsole.Client.log("错误信息: " + sendResp.body.message + "");
|
||||
// return ;
|
||||
// }
|
||||
//
|
||||
// String bizId = sendResp.body.bizId;
|
||||
// // 2. 等待 10 秒后查询结果
|
||||
// com.aliyun.teautil.Common.sleep(10000);
|
||||
// // 3.查询结果
|
||||
// java.util.List<String> phoneNums = com.aliyun.darabonbastring.Client.split(args.get(0), ",", -1);
|
||||
// for (String phoneNum : phoneNums) {
|
||||
// QuerySendDetailsRequest queryReq = new QuerySendDetailsRequest()
|
||||
// .setPhoneNumber(com.aliyun.teautil.Common.assertAsString(phoneNum))
|
||||
// .setBizId(bizId)
|
||||
// .setSendDate(com.aliyun.darabonbatime.Client.format("yyyyMMdd"))
|
||||
// .setPageSize(10L)
|
||||
// .setCurrentPage(1L);
|
||||
// QuerySendDetailsResponse queryResp = client.querySendDetails(queryReq);
|
||||
// java.util.List<QuerySendDetailsResponseBody.QuerySendDetailsResponseBodySmsSendDetailDTOsSmsSendDetailDTO> dtos = queryResp.body.smsSendDetailDTOs.smsSendDetailDTO;
|
||||
// // 打印结果
|
||||
// for (QuerySendDetailsResponseBody.QuerySendDetailsResponseBodySmsSendDetailDTOsSmsSendDetailDTO dto : dtos) {
|
||||
// if (com.aliyun.teautil.Common.equalString("" + dto.sendStatus + "", "3")) {
|
||||
// com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 发送成功,接收时间: " + dto.receiveDate + "");
|
||||
// } else if (com.aliyun.teautil.Common.equalString("" + dto.sendStatus + "", "2")) {
|
||||
// com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 发送失败");
|
||||
// } else {
|
||||
// com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 正在发送中...");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.ruoyi.app.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.ruoyi.app.service.OssService;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service("ossService")
|
||||
public class OssServiceImpl implements OssService {
|
||||
|
||||
|
||||
|
||||
private static final String schema= "https://";
|
||||
private static final String endpoint= "oss-cn-shanghai.aliyuncs.com";
|
||||
private static final String accessKeyId= "LTAI5tM1LeE2pkiS3qEFQkfb";
|
||||
private static final String accessKeySecret= "fEZZyFvWkETS8Clm73f7qmY9ohcTpc";
|
||||
private static final String bucketName= "gan-app-test";
|
||||
@Override
|
||||
public R uploadFile(MultipartFile file) {
|
||||
try {
|
||||
//4、 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(schema + endpoint, accessKeyId, accessKeySecret);
|
||||
String fileName = file.getOriginalFilename();//获取上传文件的名称
|
||||
InputStream inputStream = file.getInputStream();
|
||||
// 通过ossClient上传文件: 参数1:桶名, 参数2:上传后的文件路径+文件名 ,参数3:要上传的文件流
|
||||
String objectName = new DateTime().toString("yyyy/MM/dd/") +
|
||||
UUID.randomUUID().toString().replace("-", "").substring(0, 16) +
|
||||
"_" + fileName;//使用UUID+源文件名称后缀拼接生成objectName
|
||||
ossClient.putObject(bucketName, objectName, inputStream);
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
|
||||
String path = schema + bucketName + "." + endpoint + "/" + objectName;//手动拼接上传成功的图片地址
|
||||
// System.out.println("path ======================================" + path);
|
||||
return R.ok(path);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("图片上传失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public R deleteFile(String path) {
|
||||
String host = schema + bucketName + "." + endpoint +"/";
|
||||
String objectName = path.replace(host,"");
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
ossClient.deleteObject(bucketName, objectName.trim());
|
||||
ossClient.shutdown();
|
||||
return R.ok("删除成功");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue