阿里支付开发

gateway:"https://openapi.alipaydev.com/gateway.do"
appId: "这是收款方的appid,采用沙箱环境的话就是那个appid"
privateKey: "应用私钥"
format: "json"
charset: "UTF-8"
publicKey: "支付宝公钥"
signType: "RSA2"
return_url:"表示处理了业务以后成功跳转的地址"
notify_url:"响应的url,回调的controller,必须公网能访问"
##### 支付宝二维码支付(可参考官方文档,已经非常详细)

//支付宝退款接口,


public static String RefundOrder(TradeRefundVo tradeRefund) throws BizException {
//TradeRefundVo 自己定义的实体类,可根据官方文档的api进行封装
    AlipayConfig alipay = AlipayConfig.getInstance();
    //实例化客户端
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGateway(), alipay.getAppId(),
            alipay.getPrivateKey(), alipay.getFormat(),
            alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
    AlipayTradeRefundRequest alipayTradeRefundRequest = new AlipayTradeRefundRequest();
    AlipayTradeRefundModel alipayTradeRefundModel = new AlipayTradeRefundModel();
    alipayTradeRefundModel.setOutTradeNo(tradeRefund.getOut_trade_no());
    alipayTradeRefundModel.setRefundAmount(tradeRefund.getRefund_amount());
    alipayTradeRefundModel.setRefundReason(tradeRefund.getTrade_reason());
    alipayTradeRefundRequest.setBizModel(alipayTradeRefundModel);
    try {
        AlipayTradeRefundResponse response = alipayClient.execute(alipayTradeRefundRequest);
        logger.info("response请求体的参数为{}" + response.getBody());
        if (response.isSuccess()) {
            System.out.println("退款接口调用成功");
        } else {
            System.out.println("退款接口调用失败");
        }
        return response.getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
        logger.info("退款出现异常");
        logger.error(e.getMessage(), e.fillInStackTrace());
        throw new BizException(AlipayException);
    }
}

你可能感兴趣的:(java,程序员)