Java Code Examples for com.alipay.api.AlipayClient#sdkExecute()

The following examples show how to use com.alipay.api.AlipayClient#sdkExecute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AliAppTradePayImpl.java    From common-project with Apache License 2.0 6 votes vote down vote up
@Override
public AliTradePayResponse createTradePay(AliTradeAppPayParams aliTradeAppPayParams) throws Exception {
    AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliPayConfig.getAppId(),aliPayConfig.getAppPrivateKey(),"json",aliPayConfig.getCharset(),aliPayConfig.getAliPayPublicKey(),aliPayConfig.getSignType());
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    request.setNotifyUrl(aliTradeAppPayParams.getNotifyUrl());
    Map<String,Object> bizContent = new HashMap<>();
    bizContent.put("total_amount", aliTradeAppPayParams.getTotalAmount());
    bizContent.put("subject", aliTradeAppPayParams.getSubject());
    bizContent.put("out_trade_no", aliTradeAppPayParams.getOutTradeNo());
    request.setBizContent(JSON.toJSONString(bizContent));
    AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
    if(!response.isSuccess()){
        return null;
    }
    logger.info("支付宝APP统一下单成功");
    return AliTradePayResponse.generator(response);
}
 
Example 2
Source File: PayUtil.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 支付宝订单创建
 * @param out_trade_no 商户订单号,商户网站订单系统中唯一订单号,必填
 * @param subject      订单名称,必填
 * @param total_amount 付款金额,必填
 * @param body         商品描述,可空
 */
public static String createOrder(String out_trade_no, String subject, String total_amount, String body) throws Exception {
    if (Strings.isEmpty(out_trade_no) || Strings.isEmpty(subject) || Strings.isEmpty(total_amount)) {
        throw new Exception("支付宝参数异常");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY,
            AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
    //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody(body);
    model.setSubject(subject);
    model.setOutTradeNo(out_trade_no);
    model.setTimeoutExpress("30m");
    model.setTotalAmount(total_amount);
    model.setProductCode("QUICK_MSECURITY_PAY");
    request.setBizModel(model);
    request.setNotifyUrl(AlipayConfig.notify_url);
    try {
        //这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        System.out.println(response.getBody());
        return response.getBody();
        //就是orderString 可以直接给客户端请求,无需再做处理。
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return null;
}