Search in sources :

Example 1 with DefaultAlipayClient

use of com.alipay.api.DefaultAlipayClient 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 DefaultAlipayClient

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

the class AlipayAssistant method refund.

/**
 * 退款接口
 *
 * @param model
 * @return
 * @throws Exception
 */
public static AlipayTradeRefundResponse refund(AlipayTradeRefundModel 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);
    AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
    request.setBizModel(model);
    AlipayTradeRefundResponse response = alipayClient.execute(request);
    if (!response.isSuccess()) {
        throw new RuntimeException("调用失败");
    }
    return response;
}
Also used : AlipayTradeRefundResponse(com.alipay.api.response.AlipayTradeRefundResponse) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient)

Example 3 with DefaultAlipayClient

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

the class AlipayAssistant method preOrder4Web.

/**
 * 网页支付
 *
 * @param model
 * @param return_url
 * @param notify_url
 * @return
 * @throws Exception
 */
public static String preOrder4Web(AlipayTradePagePayModel model, String return_url, String notify_url) throws Exception {
    String html = "";
    // 获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfigurations.GATE_URL, AlipayConfigurations.getAppid(), AlipayConfigurations.getPrivateKey(), AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8, AlipayConfigurations.getPublicKey(), AlipayConstants.SIGN_TYPE_RSA2);
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
    if (return_url != null && !"".equals(return_url)) {
        request.setReturnUrl(return_url);
    }
    request.setNotifyUrl(notify_url);
    request.setBizModel(model);
    html = alipayClient.pageExecute(request).getBody();
    return html;
}
Also used : DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient)

Example 4 with DefaultAlipayClient

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

the class AlipayAssistant method preOrder4Wap.

/**
 * 手机网页支付
 *
 * @param model
 * @param return_url
 * @param notify_url
 * @return 返回的是一个网页
 * @throws Exception
 */
public static String preOrder4Wap(AlipayTradeWapPayModel model, String return_url, String notify_url) throws Exception {
    String html = "";
    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);
    AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
    if (return_url != null && !"".equals(return_url)) {
        request.setReturnUrl(return_url);
    }
    request.setNotifyUrl(notify_url);
    request.setBizModel(model);
    AlipayTradeWapPayResponse response = alipayClient.pageExecute(request);
    html = response.getBody();
    return html;
}
Also used : DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayTradeWapPayResponse(com.alipay.api.response.AlipayTradeWapPayResponse)

Example 5 with DefaultAlipayClient

use of com.alipay.api.DefaultAlipayClient in project leopard by tanhaichao.

the class AlipayClientImpl method init.

@PostConstruct
public void init() {
    alipay = AlipayBuilder.newBuilder(partner, privateKey).build();
    AliPayApiConfig aliPayApiConfig = AliPayApiConfig.New();
    aliPayApiConfig.setAppId(partner);
    aliPayApiConfig.setPrivateKey(privateKey);
    aliPayApiConfig.setAlipayPublicKey(publicKey);
    aliPayApiConfig.setServiceUrl(gatewayUrl);
    aliPayApiConfig.setCharset("UTF-8");
    aliPayApiConfig.setSignType("RSA2");
    aliPayApiConfig.build();
    System.err.println("appId:" + appId);
    System.err.println("gatewayUrl:" + gatewayUrl);
    AliPayApiConfigKit.putApiConfig(aliPayApiConfig);
    alipayClient = new DefaultAlipayClient(gatewayUrl, appId, privateKey, "json", "UTF-8", publicKey, "RSA2");
}
Also used : DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AliPayApiConfig(com.jpay.alipay.AliPayApiConfig) PostConstruct(javax.annotation.PostConstruct)

Aggregations

DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)7 AlipayClient (com.alipay.api.AlipayClient)6 AlipayTradeAppPayResponse (com.alipay.api.response.AlipayTradeAppPayResponse)2 AlipayTradeWapPayResponse (com.alipay.api.response.AlipayTradeWapPayResponse)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 AlipayTradeQueryResponse (com.alipay.api.response.AlipayTradeQueryResponse)1 AlipayTradeRefundResponse (com.alipay.api.response.AlipayTradeRefundResponse)1 AlipayConfig (com.github.liuweijw.business.pay.config.alipay.AlipayConfig)1 R (com.github.liuweijw.commons.base.R)1 AliPayApiConfig (com.jpay.alipay.AliPayApiConfig)1