use of com.paascloud.provider.model.dto.oss.OptUploadFileRespDto in project paascloud-master by paascloud.
the class OpcFileController method uploadFile.
/**
* 上传文件.
*
* @param request the request
* @param optUploadFileReqDto the opt upload file req dto
*
* @return the wrapper
*/
@PostMapping(consumes = "multipart/form-data", value = "/uploadFile")
@ApiOperation(httpMethod = "POST", value = "上传文件")
public Wrapper<String> uploadFile(HttpServletRequest request, OptUploadFileReqDto optUploadFileReqDto) {
StringBuilder temp = new StringBuilder();
logger.info("uploadFile - 上传文件. optUploadFileReqDto={}", optUploadFileReqDto);
Preconditions.checkArgument(StringUtils.isNotEmpty(optUploadFileReqDto.getFileType()), "文件类型为空");
Preconditions.checkArgument(StringUtils.isNotEmpty(optUploadFileReqDto.getBucketName()), "存储地址为空");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<OptUploadFileRespDto> optUploadFileRespDtos = optAttachmentService.uploadFile(multipartRequest, optUploadFileReqDto, getLoginAuthDto(), true);
for (final OptUploadFileRespDto fileRespDto : optUploadFileRespDtos) {
temp.append(fileRespDto.getAttachmentId()).append(",");
}
String attachmentIds = temp.toString();
if (StringUtils.isNotEmpty(attachmentIds)) {
attachmentIds = StringUtils.substringBeforeLast(attachmentIds, GlobalConstant.Symbol.COMMA);
}
return WrapMapper.ok(attachmentIds);
}
use of com.paascloud.provider.model.dto.oss.OptUploadFileRespDto in project paascloud-master by paascloud.
the class OpcFileController method uploadPictureWithWangEditor.
/**
* Upload picture with wang editor map.
*
* @param request the request
* @param optUploadFileReqDto the opt upload file req dto
*
* @return the map
*/
@PostMapping(consumes = "multipart/form-data", value = "/uploadPictureWithWangEditor")
@ApiOperation(httpMethod = "POST", value = "上传文件")
public Map<String, Object> uploadPictureWithWangEditor(HttpServletRequest request, OptUploadFileReqDto optUploadFileReqDto) {
logger.info("uploadWangEditor - 上传文件. optUploadFileReqDto={}", optUploadFileReqDto);
String fileType = optUploadFileReqDto.getFileType();
String bucketName = optUploadFileReqDto.getBucketName();
Preconditions.checkArgument(StringUtils.isNotEmpty(fileType), "文件类型为空");
Preconditions.checkArgument(StringUtils.isNotEmpty(bucketName), "存储地址为空");
optUploadFileReqDto.setFilePath("paascloud/picture/wangEditor/");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<OptUploadFileRespDto> optUploadFileRespDtos = optAttachmentService.uploadFile(multipartRequest, optUploadFileReqDto, getLoginAuthDto(), false);
List<String> imgUrlList = Lists.newArrayList();
for (final OptUploadFileRespDto fileRespDto : optUploadFileRespDtos) {
imgUrlList.add(fileRespDto.getAttachmentUrl());
}
Map<String, Object> map = Maps.newHashMap();
map.put("errno", 0);
map.put("data", imgUrlList.toArray());
return map;
}
use of com.paascloud.provider.model.dto.oss.OptUploadFileRespDto in project paascloud-master by paascloud.
the class OptQiniuOssServiceImpl method uploadFile.
@Override
public OptUploadFileRespDto uploadFile(byte[] uploadBytes, String fileName, String filePath, String bucketName) throws IOException {
log.info("uploadFile - 上传文件. fileName={}, bucketName={}", fileName, bucketName);
Preconditions.checkArgument(uploadBytes != null, "读取文件失败");
Preconditions.checkArgument(StringUtils.isNotEmpty(fileName), ErrorCodeEnum.OPC10040010.msg());
Preconditions.checkArgument(StringUtils.isNotEmpty(filePath), "文件路径不能为空");
Preconditions.checkArgument(StringUtils.isNotEmpty(bucketName), "存储节点不能为空");
InputStream is = new ByteArrayInputStream(uploadBytes);
String inputStreamFileType = FileTypeUtil.getType(is);
String newFileName = UniqueIdGenerator.generateId() + "." + inputStreamFileType;
// 检查数据大小
this.checkFileSize(uploadBytes);
Response response = uploadManager.put(uploadBytes, filePath + newFileName, getUpToken(bucketName));
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
log.info("uploadFile - 上传文件. [OK] putRet={}", putRet);
if (PublicUtil.isEmpty(putRet) || StringUtils.isEmpty(putRet.key)) {
throw new OpcBizException(ErrorCodeEnum.OPC10040009);
}
String fileUrl;
// 获取图片路径
if (StringUtils.equals(OPEN_IMG_BUCKET, bucketName)) {
fileUrl = paascloudProperties.getQiniu().getOss().getPublicHost() + "/" + filePath + newFileName;
} else {
String domainUrl = paascloudProperties.getQiniu().getOss().getPrivateHost();
fileUrl = this.getFileUrl(domainUrl, fileName);
}
OptUploadFileRespDto result = new OptUploadFileRespDto();
result.setAttachmentUrl(fileUrl);
result.setAttachmentName(newFileName);
result.setAttachmentPath(filePath);
return result;
}
use of com.paascloud.provider.model.dto.oss.OptUploadFileRespDto in project paascloud-master by paascloud.
the class PtcAlipayServiceImpl method pay.
/**
* Pay wrapper.
*
* @param orderNo the order no
* @param loginAuthDto the login auth dto
*
* @return the wrapper
*/
@Override
public Wrapper pay(String orderNo, LoginAuthDto loginAuthDto) {
Long userId = loginAuthDto.getUserId();
OrderDto order = omcOrderService.queryOrderDtoByUserIdAndOrderNo(userId, orderNo);
if (order == null) {
throw new OmcBizException(ErrorCodeEnum.OMC10031003);
}
// (必填) 商户网站订单系统中唯一订单号, 64个字符以内, 只能包含字母、数字、下划线,
// 需保证商户系统端不能重复, 建议通过数据库sequence生成,
String outTradeNo = order.getOrderNo();
// (必填) 订单标题, 粗略描述用户的支付目的。如“xxx品牌xxx门店当面付扫码消费”
String subject = "PCMall扫码支付,订单号:" + outTradeNo;
// (必填) 订单总金额, 单位为元, 不能超过1亿元
// 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】
String totalAmount = order.getPayment().toString();
// (可选) 订单不可打折金额, 可以配合商家平台配置折扣活动, 如果酒水不参与打折, 则将对应金额填写至此字段
// 如果该值未传入,但传入了【订单总金额】,【打折金额】,则该值默认为【订单总金额】-【打折金额】
String undiscountableAmount = "0";
// 卖家支付宝账号ID, 用于支持一个签约账号下支持打款到不同的收款账号, (打款到sellerId对应的支付宝账号)
// 如果该字段为空, 则默认为与支付宝签约的商户的PID, 也就是appid对应的PID
String sellerId = "";
// 订单描述, 可以对交易或商品进行一个详细地描述, 比如填写"购买商品2件共15.00元"
String body = "订单" + outTradeNo + "购买商品共" + totalAmount + "元";
// 商户操作员编号, 添加此参数可以为商户操作员做销售统计
String operatorId = "test_operator_id";
// (必填) 商户门店编号, 通过门店号和商家后台可以配置精准到门店的折扣信息, 详询支付宝技术支持
String storeId = "test_store_id";
// 业务扩展参数, 目前可添加由支付宝分配的系统商编号(通过setSysServiceProviderId方法), 详情请咨询支付宝技术支持
ExtendParams extendParams = new ExtendParams();
extendParams.setSysServiceProviderId("2088100200300400500");
// 支付超时, 定义为120分钟
String timeoutExpress = "120m";
// 商品明细列表, 需填写购买商品详细信息,
List<GoodsDetail> goodsDetailList = Lists.newArrayList();
List<OmcOrderDetail> orderItemList = omcOrderDetailService.getListByOrderNoUserId(orderNo, userId);
for (OmcOrderDetail orderItem : orderItemList) {
GoodsDetail goods = GoodsDetail.newInstance(orderItem.getProductId().toString(), orderItem.getProductName(), BigDecimalUtil.mul(orderItem.getCurrentUnitPrice().doubleValue(), 100D).longValue(), orderItem.getQuantity());
goodsDetailList.add(goods);
}
// 创建扫码支付请求builder, 设置请求参数
AlipayTradePrecreateRequestBuilder builder = new AlipayTradePrecreateRequestBuilder().setSubject(subject).setTotalAmount(totalAmount).setOutTradeNo(outTradeNo).setUndiscountableAmount(undiscountableAmount).setSellerId(sellerId).setBody(body).setOperatorId(operatorId).setStoreId(storeId).setExtendParams(extendParams).setTimeoutExpress(timeoutExpress).setNotifyUrl(alipayCallbackUrl).setGoodsDetailList(goodsDetailList);
AlipayF2FPrecreateResult result = tradeService.tradePrecreate(builder);
switch(result.getTradeStatus()) {
case SUCCESS:
log.info("支付宝预下单成功: )");
AlipayTradePrecreateResponse response = result.getResponse();
dumpResponse(response);
// 需要修改为运行机器上的路径
File folder = new File(qrCodePcPath);
if (!folder.exists()) {
folder.setWritable(true);
folder.mkdirs();
}
// 细节细节细节
String qrPath = String.format(qrCodePcPath + "/qr-%s.png", response.getOutTradeNo());
String qrFileName = String.format("qr-%s.png", response.getOutTradeNo());
ZxingUtils.getQRCodeImge(response.getQrCode(), 256, qrPath);
File qrCodeImage = new File(qrPath);
OptUploadFileReqDto optUploadFileReqDto = new OptUploadFileReqDto();
optUploadFileReqDto.setBucketName("paascloud-oss-bucket");
optUploadFileReqDto.setFilePath(qrCodeQiniuPath);
optUploadFileReqDto.setFileType("png");
optUploadFileReqDto.setUserId(loginAuthDto.getUserId());
optUploadFileReqDto.setUserName(loginAuthDto.getUserName());
OptUploadFileByteInfoReqDto optUploadFileByteInfoReqDto = new OptUploadFileByteInfoReqDto();
optUploadFileByteInfoReqDto.setFileName(qrFileName);
byte[] bytes = FileUtil.readBytes(qrCodeImage);
optUploadFileByteInfoReqDto.setFileByteArray(bytes);
optUploadFileReqDto.setUploadFileByteInfoReqDto(optUploadFileByteInfoReqDto);
OptUploadFileRespDto optUploadFileRespDto = null;
try {
optUploadFileRespDto = opcOssService.uploadFile(optUploadFileReqDto);
optUploadFileRespDto.setRefNo(orderNo);
// 获取二维码
final OptGetUrlRequest request = new OptGetUrlRequest();
request.setAttachmentId(optUploadFileRespDto.getAttachmentId());
request.setEncrypt(true);
String fileUrl = opcOssService.getFileUrl(request);
optUploadFileRespDto.setAttachmentUrl(fileUrl);
} catch (Exception e) {
log.error("上传二维码异常", e);
}
return WrapMapper.ok(optUploadFileRespDto);
case FAILED:
log.error("支付宝预下单失败!!!");
return WrapMapper.error("支付宝预下单失败!!!");
case UNKNOWN:
log.error("系统异常, 预下单状态未知!!!");
return WrapMapper.error("系统异常, 预下单状态未知!!!");
default:
log.error("不支持的交易状态, 交易返回异常!!!");
return WrapMapper.error("不支持的交易状态, 交易返回异常!!!");
}
}
Aggregations