All URIs are relative to https://openapi.alipay.com
Method | HTTP request | Description |
---|---|---|
cancel | POST /v3/alipay/trade/cancel | 统一收单交易撤销接口 |
close | POST /v3/alipay/trade/close | 统一收单交易关闭接口 |
create | POST /v3/alipay/trade/create | 统一收单交易创建接口 |
pay | POST /v3/alipay/trade/pay | 统一收单交易支付接口 |
precreate | POST /v3/alipay/trade/precreate | 统一收单线下交易预创建 |
query | POST /v3/alipay/trade/query | 统一收单交易查询 |
refund | POST /v3/alipay/trade/refund | 统一收单交易退款接口 |
AlipayTradeCancelResponseModel cancel(alipayTradeCancelModel)
统一收单交易撤销接口
支付交易返回失败或支付系统超时,调用该接口撤销交易。如果此订单用户支付失败,支付宝系统会将此订单关闭;如果用户支付成功,支付宝系统会将此订单资金退还给用户。 注意:只有发生支付系统超时或者支付结果未知时可调用撤销,其他正常支付的单如需实现相同功能请调用申请退款API。提交支付交易后调用【查询订单API】,没有明确的支付结果再调用【撤销订单API】。
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradeCancelModel alipayTradeCancelModel = new AlipayTradeCancelModel(); // AlipayTradeCancelModel |
try {
AlipayTradeCancelResponseModel result = apiInstance.cancel(alipayTradeCancelModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#cancel");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradeCancelModel | AlipayTradeCancelModel | [optional] |
AlipayTradeCancelResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradeCloseResponseModel close(alipayTradeCloseModel)
统一收单交易关闭接口
用于交易创建后,用户在一定时间内未进行支付,可调用该接口直接将未付款的交易进行关闭。
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradeCloseModel alipayTradeCloseModel = new AlipayTradeCloseModel(); // AlipayTradeCloseModel |
try {
AlipayTradeCloseResponseModel result = apiInstance.close(alipayTradeCloseModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#close");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradeCloseModel | AlipayTradeCloseModel | [optional] |
AlipayTradeCloseResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradeCreateResponseModel create(alipayTradeCreateModel)
统一收单交易创建接口
商户通过该接口进行交易的创建下单
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradeCreateModel alipayTradeCreateModel = new AlipayTradeCreateModel(); // AlipayTradeCreateModel |
try {
AlipayTradeCreateResponseModel result = apiInstance.create(alipayTradeCreateModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#create");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradeCreateModel | AlipayTradeCreateModel | [optional] |
AlipayTradeCreateResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradePayResponseModel pay(alipayTradePayModel)
统一收单交易支付接口
收银员使用扫码设备读取用户手机支付宝“付款码”获取设备(如扫码枪)读取用户手机支付宝的付款码信息后,将二维码或条码信息通过本接口上送至支付宝发起支付。
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradePayModel alipayTradePayModel = new AlipayTradePayModel(); // AlipayTradePayModel |
try {
AlipayTradePayResponseModel result = apiInstance.pay(alipayTradePayModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#pay");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradePayModel | AlipayTradePayModel | [optional] |
AlipayTradePayResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradePrecreateResponseModel precreate(alipayTradePrecreateModel)
统一收单线下交易预创建
收银员通过收银台或商户后台调用支付宝接口,生成二维码后,展示给用户,由用户扫描二维码完成订单支付。
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradePrecreateModel alipayTradePrecreateModel = new AlipayTradePrecreateModel(); // AlipayTradePrecreateModel |
try {
AlipayTradePrecreateResponseModel result = apiInstance.precreate(alipayTradePrecreateModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#precreate");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradePrecreateModel | AlipayTradePrecreateModel | [optional] |
AlipayTradePrecreateResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradeQueryResponseModel query(alipayTradeQueryModel)
统一收单交易查询
该接口提供所有支付宝支付订单的查询,商户可以通过该接口主动查询订单状态,完成下一步的业务逻辑。 需要调用查询接口的情况: 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知; 调用支付接口后,返回系统错误或未知交易状态情况; 调用alipay.trade.pay,返回INPROCESS的状态; 调用alipay.trade.cancel之前,需确认支付状态;
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradeQueryModel alipayTradeQueryModel = new AlipayTradeQueryModel(); // AlipayTradeQueryModel |
try {
AlipayTradeQueryResponseModel result = apiInstance.query(alipayTradeQueryModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#query");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradeQueryModel | AlipayTradeQueryModel | [optional] |
AlipayTradeQueryResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |
AlipayTradeRefundResponseModel refund(alipayTradeRefundModel)
统一收单交易退款接口
当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,支付宝将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。 交易超过约定时间(签约时设置的可退款时间)的订单无法进行退款。 支付宝退款支持单笔交易分多次退款,多次退款需要提交原支付订单的订单号和设置不同的退款请求号。一笔退款失败后重新提交,要保证重试时退款请求号不能变更,防止该笔交易重复退款。 同一笔交易累计提交的退款金额不能超过原始交易总金额。
// Import classes:
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
import com.alipay.v3.util.*;
import com.alipay.v3.api.models.*;
import com.alipay.v3.api.AlipayTradeApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://openapi.alipay.com");
// 设置alipayConfig参数(全局设置一次)
AlipayConfig config = new AlipayConfig();
config.setAppId("app_id");
config.setPrivateKey("private_key");
config.setAlipayPublicKey("alipay_public_key");
config.setEncryptKey("encrypt_key");
defaultClient.setAlipayConfig(config);
AlipayTradeApi apiInstance = new AlipayTradeApi(defaultClient);
AlipayTradeRefundModel alipayTradeRefundModel = new AlipayTradeRefundModel(); // AlipayTradeRefundModel |
try {
AlipayTradeRefundResponseModel result = apiInstance.refund(alipayTradeRefundModel);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AlipayTradeApi#refund");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Name | Type | Description | Notes |
---|---|---|---|
alipayTradeRefundModel | AlipayTradeRefundModel | [optional] |
AlipayTradeRefundResponseModel
No authorization required
- Content-Type: application/json
- Accept: application/json
Status code | Description | Response headers |
---|---|---|
200 | common response | - |
0 | 请求失败 | - |