商家接入指南
接入流程图

支付消息

小程序支付消息
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AlipayOpenMiniTemplatemsgTinypayswitchApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AlipayOpenMiniTemplatemsgTinypayswitchApiConfirm {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AlipayOpenMiniTemplatemsgTinypayswitchApi api = new AlipayOpenMiniTemplatemsgTinypayswitchApi();
try {
Object response = api.confirm();
} catch (ApiException e) {
AlipayOpenMiniTemplatemsgTinypayswitchConfirmDefaultResponse errorObject = (AlipayOpenMiniTemplatemsgTinypayswitchConfirmDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
非小程序支付消息
查询可关联 PID
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AntMerchantExpandApprecommendAvailableApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AntMerchantExpandApprecommendAvailableApiQuery {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AntMerchantExpandApprecommendAvailableApi api = new AntMerchantExpandApprecommendAvailableApi();
Integer pageSize = 10;
Integer pageNumber = 1;
try {
AntMerchantExpandApprecommendAvailableQueryResponseModel response = api.query(pageSize, pageNumber);
} catch (ApiException e) {
AntMerchantExpandApprecommendAvailableQueryDefaultResponse errorObject = (AntMerchantExpandApprecommendAvailableQueryDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
关联 PID 和小程序
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AntMerchantExpandApprecommendAccountApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AntMerchantExpandApprecommendAccountApiCreate {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AntMerchantExpandApprecommendAccountApi api = new AntMerchantExpandApprecommendAccountApi();
AntMerchantExpandApprecommendAccountCreateModel data = new AntMerchantExpandApprecommendAccountCreateModel();
data.setAppNo("2021000155639069");
data.setAccNo("2088001969784501");
try {
Object response = api.create(data);
} catch (ApiException e) {
AntMerchantExpandApprecommendAccountCreateDefaultResponse errorObject = (AntMerchantExpandApprecommendAccountCreateDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
查询己关联 PID
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AntMerchantExpandApprecommendAccountApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AntMerchantExpandApprecommendAccountApiQuery {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AntMerchantExpandApprecommendAccountApi api = new AntMerchantExpandApprecommendAccountApi();
String appNo = "2021000155639069";
Integer pageSize = 10;
Integer pageNumber = 1;
try {
AntMerchantExpandApprecommendAccountQueryResponseModel response = api.query(appNo, pageSize, pageNumber);
} catch (ApiException e) {
AntMerchantExpandApprecommendAccountQueryDefaultResponse errorObject = (AntMerchantExpandApprecommendAccountQueryDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
取消关联
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AntMerchantExpandApprecommendAccountApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AntMerchantExpandApprecommendAccountApiDelete {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AntMerchantExpandApprecommendAccountApi api = new AntMerchantExpandApprecommendAccountApi();
String appNo = "2021000155639069";
String accNo = "2088001969784501";
try {
Object response = api.delete(appNo, accNo);
} catch (ApiException e) {
AntMerchantExpandApprecommendAccountDeleteDefaultResponse errorObject = (AntMerchantExpandApprecommendAccountDeleteDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
订单消息
订阅消息
1.
2.
3.
领用订阅消息模板
方式一
1.

2.

3.

4.
说明:右侧示例图会实时展示该订阅消息在用户界面效果。

5.

方式二
调用订阅组件

订阅组件案例展示
一次性订阅消息

长期性订阅消息

订阅组件接入方式说明
订阅组件类型 | 适用商家类型及场景 | 接入方式 | 支持订阅消息类型 | 使用规则 | 示例与说明 |
---|---|---|---|---|---|
订阅半弹层组件 | 有较强开发能力及前端资源,需要有自定义的弹层拉齐逻辑 | 调用 OpenAPI | 一次性订阅、长期订阅 | 仅支持应用于小程序页面,暂不支持 H5。一个小程序可创建多个订阅半弹层组件,可进行自行调用。一个组件 最多可包含 3 个订阅消息模版。 | ![]() |
嵌入式订阅组件 | 开发能力有限或开发资源紧张,需快速上线相应模版 | 后台配置组件生成代码,商家技术将放入页面中 | 长期订阅 | 仅支持应用于小程序页面,暂不支持 H5。一个小程序可创建多个嵌入式订阅组件,每个组件有唯一的 ID,审核通过后即可生效使用。一个嵌入式订阅组件可以 最多包含 3 个订阅消息模板。嵌入式订阅组件标题支持自定义,建议 具备概括性,不得带有营销诱导性文案。按钮文案 订阅、副标题描述文案均不支持自定义。 | ![]() |
订阅半弹层组件
注意:基础库 v1.x 从 1.25.7 开始支持,基础库 v2.x 从 2.7.10 开始支持。
my.requestSubscribeMessage({
//需要用户订阅的消息模板的id的集合
entityIds: ['ac768fca1ce245ccae9404bb5243c49b', '9aa357acb7c6434aba294aded1cdfb7c'],
success: (res) => {
// res.behavior=='subscribe'
console.log("接口调用成功的回调", res);
},
fail: (res) => {
console.log("接口调用失败的回调", res);
},
complete: (res) => {
console.log("接口调用结束的回调", res)
}
});
订阅嵌入式组件
配置及管理订阅组件
1.

2.

3.

4.

5.

6.

7.
注意:

1.

2.

3.

接入嵌入式订阅组件
管理组件

发送订阅消息
调用流程图

示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AlipayOpenAppMiniTemplatemessageApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AlipayOpenAppMiniTemplatemessageApiSend {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AlipayOpenAppMiniTemplatemessageApi api = new AlipayOpenAppMiniTemplatemessageApi();
AlipayOpenAppMiniTemplatemessageSendModel data = new AlipayOpenAppMiniTemplatemessageSendModel();
data.setFormId("2017010100000000580012345678");
data.setData("{\"keyword1\": {\"value\" : \"12:00\"},\"keyword2\": {\"value\" : \"20180808\"},\"keyword3\": {\"value\" : \"支付宝\"}}");
data.setPage("page/component/index");
data.setUserTemplateId("MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=");
data.setToUserId("2088102122458832");
try {
Object response = api.send(data);
} catch (ApiException e) {
AlipayOpenAppMiniTemplatemessageSendDefaultResponse errorObject = (AlipayOpenAppMiniTemplatemessageSendDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
注意**:占位符必须和申请模板时的关键词一一匹配(包括顺序)。
辅助功能
查询消息订阅关系
示例代码
package com.java.sdk.demo;
import com.alipay.v3.ApiException;
import com.alipay.v3.ApiClient;
import com.alipay.v3.util.model.AlipayConfig;
import com.alipay.v3.Configuration;
import com.alipay.v3.api.AlipayOpenAppMessagetemplateSubscribeApi;
import com.alipay.v3.model.*;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AlipayOpenAppMessagetemplateSubscribeApiQuery {
public static void main(String[] args) throws ApiException {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// 初始化alipay参数(全局设置一次)
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setPrivateKey("<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->");
alipayConfig.setAlipayPublicKey("<-- 请填写您的支付宝公钥,例如:MIIBIjANBg... -->");
defaultClient.setAlipayConfig(alipayConfig);
AlipayOpenAppMessagetemplateSubscribeApi api = new AlipayOpenAppMessagetemplateSubscribeApi();
AlipayOpenAppMessagetemplateSubscribeQueryModel data = new AlipayOpenAppMessagetemplateSubscribeQueryModel();
List<String> templateIdList = new ArrayList<String>();
templateIdList.add("6511999536b14ba5830e3a0289ea69a");
templateIdList.add("0b1fcca882aa435382ae98641e14d37");
templateIdList.add("a3b396be6fd345579221af5dea35028");
data.setTemplateIdList(templateIdList);
data.setUserId("2088202882050410");
try {
AlipayOpenAppMessagetemplateSubscribeQueryResponseModel response = api.query(data);
} catch (ApiException e) {
AlipayOpenAppMessagetemplateSubscribeQueryDefaultResponse errorObject = (AlipayOpenAppMessagetemplateSubscribeQueryDefaultResponse) e.getErrorObject();
System.out.println("调用失败:" + errorObject);
}
}
}
重要入参说明
修改于 2023-11-21 05:55:51