Search in sources :

Example 1 with AlipayTradeAppPayResponse

use of com.alipay.api.response.AlipayTradeAppPayResponse in project synergic-developing by zeemood.

the class AlipayAssistant method preOrder4App.

/**
 * 支付宝APP支付
 *
 * @param notifyUrl
 * @param model
 * @return
 * @throws Exception
 */
public static String preOrder4App(String notifyUrl, AlipayTradeAppPayModel model) throws Exception {
    AlipayClient alipayClient = new DefaultAlipayClient(// 支付地址
    AlipayConfigurations.GATE_URL, // 应用id
    AlipayConfigurations.getAppid(), // 私钥
    AlipayConfigurations.getPrivateKey(), // 固定值json,参数类型,
    AlipayConstants.FORMAT_JSON, // 编码方式
    AlipayConstants.CHARSET_UTF8, // 公钥
    AlipayConfigurations.getPublicKey(), AlipayConstants.SIGN_TYPE_RSA2);
    // 实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    request.setBizModel(model);
    if (notifyUrl == null || "".equals(notifyUrl)) {
        throw new RuntimeException("异步通知回调地址不能为空");
    }
    // request.setNotifyUrl(AlipayConfigurations.getNotifyUrl(suffix));
    request.setNotifyUrl(notifyUrl);
    try {
        // 这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        return response.getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : AlipayTradeAppPayResponse(com.alipay.api.response.AlipayTradeAppPayResponse) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) AlipayApiException(com.alipay.api.AlipayApiException) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient)

Example 2 with AlipayTradeAppPayResponse

use of com.alipay.api.response.AlipayTradeAppPayResponse in project fw-cloud-framework by liuweijw.

the class AliUnifiedOrderServiceImpl method doAliUnifiedOrderRequest.

@Override
public R<Map<String, Object>> doAliUnifiedOrderRequest(String tradeType, PayOrder payOrder, Map<String, String> params) {
    try {
        if (null == payOrder || null == params || StringHelper.isBlank(tradeType) || StringHelper.isBlank(params.get("resKey")) || StringHelper.isBlank(params.get("channelParam")))
            return new R<Map<String, Object>>().data(PayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001)).failure();
        String resKey = params.get("resKey");
        String payOrderId = payOrder.getPayOrderId();
        AlipayConfig alipayConfig = AlipayUtil.init(params.get("channelParam"), params.get("returnUrl"));
        AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getAppId(), alipayConfig.getRsaPrivateKey(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipayPublicKey(), AlipayConfig.SIGNTYPE);
        Map<String, Object> map = PayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
        if (tradeType.equals(PayConstant.PAY_CHANNEL_ALIPAY_WAP)) {
            String logPrefix = "【支付宝WAP支付下单】";
            AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
            model.setOutTradeNo(payOrderId);
            model.setSubject(payOrder.getSubject());
            model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
            model.setBody(payOrder.getBody());
            model.setProductCode("QUICK_WAP_PAY");
            String objParams = payOrder.getExtra();
            if (StringUtils.isNotEmpty(objParams)) {
                JSONObject objParamsJson = JSON.parseObject(objParams);
                if (StringUtils.isNotBlank(objParamsJson.getString("quit_url"))) {
                    model.setQuitUrl(objParamsJson.getString("quit_url"));
                }
            }
            AlipayTradeWapPayRequest alipay_request = new AlipayTradeWapPayRequest();
            alipay_request.setBizModel(model);
            alipay_request.setNotifyUrl(alipayProperties.getNotifyUrl());
            alipay_request.setReturnUrl(alipayConfig.getReturnUrl());
            AlipayTradeWapPayResponse alipayTradeWapPayResponse = client.pageExecute(alipay_request);
            String payUrl = alipayTradeWapPayResponse.getBody();
            log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
            boolean result = payOrderService.updatePayOrderStatus4Paying(payOrderId, payOrderId);
            log.info("{}更新第三方支付订单号:payOrderId={},tradeNo={},result={}", logPrefix, payOrderId, alipayTradeWapPayResponse.getTradeNo(), result);
            log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
            map.put("tradeNo", alipayTradeWapPayResponse.getTradeNo());
            map.put("payOrderId", payOrderId);
            map.put("payUrl", payUrl);
            log.info("{}商户统一下单处理完成", logPrefix);
        } else if (tradeType.equals(PayConstant.PAY_CHANNEL_ALIPAY_PC)) {
            String logPrefix = "【支付宝PC支付下单】";
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();
            model.setOutTradeNo(payOrderId);
            model.setSubject(payOrder.getSubject());
            model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
            model.setBody(payOrder.getBody());
            model.setProductCode("FAST_INSTANT_TRADE_PAY");
            String objParams = payOrder.getExtra();
            String qr_pay_mode = "2";
            String qrcode_width = "200";
            if (StringUtils.isNotEmpty(objParams)) {
                JSONObject objParamsJson = JSON.parseObject(objParams);
                qr_pay_mode = objParamsJson.containsKey("qr_pay_mode") ? objParamsJson.getString("qr_pay_mode") : qr_pay_mode;
                qrcode_width = objParamsJson.containsKey("qrcode_width") ? objParamsJson.getString("qrcode_width") : qrcode_width;
            }
            model.setQrPayMode(qr_pay_mode);
            model.setQrcodeWidth(Long.parseLong(qrcode_width));
            AlipayTradePagePayRequest alipay_request = new AlipayTradePagePayRequest();
            alipay_request.setBizModel(model);
            alipay_request.setNotifyUrl(alipayProperties.getNotifyUrl());
            alipay_request.setReturnUrl(alipayConfig.getReturnUrl());
            AlipayTradePagePayResponse alipayTradePagePayResponse = client.pageExecute(alipay_request);
            String payUrl = alipayTradePagePayResponse.getBody();
            log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
            boolean result = payOrderService.updatePayOrderStatus4Paying(payOrderId, payOrderId);
            log.info("{}更新第三方支付订单号:payOrderId={},tradeNo={},result={}", logPrefix, payOrderId, alipayTradePagePayResponse.getTradeNo(), result);
            log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
            map.put("tradeNo", alipayTradePagePayResponse.getTradeNo());
            map.put("payOrderId", payOrderId);
            map.put("payUrl", payUrl);
            log.info("{}商户统一下单处理完成", logPrefix);
        } else if (tradeType.equals(PayConstant.PAY_CHANNEL_ALIPAY_MOBILE)) {
            String logPrefix = "【支付宝APP支付下单】";
            AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
            model.setOutTradeNo(payOrderId);
            model.setSubject(payOrder.getSubject());
            model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
            model.setBody(payOrder.getBody());
            model.setProductCode("QUICK_MSECURITY_PAY");
            AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
            alipay_request.setBizModel(model);
            alipay_request.setNotifyUrl(alipayProperties.getNotifyUrl());
            alipay_request.setReturnUrl(alipayConfig.getReturnUrl());
            AlipayTradeAppPayResponse alipayTradeAppPayResponse = client.sdkExecute(alipay_request);
            String payParams = alipayTradeAppPayResponse.getBody();
            boolean result = payOrderService.updatePayOrderStatus4Paying(payOrderId, payOrderId);
            log.info("{}更新第三方支付订单号:payOrderId={},tradeNo={},result={}", logPrefix, payOrderId, alipayTradeAppPayResponse.getTradeNo(), result);
            log.info("{}生成请求支付宝数据,payParams={}", logPrefix, payParams);
            map.put("tradeNo", alipayTradeAppPayResponse.getTradeNo());
            map.put("payOrderId", payOrderId);
            map.put("payParams", payParams);
            log.info("{}商户统一下单处理完成", logPrefix);
        } else if (tradeType.equals(PayConstant.PAY_CHANNEL_ALIPAY_QR)) {
            // 刷脸付 需要签约
            String logPrefix = "【支付宝当面付之扫码支付下单】";
            AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
            model.setOutTradeNo(payOrderId);
            model.setSubject(payOrder.getSubject());
            model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
            model.setBody(payOrder.getBody());
            String objParams = payOrder.getExtra();
            if (StringUtils.isNotEmpty(objParams)) {
                JSONObject objParamsJson = JSON.parseObject(objParams);
                if (StringUtils.isNotBlank(objParamsJson.getString("discountable_amount"))) {
                    // 可打折金额
                    model.setDiscountableAmount(objParamsJson.getString("discountable_amount"));
                }
                if (StringUtils.isNotBlank(objParamsJson.getString("undiscountable_amount"))) {
                    // 不可打折金额
                    model.setUndiscountableAmount(objParamsJson.getString("undiscountable_amount"));
                }
            }
            AlipayTradePrecreateRequest alipay_request = new AlipayTradePrecreateRequest();
            alipay_request.setBizModel(model);
            alipay_request.setNotifyUrl(alipayProperties.getNotifyUrl());
            alipay_request.setReturnUrl(alipayConfig.getReturnUrl());
            String payUrl = client.execute(alipay_request).getBody();
            log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
            boolean result = payOrderService.updatePayOrderStatus4Paying(payOrderId, payOrderId);
            log.info("{}更新第三方支付订单号:payOrderId={},result={}", logPrefix, payOrderId, result);
            log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
            map.put("payOrderId", payOrderId);
            map.put("payUrl", payUrl);
            log.info("{}商户统一下单处理完成", logPrefix);
        }
        return new R<Map<String, Object>>().data(PayUtil.makeRetData(map, resKey)).success();
    } catch (Exception e) {
        log.error("支付宝支付统一下单异常" + e);
        return new R<Map<String, Object>>().data(PayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001)).failure();
    }
}
Also used : AlipayConfig(com.github.liuweijw.business.pay.config.alipay.AlipayConfig) AlipayTradePagePayResponse(com.alipay.api.response.AlipayTradePagePayResponse) AlipayTradeAppPayModel(com.alipay.api.domain.AlipayTradeAppPayModel) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayTradeWapPayResponse(com.alipay.api.response.AlipayTradeWapPayResponse) AlipayTradePagePayRequest(com.alipay.api.request.AlipayTradePagePayRequest) R(com.github.liuweijw.commons.base.R) AlipayTradeAppPayResponse(com.alipay.api.response.AlipayTradeAppPayResponse) JSONObject(com.alibaba.fastjson.JSONObject) AlipayTradeWapPayModel(com.alipay.api.domain.AlipayTradeWapPayModel) AlipayTradePrecreateModel(com.alipay.api.domain.AlipayTradePrecreateModel) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) AlipayTradeWapPayRequest(com.alipay.api.request.AlipayTradeWapPayRequest) JSONObject(com.alibaba.fastjson.JSONObject) AlipayTradePagePayModel(com.alipay.api.domain.AlipayTradePagePayModel) Map(java.util.Map) AlipayTradeAppPayRequest(com.alipay.api.request.AlipayTradeAppPayRequest) AlipayTradePrecreateRequest(com.alipay.api.request.AlipayTradePrecreateRequest)

Aggregations

AlipayClient (com.alipay.api.AlipayClient)2 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)2 AlipayTradeAppPayResponse (com.alipay.api.response.AlipayTradeAppPayResponse)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AlipayApiException (com.alipay.api.AlipayApiException)1 AlipayTradeAppPayModel (com.alipay.api.domain.AlipayTradeAppPayModel)1 AlipayTradePagePayModel (com.alipay.api.domain.AlipayTradePagePayModel)1 AlipayTradePrecreateModel (com.alipay.api.domain.AlipayTradePrecreateModel)1 AlipayTradeWapPayModel (com.alipay.api.domain.AlipayTradeWapPayModel)1 AlipayTradeAppPayRequest (com.alipay.api.request.AlipayTradeAppPayRequest)1 AlipayTradePagePayRequest (com.alipay.api.request.AlipayTradePagePayRequest)1 AlipayTradePrecreateRequest (com.alipay.api.request.AlipayTradePrecreateRequest)1 AlipayTradeWapPayRequest (com.alipay.api.request.AlipayTradeWapPayRequest)1 AlipayTradePagePayResponse (com.alipay.api.response.AlipayTradePagePayResponse)1 AlipayTradeWapPayResponse (com.alipay.api.response.AlipayTradeWapPayResponse)1 AlipayConfig (com.github.liuweijw.business.pay.config.alipay.AlipayConfig)1 R (com.github.liuweijw.commons.base.R)1 Map (java.util.Map)1