初始代码
This commit is contained in:
37
yunzhupaas-file/yunzhupaas-file-biz/pom.xml
Normal file
37
yunzhupaas-file/yunzhupaas-file-biz/pom.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-file</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-file-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-file-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-system-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- aop -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-exception</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yunzhupaas.entity.FileEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2021/5/13
|
||||
*/
|
||||
public interface FileMapper extends SuperMapper<FileEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yunzhupaas.entity.FileEntity;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
|
||||
import com.yunzhupaas.model.YozoFileParams;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2021/5/13
|
||||
*/
|
||||
@Service
|
||||
public interface YozoService extends SuperService<FileEntity> {
|
||||
/**
|
||||
* 生成文件预览url
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
String getPreviewUrl(YozoFileParams params);
|
||||
|
||||
/**
|
||||
* 新建文档保存versionId
|
||||
* @param fileVersionId
|
||||
* @param fileId
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
ActionResult saveFileId(String fileVersionId, String fileId, String fileName);
|
||||
|
||||
/**
|
||||
* 根据文件名查询
|
||||
* @param fileNa
|
||||
* @return
|
||||
*/
|
||||
FileEntity selectByName(String fileNa);
|
||||
|
||||
/**
|
||||
* 上传文件到永中
|
||||
* @param fileVersionId
|
||||
* @param fileId
|
||||
* @param fileUrl
|
||||
* @return
|
||||
*/
|
||||
ActionResult saveFileIdByHttp(String fileVersionId, String fileId, String fileUrl);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param versionId
|
||||
* @return
|
||||
*/
|
||||
ActionResult deleteFileByVersionId(String versionId);
|
||||
|
||||
/**
|
||||
* 根据versionId查询文件
|
||||
* @param fileVersionId
|
||||
* @return
|
||||
*/
|
||||
FileEntity selectByVersionId(String fileVersionId);
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param versions
|
||||
* @return
|
||||
*/
|
||||
ActionResult deleteBatch(String[] versions);
|
||||
|
||||
/**
|
||||
* 更新versionId
|
||||
* @param oldFileId
|
||||
* @param newFileId
|
||||
*/
|
||||
void editFileVersion(String oldFileId, String newFileId);
|
||||
|
||||
List<FileEntity> getAllList(PaginationVO pageModel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.yunzhupaas.service.impl;
|
||||
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.entity.FileEntity;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.mapper.FileMapper;
|
||||
import com.yunzhupaas.model.YozoFileParams;
|
||||
import com.yunzhupaas.service.YozoService;
|
||||
import com.yunzhupaas.utils.SplicingUrlUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2021/5/13
|
||||
*/
|
||||
@Service
|
||||
public class YozoServiceImpl extends SuperServiceImpl<FileMapper,FileEntity> implements YozoService {
|
||||
|
||||
@Autowired
|
||||
private FileMapper fileMapper;
|
||||
|
||||
@Override
|
||||
public String getPreviewUrl(YozoFileParams params) {
|
||||
String previewUrl = SplicingUrlUtil.getPreviewUrl(params);
|
||||
return previewUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult saveFileId(String fileVersionId, String fileId, String fileName) {
|
||||
FileEntity fileEntity =new FileEntity();
|
||||
fileEntity.setId(fileId);
|
||||
fileEntity.setFileName(fileName);
|
||||
fileEntity.setFileVersionId(fileVersionId);
|
||||
fileEntity.setType("create");
|
||||
this.save(fileEntity);
|
||||
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEntity selectByName(String fileNa) {
|
||||
QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(FileEntity::getFileName,fileNa);
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult saveFileIdByHttp(String fileVersionId, String fileId, String fileUrl) {
|
||||
String fileName = "";
|
||||
String url = "";
|
||||
String name = "";
|
||||
try {
|
||||
url = URLDecoder.decode(fileUrl, "UTF-8");
|
||||
if (url.contains("/")) {
|
||||
fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
} else {
|
||||
fileName = url.substring(url.lastIndexOf("\\") + 1);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//同一url文件数
|
||||
QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("F_Url", url);
|
||||
Long total = fileMapper.selectCount(wrapper);
|
||||
if (total == 0) {
|
||||
name = fileName;
|
||||
} else {
|
||||
String t = total.toString();
|
||||
name = fileName + "(" + t + ")";
|
||||
}
|
||||
FileEntity fileEntity = new FileEntity();
|
||||
fileEntity.setType(url.contains("http") ? "http" : "local");
|
||||
fileEntity.setFileVersionId(fileVersionId);
|
||||
fileEntity.setId(fileId);
|
||||
fileEntity.setFileName(name);
|
||||
fileEntity.setUrl(url);
|
||||
fileMapper.insert(fileEntity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult deleteFileByVersionId(String versionId) {
|
||||
QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("F_FileVersion", versionId);
|
||||
int i = fileMapper.delete(wrapper);
|
||||
if (i == 1) {
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEntity selectByVersionId(String fileVersionId) {
|
||||
QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("F_FileVersion", fileVersionId);
|
||||
FileEntity fileEntity = fileMapper.selectOne(wrapper);
|
||||
return fileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult deleteBatch(String[] versions) {
|
||||
for (String version : versions) {
|
||||
QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("F_FileVersion", version);
|
||||
int i = fileMapper.delete(wrapper);
|
||||
if (i == 0) {
|
||||
return ActionResult.fail(MsgCode.FA045.get(version));
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editFileVersion(String oldFileId, String newFileId) {
|
||||
UpdateWrapper<FileEntity> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("F_FileVersion", oldFileId);
|
||||
FileEntity fileEntity = new FileEntity();
|
||||
fileEntity.setFileVersionId(newFileId);
|
||||
fileEntity.setOldFileVersionId(oldFileId);
|
||||
fileMapper.update(fileEntity, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileEntity> getAllList(PaginationVO pageModel) {
|
||||
Page page = new Page(pageModel.getCurrentPage(), pageModel.getPageSize());
|
||||
IPage<FileEntity> iPage = fileMapper.selectPage(page, null);
|
||||
return iPage.getRecords();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
package com.yunzhupaas.utils;
|
||||
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.yozo.client.AppAuthenticator;
|
||||
import com.yunzhupaas.yozo.client.UaaAppAuthenticator;
|
||||
import com.yunzhupaas.yozo.utils.DefaultResult;
|
||||
import com.yunzhupaas.yozo.utils.IResult;
|
||||
import com.yunzhupaas.model.YozoParams;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import com.yunzhupaas.yozo.constants.EnumResultCode;
|
||||
import com.yunzhupaas.yozo.constants.UaaConstant;
|
||||
import lombok.Cleanup;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.HttpMultipartMode;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.entity.mime.content.FileBody;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件预览编辑工具类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2021/5/13
|
||||
*/
|
||||
@Component
|
||||
public class YozoUtils {
|
||||
/**
|
||||
* 生成签名
|
||||
*
|
||||
* @param appId
|
||||
* @param secret
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public IResult<String> generateSign(String appId, String secret, Map<String, String[]> params) {
|
||||
AppAuthenticator authenticator = new UaaAppAuthenticator(UaaConstant.SIGN, null, UaaConstant.APPID);
|
||||
try {
|
||||
String[] appIds = params.get(UaaConstant.APPID);
|
||||
if (appIds == null || appIds.length != 1 || StringUtils.isEmpty(appIds[0])) {
|
||||
params.put(UaaConstant.APPID, new String[]{appId});
|
||||
}
|
||||
String sign = authenticator.generateSign(secret, params);
|
||||
return DefaultResult.successResult(sign);
|
||||
} catch (Exception e) {
|
||||
return DefaultResult.failResult(EnumResultCode.E_GENERATE_SIGN_FAIL.getInfo());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取文件名
|
||||
* @param fileName
|
||||
* @param templateType
|
||||
* @return
|
||||
*/
|
||||
public String getFileName(String fileName, String templateType) {
|
||||
String suffix;
|
||||
switch (templateType) {
|
||||
case "1":
|
||||
suffix = ".doc";
|
||||
break;
|
||||
case "2":
|
||||
suffix = ".docx";
|
||||
break;
|
||||
case "3":
|
||||
suffix = ".ppt";
|
||||
break;
|
||||
case "4":
|
||||
suffix = ".pptx";
|
||||
break;
|
||||
case "5":
|
||||
suffix = ".xls";
|
||||
break;
|
||||
case "6":
|
||||
suffix = ".xlsx";
|
||||
break;
|
||||
default:
|
||||
suffix = null;
|
||||
}
|
||||
if (suffix==null){
|
||||
return null;
|
||||
}
|
||||
String name = fileName + suffix;
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用httpclint 发送文件
|
||||
* @author: qingfeng
|
||||
* @date: 2019-05-27
|
||||
* @param file
|
||||
* 上传的文件
|
||||
*/
|
||||
public String uploadFile(String url , File file, String appId, String sign) {
|
||||
String result="";
|
||||
//构建HttpClient对象
|
||||
CloseableHttpResponse response = null;
|
||||
//构建POST请求
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
try {
|
||||
@Cleanup CloseableHttpClient client = HttpClients.createDefault();
|
||||
//构建文件体
|
||||
String fileName = file.getName();
|
||||
FileBody fileBody = new FileBody(file, ContentType.MULTIPART_FORM_DATA, fileName);
|
||||
HttpEntity httpEntity = MultipartEntityBuilder
|
||||
.create()
|
||||
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
|
||||
.addPart("file", fileBody)
|
||||
.addTextBody("appId",appId)
|
||||
.addTextBody("sign",sign)
|
||||
.build();
|
||||
httpPost.setEntity(httpEntity);
|
||||
// 执行http请求
|
||||
response = client.execute(httpPost);
|
||||
result = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件到指定目录
|
||||
* @param fileUrl
|
||||
* @param savePath
|
||||
* @throws Exception
|
||||
*/
|
||||
public void downloadFile(String fileUrl,String savePath) throws Exception {
|
||||
File file=new File(XSSEscape.escapePath(savePath));
|
||||
//判断文件是否存在,不存在则创建文件
|
||||
if(!file.exists()){
|
||||
file.createNewFile();
|
||||
}
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
|
||||
urlCon.setConnectTimeout(6000);
|
||||
urlCon.setReadTimeout(6000);
|
||||
int code = urlCon.getResponseCode();
|
||||
if (code != HttpURLConnection.HTTP_OK) {
|
||||
throw new Exception(MsgCode.FA046.get());
|
||||
}
|
||||
@Cleanup DataInputStream in = new DataInputStream(urlCon.getInputStream());
|
||||
@Cleanup FileOutputStream fileOutputStream = new FileOutputStream(savePath);
|
||||
@Cleanup DataOutputStream out = new DataOutputStream(fileOutputStream);
|
||||
byte[] buffer = new byte[2048];
|
||||
int count = 0;
|
||||
while ((count = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, count);
|
||||
}
|
||||
try {
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到永中
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public String uploadFileInPreview(InputStream inputStream,String fileName) throws IOException {
|
||||
//获取签名
|
||||
Map<String, String[]> parameter = new HashMap<String, String[]>();
|
||||
parameter.put("appId", new String[]{YozoParams.APP_ID});
|
||||
String sign = this.generateSign(YozoParams.APP_ID, YozoParams.APP_KEY, parameter).getData();
|
||||
String url= "http://dmc.yozocloud.cn/api/file/upload?appId="+YozoParams.APP_ID+"&sign="+sign;
|
||||
|
||||
@Cleanup CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
String result ="";
|
||||
HttpEntity httpEntity =null;
|
||||
HttpEntity responseEntity = null;
|
||||
|
||||
try {
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||
multipartEntityBuilder.setCharset(Charset.forName("utf-8"));
|
||||
multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);//加上此行代码解决返回中文乱码问题
|
||||
multipartEntityBuilder.addBinaryBody("file", inputStream, ContentType.MULTIPART_FORM_DATA, fileName);
|
||||
|
||||
httpEntity = multipartEntityBuilder.build();
|
||||
httpPost.setEntity(httpEntity);
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
responseEntity = response.getEntity();
|
||||
result = EntityUtils.toString(responseEntity,Charset.forName("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if (inputStream!=null){
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.yunzhupaas.yozo.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AppAuthenticator {
|
||||
String generateSign(String var1, Map<String, String[]> var2) throws Exception;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.yunzhupaas.yozo.client;
|
||||
|
||||
import com.yunzhupaas.yozo.utils.SecretSignatureUtils;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class UaaAppAuthenticator implements AppAuthenticator {
|
||||
public static final String OPEN_PARAM_PREFIX = "y_";
|
||||
public static final String OPEN_PARAM_APPID = "y_appid";
|
||||
public static final String OPEN_PARAM_SIGN = "y_SIGN";
|
||||
private String signParamName;
|
||||
private String paramNamePrefix;
|
||||
private String appidParamName;
|
||||
|
||||
public UaaAppAuthenticator() {
|
||||
}
|
||||
|
||||
public UaaAppAuthenticator(String signParamName, String paramNamePrefix, String appidParamName) {
|
||||
this.signParamName = signParamName;
|
||||
this.paramNamePrefix = paramNamePrefix;
|
||||
this.appidParamName = appidParamName;
|
||||
}
|
||||
|
||||
public String getSignParamName() {
|
||||
return this.signParamName;
|
||||
}
|
||||
|
||||
public void setSignParamName(String signParamName) {
|
||||
this.signParamName = signParamName;
|
||||
}
|
||||
|
||||
public String getParamNamePrefix() {
|
||||
return this.paramNamePrefix;
|
||||
}
|
||||
|
||||
public void setParamNamePrefix(String paramNamePrefix) {
|
||||
this.paramNamePrefix = paramNamePrefix;
|
||||
}
|
||||
|
||||
public String getAppidParamName() {
|
||||
return this.appidParamName;
|
||||
}
|
||||
|
||||
public void setAppidParamName(String appidParamName) {
|
||||
this.appidParamName = appidParamName;
|
||||
}
|
||||
|
||||
public String generateSign(String secret, Map<String, String[]> params) throws Exception {
|
||||
String fullParamStr = this.uniqSortParams(params);
|
||||
return SecretSignatureUtils.hmacSHA256(fullParamStr, secret);
|
||||
}
|
||||
|
||||
private String uniqSortParams(Map<String, String[]> params) {
|
||||
boolean prefix = StringUtil.isNotEmpty(this.paramNamePrefix);
|
||||
params.remove(this.signParamName);
|
||||
String[] paramKeys = new String[params.keySet().size()];
|
||||
int idx = 0;
|
||||
Iterator var5 = params.keySet().iterator();
|
||||
|
||||
while(true) {
|
||||
String param;
|
||||
do {
|
||||
if (!var5.hasNext()) {
|
||||
Arrays.sort(paramKeys, 0, idx);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String[] var16 = paramKeys;
|
||||
int var7 = paramKeys.length;
|
||||
|
||||
for(int var8 = 0; var8 < var7; ++var8) {
|
||||
String key = var16[var8];
|
||||
String[] values = (String[])((String[])params.get(key));
|
||||
if (values != null && values.length > 0) {
|
||||
Arrays.sort(values);
|
||||
String[] var11 = values;
|
||||
int var12 = values.length;
|
||||
|
||||
for(int var13 = 0; var13 < var12; ++var13) {
|
||||
String val = var11[var13];
|
||||
builder.append(key).append("=").append(val);
|
||||
}
|
||||
} else {
|
||||
builder.append(key).append("=");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
param = (String)var5.next();
|
||||
} while(prefix && param.startsWith(this.paramNamePrefix));
|
||||
|
||||
paramKeys[idx++] = param;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yunzhupaas.yozo.client;
|
||||
|
||||
import com.yunzhupaas.yozo.utils.DefaultResult;
|
||||
import com.yunzhupaas.yozo.utils.IResult;
|
||||
import com.yunzhupaas.yozo.constants.EnumResultCode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UaaAppConfigClient {
|
||||
public UaaAppConfigClient() {
|
||||
}
|
||||
|
||||
public IResult<String> generateSign(String appId, String secret, Map<String, String[]> params) {
|
||||
UaaAppAuthenticator authenticator = new UaaAppAuthenticator("sign", (String)null, "appId");
|
||||
|
||||
try {
|
||||
String[] appIds = (String[])params.get("appId");
|
||||
if (appIds == null || appIds.length != 1 || appIds[0] == null || "".equals(appIds[0])) {
|
||||
params.put("appId", new String[]{appId});
|
||||
}
|
||||
|
||||
String sign = authenticator.generateSign(secret, params);
|
||||
return DefaultResult.successResult(sign);
|
||||
} catch (Exception var7) {
|
||||
return DefaultResult.failResult(EnumResultCode.E_GENERATE_SIGN_FAIL.getInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yunzhupaas.yozo.constants;
|
||||
|
||||
public enum EnumResultCode {
|
||||
E_SUCCESS(0, "操作成功"),
|
||||
E_GENERATE_SIGN_FAIL(1000, "获取签名失败");
|
||||
|
||||
private Integer value;
|
||||
private String info;
|
||||
|
||||
private EnumResultCode(Integer value, String info) {
|
||||
this.value = value;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return this.info;
|
||||
}
|
||||
|
||||
public static EnumResultCode getEnum(Integer value) {
|
||||
EnumResultCode[] var1 = values();
|
||||
int var2 = var1.length;
|
||||
|
||||
for(int var3 = 0; var3 < var2; ++var3) {
|
||||
EnumResultCode code = var1[var3];
|
||||
if (code.getValue().equals(value)) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.yunzhupaas.yozo.constants;
|
||||
|
||||
public class UaaConstant {
|
||||
public static final String APPID = "appId";
|
||||
public static final String SIGN = "sign";
|
||||
|
||||
public UaaConstant() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.yunzhupaas.yozo.utils;
|
||||
|
||||
public class DefaultResult<T> implements IResult<T> {
|
||||
private static final DefaultResult.SuccessResult SUCCESS = new DefaultResult.SuccessResult();
|
||||
private static final DefaultResult.FailResult FAIL = new DefaultResult.FailResult();
|
||||
private boolean success;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public DefaultResult() {
|
||||
}
|
||||
|
||||
public DefaultResult(boolean success, String message) {
|
||||
this(success, message, (T) null);
|
||||
}
|
||||
|
||||
public DefaultResult(boolean success, T data) {
|
||||
this(success, (String)null, data);
|
||||
}
|
||||
|
||||
public DefaultResult(boolean success, String message, T data) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> successResult() {
|
||||
return (DefaultResult<T>) SUCCESS;
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> successResult(T data) {
|
||||
return new DefaultResult(true, (String)null, data);
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> successResult(String message, T data) {
|
||||
return new DefaultResult(true, message, data);
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> failResult() {
|
||||
return (DefaultResult<T>) FAIL;
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> failResult(String message) {
|
||||
return new DefaultResult(false, message, (Object)null);
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> failResult(String message, T data) {
|
||||
return new DefaultResult(false, message, data);
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> failResult(T data) {
|
||||
return new DefaultResult(false, (String)null, data);
|
||||
}
|
||||
|
||||
public static <T> DefaultResult<T> result(boolean success, String message, T data) {
|
||||
return new DefaultResult(success, message, data);
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(T obj) {
|
||||
this.data = obj;
|
||||
}
|
||||
|
||||
private static class FailResult extends DefaultResult<Object> {
|
||||
public FailResult() {
|
||||
super(false, (String)null, (Object)null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SuccessResult extends DefaultResult<Object> {
|
||||
public SuccessResult() {
|
||||
super(true, (String)null, (Object)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yunzhupaas.yozo.utils;
|
||||
|
||||
public class HttpRequestUtils {
|
||||
public HttpRequestUtils() {
|
||||
}
|
||||
|
||||
public static class StringUtils {
|
||||
public StringUtils() {
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String data) {
|
||||
return data != null && data.trim().length() > 0;
|
||||
}
|
||||
|
||||
public static boolean equals(String cs1, String cs2) {
|
||||
if (cs1 == cs2) {
|
||||
return true;
|
||||
} else if (cs1 != null && cs2 != null) {
|
||||
return cs1.length() != cs2.length() ? false : cs1.equals(cs2);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yunzhupaas.yozo.utils;
|
||||
|
||||
public interface IResult<T> {
|
||||
boolean isSuccess();
|
||||
|
||||
String getMessage();
|
||||
|
||||
T getData();
|
||||
|
||||
void setData(T var1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yunzhupaas.yozo.utils;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class SecretSignatureUtils {
|
||||
public static final String SHA256 = "HmacSHA256";
|
||||
|
||||
public SecretSignatureUtils() {
|
||||
}
|
||||
|
||||
public static String hmacSHA256(String data, String key) throws Exception {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
|
||||
mac.init(secret_key);
|
||||
byte[] array = mac.doFinal(data.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] var6 = array;
|
||||
int var7 = array.length;
|
||||
|
||||
for(int var8 = 0; var8 < var7; ++var8) {
|
||||
byte item = var6[var8];
|
||||
sb.append(Integer.toHexString(item & 255 | 256).substring(1, 3));
|
||||
}
|
||||
|
||||
return sb.toString().toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user