glhcp/server/vendor/alipaysdk/easysdk/java/README.md

236 lines
14 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

[![Maven Central](https://img.shields.io/maven-central/v/com.alipay.sdk/alipay-easysdk.svg)](https://mvnrepository.com/artifact/com.alipay.sdk/alipay-easysdk)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk?ref=badge_shield)
使 Alipay **Easy** SDK for Java
Alipay Esay SDK for Java访SDKHTTP
Alipay Easy SDK for Java 使
##
[Alipay SDK](https://github.com/alipay/alipay-sdk-java-all)通用而全面的设计理念Alipay Easy SDK对开放能力的API进行了更加贴近高频场景的精心设计与裁剪简化了服务端调用方式让调用API像使用语言内置的函数一样简便。
APIAlipay Easy SDKAPI使
Alipay Easy SDK[](https://opendocs.alipay.com/mini/00am3f)相对应的代码组织结构让开发者可以快速找到不同能力对应的API。
Alipay Easy SDK****
##
1. Alipay Easy SDK for Java `JDK 1.8`
2. 使 Alipay Easy SDK for Java [-](https://openhome.alipay.com/platform/developerIndex.htm)完成开发者接入的一些准备工作,包括创建应用、为应用添加功能包、设置应用的接口加签方式等。
3. 使SDK
*
`AppId`````````
*
`AppId`````
##
### [Maven](https://mvnrepository.com/artifact/com.alipay.sdk/alipay-easysdk)来管理项目依赖
Maven`pom.xml`
```xml
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-easysdk</artifactId>
<version>Use the version shown in the maven badge</version>
</dependency>
```
##
###
使Alipay Easy SDK for JavaAPI3
1.
2. API
3.
```java
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.factory.Factory.Payment;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
public class Main {
public static void main(String[] args) throws Exception {
// 1. 设置参数(全局只需设置一次)
Factory.setOptions(getOptions());
try {
// 2. 发起API调用以创建当面付收款二维码为例
AlipayTradePrecreateResponse response = Payment.FaceToFace()
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
// 3. 处理响应或异常
if (ResponseChecker.success(response)) {
System.out.println("调用成功");
} else {
System.err.println("调用失败,原因:" + response.msg + "" + response.subMsg);
}
} catch (Exception e) {
System.err.println("调用遭遇异常,原因:" + e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}
private static Config getOptions() {
Config config = new Config();
config.protocol = "https";
config.gatewayHost = "openapi.alipay.com";
config.signType = "RSA2";
config.appId = "<-- 请填写您的AppId例如2019091767145019 -->";
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
config.merchantPrivateKey = "<-- 请填写您的应用私钥例如MIIEvQIBADANB ... ... -->";
//注证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径优先从文件系统中加载加载失败后会继续尝试从CLASS_PATH中加载
config.merchantCertPath = "<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->";
config.alipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->";
config.alipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt -->";
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
// config.alipayPublicKey = "<-- 请填写您的支付宝公钥例如MIIBIjANBg... -->";
//可设置异步通知接收服务地址(可选)
config.notifyUrl = "<-- 请填写您的支付类接口异步通知接收服务地址例如https://www.test.com/callback -->";
//可设置AES密钥调用AES加解密相关接口时需要可选
config.encryptKey = "<-- 请填写您的AES密钥例如aa4BtZ4tspm2wnXLb1ThQA== -->";
return config;
}
}
```
###
#### ISV
```java
Factory.Payment.FaceToFace()
// 调用agent扩展方法设置app_auth_token完成ISV代调用
.agent("ca34ea491e7146cc87d25fca24c4cD11")
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```java
Factory.Payment.FaceToFace()
// 调用asyncNotify扩展方法可以为每此API调用设置独立的异步通知地址
// 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址
.asyncNotify("https://www.test.com/callback")
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```java
List<Object> goodsDetailList = new ArrayList<>();
Map<String, Object> goodsDetail = new HashMap<>();
goodsDetail.put("goods_id", "apple-01");
goodsDetail.put("goods_name", "Apple iPhone11 128G");
goodsDetail.put("quantity", 1);
goodsDetail.put("price", "5799.00");
goodsDetailList.add(goodsDetail);
Factory.Payment.FaceToFace()
// 调用optional扩展方法完成可选业务参数biz_content下的可选字段的设置
.optional("seller_id", "2088102146225135")
.optional("discountable_amount", "8.88")
.optional("goods_detail", goodsDetailList)
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
Map<String, Object> optionalArgs = new HashMap<>();
optionalArgs.put("seller_id", "2088102146225135");
optionalArgs.put("discountable_amount", "8.88");
optionalArgs.put("goods_detail", goodsDetailList);
Factory.Payment.FaceToFace()
// 也可以调用batchOptional扩展方法批量设置可选业务参数biz_content下的可选字段
.batchOptional(optionalArgs)
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```java
// 多种扩展方式可灵活组装(对扩展方法的调用顺序没有要求)
Factory.Payment.FaceToFace()
.agent("ca34ea491e7146cc87d25fca24c4cD11")
.asyncNotify("https://www.test.com/callback")
.optional("seller_id", "2088102146225135")
.preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
## API
Alipay Easy SDKAPI
> Factory..().( ... )
使[](https://opendocs.alipay.com/mini/00am3f)中`营销能力`下的`模板消息`场景中的`小程序发送模板消息`,只需按如下形式编写调用代码即可。
`Factory.Marketing.TemplateMessage().send( ... )`
OpenAPIOpenAPIOpenAPI使
Alipay Easy SDKAPI
## API
| | | | OpenAPI |
|-----------|-----------------|------------------------|-----------------------------------------------------------|
| Base | OAuth | getToken | alipay\.system\.oauth\.token |
| Base | OAuth | refreshToken | alipay\.system\.oauth\.token |
| Base | Qrcode | create | alipay\.open\.app\.qrcode\.create |
| Base | Image | upload | alipay\.offline\.material\.image\.upload |
| Base | Video | upload | alipay\.offline\.material\.image\.upload |
| Member | Identification | init | alipay\.user\.certify\.open\.initialize |
| Member | Identification | certify | alipay\.user\.certify\.open\.certify |
| Member | Identification | query | alipay\.user\.certify\.open\.query |
| Payment | Common | create | alipay\.trade\.create |
| Payment | Common | query | alipay\.trade\.query |
| Payment | Common | refund | alipay\.trade\.refund |
| Payment | Common | close | alipay\.trade\.close |
| Payment | Common | cancel | alipay\.trade\.cancel |
| Payment | Common | queryRefund | alipay\.trade\.fastpay\.refund\.query |
| Payment | Common | downloadBill | alipay\.data\.dataservice\.bill\.downloadurl\.query |
| Payment | Common | verifyNotify | - |
| Payment | Huabei | create | alipay\.trade\.create |
| Payment | FaceToFace | pay | alipay\.trade\.pay |
| Payment | FaceToFace | precreate | alipay\.trade\.precreate |
| Payment | App | pay | alipay\.trade\.app\.pay |
| Payment | Page | pay | alipay\.trade\.page\.pay |
| Payment | Wap | pay | alipay\.trade\.wap\.pay |
| Security | TextRisk | detect | alipay\.security\.risk\.content\.detect |
| Marketing | Pass | createTemplate | alipay\.pass\.template\.add |
| Marketing | Pass | updateTemplate | alipay\.pass\.template\.update |
| Marketing | Pass | addInstance | alipay\.pass\.instance\.add |
| Marketing | Pass | updateInstance | alipay\.pass\.instance\.update |
| Marketing | TemplateMessage | send | alipay\.open\.app\.mini\.templatemessage\.send |
| Marketing | OpenLife | createImageTextContent | alipay\.open\.public\.message\.content\.create |
| Marketing | OpenLife | modifyImageTextContent | alipay\.open\.public\.message\.content\.modify |
| Marketing | OpenLife | sendText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendImageText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendSingleMessage | alipay\.open\.public\.message\.single\.send |
| Marketing | OpenLife | recallMessage | alipay\.open\.public\.life\.msg\.recall |
| Marketing | OpenLife | setIndustry | alipay\.open\.public\.template\.message\.industry\.modify |
| Marketing | OpenLife | getIndustry | alipay\.open\.public\.setting\.category\.query |
| Util | AES | decrypt | - |
| Util | AES | encrypt | - |
| Util | Generic | execute | - |
| Util | Generic | sdkExecute | - |
| Util | Generic | fileExecute | - |
> API
##
[API Doc](./../APIDoc.md)
[Alipay Easy SDK](./../README.md)