use of com.paascloud.provider.model.dto.attachment.OptUploadFileByteInfoReqDto in project paascloud-master by paascloud.
the class OptAttachmentServiceImpl method rpcUploadFile.
@Override
public OptUploadFileRespDto rpcUploadFile(OptUploadFileReqDto optUploadFileReqDto) throws IOException {
String fileType = optUploadFileReqDto.getFileType();
String filePath = optUploadFileReqDto.getFilePath();
String bucketName = optUploadFileReqDto.getBucketName();
OptUploadFileByteInfoReqDto uploadFileByteInfoReqDto = optUploadFileReqDto.getUploadFileByteInfoReqDto();
LoginAuthDto authResDto = new LoginAuthDto();
authResDto.setUserId(optUploadFileReqDto.getUserId());
authResDto.setUserName(optUploadFileReqDto.getUserName());
if (PublicUtil.isEmpty(filePath)) {
filePath = GlobalConstant.Oss.DEFAULT_FILE_PATH;
}
InputStream is = null;
try {
Preconditions.checkArgument(uploadFileByteInfoReqDto != null, "上传数据不能为空");
byte[] fileByteArray = uploadFileByteInfoReqDto.getFileByteArray();
Preconditions.checkArgument(fileByteArray.length / GlobalConstant.M_SIZE <= GlobalConstant.FILE_MAX_SIZE, "上传文件不能大于5M");
String fileName = uploadFileByteInfoReqDto.getFileName();
is = new ByteArrayInputStream(fileByteArray);
String type = FileTypeUtil.getType(is);
Preconditions.checkArgument(type.equals(fileType), "文件类型不符");
fileName = filePath + fileName;
OptUploadFileRespDto optUploadFileRespDto = this.uploadFile(fileByteArray, fileName, fileType, filePath, bucketName, authResDto);
optUploadFileRespDto.setFileType(fileType);
return optUploadFileRespDto;
} catch (IOException e) {
logger.error("上传文件失败={}", e.getMessage(), e);
} finally {
if (null != is) {
is.close();
}
}
return null;
}
use of com.paascloud.provider.model.dto.attachment.OptUploadFileByteInfoReqDto 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