Search in sources :

Example 1 with OptGetUrlRequest

use of com.paascloud.provider.model.dto.oss.OptGetUrlRequest in project paascloud-master by paascloud.

the class MdcProductServiceImpl method getMainImage.

@Override
public String getMainImage(final Long productId) {
    MdcProduct product = mdcProductMapper.selectByPrimaryKey(productId);
    String url = null;
    if (product != null) {
        final OptGetUrlRequest request = new OptGetUrlRequest();
        request.setEncrypt(true);
        request.setAttachmentId(Long.valueOf(product.getMainImage()));
        request.setExpires(3600 * 12 * 7L);
        url = opcRpcService.getFileUrl(request);
    }
    return url;
}
Also used : OptGetUrlRequest(com.paascloud.provider.model.dto.oss.OptGetUrlRequest) MdcProduct(com.paascloud.provider.model.domain.MdcProduct)

Example 2 with OptGetUrlRequest

use of com.paascloud.provider.model.dto.oss.OptGetUrlRequest 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("不支持的交易状态, 交易返回异常!!!");
    }
}
Also used : OptUploadFileByteInfoReqDto(com.paascloud.provider.model.dto.attachment.OptUploadFileByteInfoReqDto) AlipayF2FPrecreateResult(com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult) GoodsDetail(com.alipay.demo.trade.model.GoodsDetail) OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) AlipayTradePrecreateResponse(com.alipay.api.response.AlipayTradePrecreateResponse) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OptUploadFileRespDto(com.paascloud.provider.model.dto.oss.OptUploadFileRespDto) OptUploadFileReqDto(com.paascloud.provider.model.dto.oss.OptUploadFileReqDto) OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OptGetUrlRequest(com.paascloud.provider.model.dto.oss.OptGetUrlRequest) AlipayTradePrecreateRequestBuilder(com.alipay.demo.trade.model.builder.AlipayTradePrecreateRequestBuilder) OrderDto(com.paascloud.provider.model.dto.OrderDto) ExtendParams(com.alipay.demo.trade.model.ExtendParams) File(java.io.File)

Example 3 with OptGetUrlRequest

use of com.paascloud.provider.model.dto.oss.OptGetUrlRequest in project paascloud-master by paascloud.

the class OmcCartServiceImpl method getOrderCartProduct.

@Override
public OrderProductVo getOrderCartProduct(Long userId) {
    Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
    OrderProductVo orderProductVo = new OrderProductVo();
    List<OmcCart> omcCartList = omcCartMapper.selectCheckedCartByUserId(userId);
    List<OmcOrderDetail> orderItemList = this.getCartOrderItem(userId, omcCartList);
    List<OrderItemVo> orderItemVoList = Lists.newArrayList();
    BigDecimal payment = new BigDecimal("0");
    for (OmcOrderDetail orderItem : orderItemList) {
        payment = BigDecimalUtil.add(payment.doubleValue(), orderItem.getTotalPrice().doubleValue());
        final OptGetUrlRequest request = new OptGetUrlRequest();
        request.setAttachmentId(Long.valueOf(orderItem.getProductImage()));
        request.setEncrypt(true);
        String fileUrl = opcOssService.getFileUrl(request);
        OrderItemVo orderItemVo = assembleOrderItemVo(orderItem);
        orderItemVo.setProductImage(fileUrl);
        orderItemVoList.add(orderItemVo);
    }
    orderProductVo.setProductTotalPrice(payment);
    orderProductVo.setOrderItemVoList(orderItemVoList);
    return orderProductVo;
}
Also used : OptGetUrlRequest(com.paascloud.provider.model.dto.oss.OptGetUrlRequest) OrderProductVo(com.paascloud.provider.model.vo.OrderProductVo) OmcOrderDetail(com.paascloud.provider.model.domain.OmcOrderDetail) OrderItemVo(com.paascloud.provider.model.vo.OrderItemVo) OmcCart(com.paascloud.provider.model.domain.OmcCart) BigDecimal(java.math.BigDecimal)

Example 4 with OptGetUrlRequest

use of com.paascloud.provider.model.dto.oss.OptGetUrlRequest in project paascloud-master by paascloud.

the class MdcProductServiceImpl method assembleProductDetailVo.

private ProductDetailVo assembleProductDetailVo(MdcProduct product) {
    ProductDetailVo productDetailVo = new ProductDetailVo();
    String mainImage = product.getMainImage();
    String subImages = product.getSubImages();
    if (StringUtils.isNotEmpty(mainImage)) {
        // 图片查询
        OptGetUrlRequest request = new OptGetUrlRequest();
        request.setAttachmentId(Long.valueOf(mainImage));
        request.setEncrypt(true);
        String url = opcRpcService.getFileUrl(request);
        productDetailVo.setMainImage(url);
    }
    if (StringUtils.isNotEmpty(subImages)) {
        List<String> urlList = Lists.newArrayList();
        List<String> subImageList = Splitter.on(GlobalConstant.Symbol.COMMA).trimResults().splitToList(subImages);
        for (final String subImage : subImageList) {
            OptGetUrlRequest request = new OptGetUrlRequest();
            request.setAttachmentId(Long.valueOf(subImage));
            request.setEncrypt(true);
            String url = opcRpcService.getFileUrl(request);
            urlList.add(url);
        }
        productDetailVo.setSubImages(Joiner.on(GlobalConstant.Symbol.COMMA).join(urlList));
    }
    productDetailVo.setId(product.getId());
    productDetailVo.setSubtitle(product.getSubtitle());
    productDetailVo.setPrice(product.getPrice());
    productDetailVo.setDetail(product.getDetail());
    productDetailVo.setName(product.getName());
    productDetailVo.setStatus(product.getStatus());
    productDetailVo.setStock(product.getStock());
    productDetailVo.setImageHost("");
    MdcProductCategory category = mdcProductCategoryService.getByCategoryId(product.getId());
    if (category == null) {
        // 默认根节点
        productDetailVo.setPid(0L);
    } else {
        productDetailVo.setPid(category.getPid());
    }
    return productDetailVo;
}
Also used : OptGetUrlRequest(com.paascloud.provider.model.dto.oss.OptGetUrlRequest) MdcProductCategory(com.paascloud.provider.model.domain.MdcProductCategory) ProductDetailVo(com.paascloud.provider.model.vo.ProductDetailVo)

Aggregations

OptGetUrlRequest (com.paascloud.provider.model.dto.oss.OptGetUrlRequest)4 OmcOrderDetail (com.paascloud.provider.model.domain.OmcOrderDetail)2 AlipayTradePrecreateResponse (com.alipay.api.response.AlipayTradePrecreateResponse)1 ExtendParams (com.alipay.demo.trade.model.ExtendParams)1 GoodsDetail (com.alipay.demo.trade.model.GoodsDetail)1 AlipayTradePrecreateRequestBuilder (com.alipay.demo.trade.model.builder.AlipayTradePrecreateRequestBuilder)1 AlipayF2FPrecreateResult (com.alipay.demo.trade.model.result.AlipayF2FPrecreateResult)1 OmcBizException (com.paascloud.provider.exceptions.OmcBizException)1 MdcProduct (com.paascloud.provider.model.domain.MdcProduct)1 MdcProductCategory (com.paascloud.provider.model.domain.MdcProductCategory)1 OmcCart (com.paascloud.provider.model.domain.OmcCart)1 OrderDto (com.paascloud.provider.model.dto.OrderDto)1 OptUploadFileByteInfoReqDto (com.paascloud.provider.model.dto.attachment.OptUploadFileByteInfoReqDto)1 OptUploadFileReqDto (com.paascloud.provider.model.dto.oss.OptUploadFileReqDto)1 OptUploadFileRespDto (com.paascloud.provider.model.dto.oss.OptUploadFileRespDto)1 OrderItemVo (com.paascloud.provider.model.vo.OrderItemVo)1 OrderProductVo (com.paascloud.provider.model.vo.OrderProductVo)1 ProductDetailVo (com.paascloud.provider.model.vo.ProductDetailVo)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1