Skip to content

Commit cdfb3bb

Browse files
committed
代码整理优化
1 parent 9dc6692 commit cdfb3bb

22 files changed

Lines changed: 127 additions & 55 deletions

File tree

pay-java-ali/README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
## 支付宝支付简单例子
44

55
#### 支付配置
6-
6+
##### 普通公钥
77
```java
8-
9-
8+
9+
1010
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
1111
aliPayConfigStorage.setPid("合作者id");
1212
aliPayConfigStorage.setAppid("应用id");
@@ -21,6 +21,30 @@
2121
aliPayConfigStorage.setTest(true);
2222

2323
```
24+
##### 证书公钥
25+
```java
26+
27+
28+
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
29+
aliPayConfigStorage.setPid("合作者id");
30+
aliPayConfigStorage.setAppid("应用id");
31+
aliPayConfigStorage.setKeyPrivate("应用私钥");
32+
//设置为证书方式
33+
aliPayConfigStorage.setCertSign(true);
34+
//设置证书存储方式,这里为路径
35+
aliPayConfigStorage.setCertStoreType(CertStoreType.PATH);
36+
aliPayConfigStorage.setMerchantCert("请填写您的应用公钥证书文件路径,例如:d:/appCertPublicKey_2019051064521003.crt");
37+
aliPayConfigStorage.setAliPayCert("请填写您的支付宝公钥证书文件路径,例如:d:/alipayCertPublicKey_RSA2.crt");
38+
aliPayConfigStorage.setAliPayRootCert("请填写您的支付宝根证书文件路径,例如:d:/alipayRootCert.crt");
39+
aliPayConfigStorage.setNotifyUrl("异步回调地址");
40+
aliPayConfigStorage.setReturnUrl("同步回调地址");
41+
aliPayConfigStorage.setSignType("签名方式");
42+
aliPayConfigStorage.setSeller("收款账号");
43+
aliPayConfigStorage.setInputCharset("utf-8");
44+
//是否为测试账号,沙箱环境
45+
aliPayConfigStorage.setTest(true);
46+
47+
```
2448

2549

2650
#### 网络请求配置
@@ -85,7 +109,7 @@
85109
```java
86110

87111
//支付订单基础信息
88-
PayOrder payOrder = new PayOrder("订单title", "摘要", new BigDecimal(0.01) , UUID.randomUUID().toString().replace("-", ""));
112+
PayOrder payOrder = new PayOrder("订单title", "摘要", BigDecimal.valueOf(0.01) , UUID.randomUUID().toString().replace("-", ""));
89113

90114
```
91115

pay-java-ali/src/test/java/PayTest.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import com.egzosn.pay.ali.api.AliPayService;
33
import com.egzosn.pay.ali.bean.AliTransactionType;
44
import com.egzosn.pay.common.api.PayService;
5+
import com.egzosn.pay.common.bean.CertStoreType;
56
import com.egzosn.pay.common.bean.MethodType;
67
import com.egzosn.pay.common.bean.PayOrder;
78

@@ -20,12 +21,39 @@
2021
*/
2122
public class PayTest {
2223

24+
/**
25+
* 设置普通公钥的方式
26+
* 普通公钥方式与证书公钥方式为两者取其一的方式
27+
* @param aliPayConfigStorage 支付宝配置信息
28+
*
29+
*/
30+
private static void keyPublic(AliPayConfigStorage aliPayConfigStorage){
31+
aliPayConfigStorage.setKeyPublic("支付宝公钥");
32+
}
33+
34+
/**
35+
* 设置证书公钥信息
36+
* 普通公钥方式与证书公钥方式为两者取其一的方式
37+
* @param aliPayConfigStorage 支付宝配置信息
38+
*/
39+
private static void certKeyPublic(AliPayConfigStorage aliPayConfigStorage){
40+
//设置为证书方式
41+
aliPayConfigStorage.setCertSign(true);
42+
//设置证书存储方式,这里为路径
43+
aliPayConfigStorage.setCertStoreType(CertStoreType.PATH);
44+
aliPayConfigStorage.setMerchantCert("请填写您的应用公钥证书文件路径,例如:d:/appCertPublicKey_2019051064521003.crt");
45+
aliPayConfigStorage.setAliPayCert("请填写您的支付宝公钥证书文件路径,例如:d:/alipayCertPublicKey_RSA2.crt");
46+
aliPayConfigStorage.setAliPayRootCert("请填写您的支付宝根证书文件路径,例如:d:/alipayRootCert.crt");
47+
}
48+
2349
public static void main(String[] args) {
2450

2551
AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
2652
aliPayConfigStorage.setPid("合作者id");
2753
aliPayConfigStorage.setAppid("应用id");
28-
aliPayConfigStorage.setKeyPublic("支付宝公钥");
54+
//普通公钥方式与证书公钥方式为两者取其一的方式
55+
keyPublic(aliPayConfigStorage);
56+
// certKeyPublic(aliPayConfigStorage);
2957
aliPayConfigStorage.setKeyPrivate("应用私钥");
3058
aliPayConfigStorage.setNotifyUrl("异步回调地址");
3159
aliPayConfigStorage.setReturnUrl("同步回调地址");
@@ -37,7 +65,7 @@ public static void main(String[] args) {
3765
//支付服务
3866
PayService service = new AliPayService(aliPayConfigStorage);
3967
//支付订单基础信息
40-
PayOrder payOrder = new PayOrder("订单title", "摘要", new BigDecimal(0.01) , UUID.randomUUID().toString().replace("-", ""));
68+
PayOrder payOrder = new PayOrder("订单title", "摘要", BigDecimal.valueOf(0.01) , UUID.randomUUID().toString().replace("-", ""));
4169
/*-----------扫码付-------------------*/
4270
payOrder.setTransactionType(AliTransactionType.SWEEPPAY);
4371
//获取扫码付的二维码

pay-java-demo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public class ApyAccountService {
334334
//获取对应的支付账户操作工具(可根据账户id)
335335
PayResponse payResponse = service.getPayResponse(payId);
336336

337-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
337+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
338338

339339
//此处只有刷卡支付(银行卡支付)时需要
340340
if (StringUtils.isNotEmpty(bankType)){
@@ -355,7 +355,7 @@ public class ApyAccountService {
355355
//获取对应的支付账户操作工具(可根据账户id)
356356
PayResponse payResponse = service.getPayResponse(payId);
357357
//获取订单信息
358-
Map<String, Object> orderInfo = payResponse.getService().orderInfo(new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType)));
358+
Map<String, Object> orderInfo = payResponse.getService().orderInfo(new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType)));
359359

360360
ByteArrayOutputStream baos = new ByteArrayOutputStream();
361361
ImageIO.write(payResponse.getService().genQrPay(orderInfo), "JPEG", baos);
@@ -376,7 +376,7 @@ public class ApyAccountService {
376376
PayResponse payResponse = service.getPayResponse(payId);
377377
Map<String, Object> data = new HashMap<>();
378378
data.put("code", 0);
379-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
379+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
380380
data.put("orderInfo", payResponse.getService().orderInfo(order));
381381
return data;
382382
}

pay-java-demo/src/main/java/com/egzosn/pay/demo/controller/FuiouPayController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void init() {
6565
@RequestMapping(value = "toPay.html", produces = "text/html;charset=UTF-8")
6666
public String toPay( BigDecimal price) {
6767
//支付订单基础信息
68-
PayOrder order = new PayOrder("订单title", "摘要", new BigDecimal(0.01) , UUID.randomUUID().toString().replace("-", "").substring(2));
68+
PayOrder order = new PayOrder("订单title", "摘要", BigDecimal.valueOf(0.01) , UUID.randomUUID().toString().replace("-", "").substring(2));
6969
order.setTransactionType(FuiouTransactionType.B2C);
7070
//获取支付所需的信息
7171
// Map<String, Object> directOrderInfo = service.orderInfo(order);

pay-java-demo/src/main/java/com/egzosn/pay/demo/controller/PayController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public String toPay(HttpServletRequest request, Integer payId, String transactio
8888
//获取对应的支付账户操作工具(可根据账户id)
8989
PayResponse payResponse = service.getPayResponse(payId);
9090

91-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
91+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
9292
// ------ 微信H5使用----
9393
order.setSpbillCreateIp(request.getHeader("X-Real-IP"));
9494
StringBuffer requestURL = request.getRequestURL();
@@ -123,7 +123,7 @@ public String toWxPay(HttpServletRequest request) {
123123
//获取对应的支付账户操作工具(可根据账户id)
124124
PayResponse payResponse = service.getPayResponse(2);
125125

126-
PayOrder order = new PayOrder("订单title", "摘要", new BigDecimal(0.01), UUID.randomUUID().toString().replace("-", ""), WxTransactionType.MWEB);
126+
PayOrder order = new PayOrder("订单title", "摘要", BigDecimal.valueOf(0.01), UUID.randomUUID().toString().replace("-", ""), WxTransactionType.MWEB);
127127
order.setSpbillCreateIp(request.getHeader("X-Real-IP"));
128128
StringBuffer requestURL = request.getRequestURL();
129129
//设置网页地址
@@ -150,7 +150,7 @@ public Map toPay(Integer payId, String openid, BigDecimal price) {
150150
//获取对应的支付账户操作工具(可根据账户id)
151151
PayResponse payResponse = service.getPayResponse(payId);
152152

153-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType("JSAPI"));
153+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType("JSAPI"));
154154
order.setOpenid(openid);
155155

156156
Map orderInfo = payResponse.getService().orderInfo(order);
@@ -173,7 +173,7 @@ public Map<String, Object> getOrderInfo(Integer payId, String transactionType, B
173173
PayResponse payResponse = service.getPayResponse(payId);
174174
Map<String, Object> data = new HashMap<>();
175175
data.put("code", 0);
176-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
176+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
177177
data.put("orderInfo", payResponse.getService().app(order));
178178
return data;
179179
}
@@ -192,7 +192,7 @@ public Map<String, Object> microPay(Integer payId, String transactionType, BigDe
192192
//获取对应的支付账户操作工具(可根据账户id)
193193
PayResponse payResponse = service.getPayResponse(payId);
194194

195-
PayOrder order = new PayOrder("egan order", "egan order", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
195+
PayOrder order = new PayOrder("egan order", "egan order", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType));
196196
//设置授权码,条码等
197197
order.setAuthCode(authCode);
198198
//支付结果
@@ -225,7 +225,7 @@ public byte[] toWxQrPay(Integer payId, String transactionType, BigDecimal price)
225225
PayResponse payResponse = service.getPayResponse(payId);
226226
ByteArrayOutputStream baos = new ByteArrayOutputStream();
227227

228-
ImageIO.write(payResponse.getService().genQrPay(new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, System.currentTimeMillis() + "", PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType))), "JPEG", baos);
228+
ImageIO.write(payResponse.getService().genQrPay(new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, System.currentTimeMillis() + "", PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType))), "JPEG", baos);
229229
return baos.toByteArray();
230230
}
231231
/**
@@ -240,7 +240,7 @@ public String getQrPay(Integer payId, String transactionType, BigDecimal price)
240240
//获取对应的支付账户操作工具(可根据账户id)
241241
//获取对应的支付账户操作工具(可根据账户id)
242242
PayResponse payResponse = service.getPayResponse(payId);
243-
return payResponse.getService().getQrPay( new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, System.currentTimeMillis() + "", PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType)));
243+
return payResponse.getService().getQrPay( new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, System.currentTimeMillis() + "", PayType.valueOf(payResponse.getStorage().getPayType()).getTransactionType(transactionType)));
244244
}
245245
/**
246246
* 获取一码付二维码图像
@@ -288,7 +288,7 @@ public String toWxAliPay(Integer wxPayId, Integer aliPayId, BigDecimal price, Ht
288288
StringBuilder html = new StringBuilder();
289289

290290
//订单
291-
PayOrder payOrder = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, System.currentTimeMillis() + "");
291+
PayOrder payOrder = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, System.currentTimeMillis() + "");
292292
String ua = request.getHeader("user-agent");
293293
if (ua.contains("MicroMessenger")) {
294294
payOrder.setTransactionType(WxTransactionType.NATIVE);

pay-java-demo/src/main/java/com/egzosn/pay/demo/controller/PayPalPayController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void init() {
6868
@RequestMapping(value = "toPay.html", produces = "text/html;charset=UTF-8")
6969
public String toPay(BigDecimal price) {
7070
//及时收款
71-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayPalTransactionType.sale);
71+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), PayPalTransactionType.sale);
7272

7373
// Map orderInfo = service.orderInfo(order);
7474
// return service.buildRequest(orderInfo, MethodType.POST);
@@ -93,7 +93,7 @@ public RefundResult refund() {
9393
order.setCurType(DefaultCurType.USD);
9494
order.setDescription(" description ");
9595
order.setTradeNo("paypal 平台的单号");
96-
order.setRefundAmount(new BigDecimal(0.01));
96+
order.setRefundAmount(BigDecimal.valueOf(0.01));
9797
return service.refund(order);
9898
}
9999

pay-java-demo/src/main/java/com/egzosn/pay/demo/controller/UnionPayController.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ public void init() {
9797
@RequestMapping(value = "toPay.html", produces = "text/html;charset=UTF-8")
9898
public String toPay( BigDecimal price) {
9999
//网关支付(WEB)/手机网页支付
100-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""),
100+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""),
101101
WEB);
102102
//企业网银支付(B2B支付)
103-
// PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", ""), UnionTransactionType.B2B);
103+
// PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", ""), UnionTransactionType.B2B);
104104

105105
// Map orderInfo = service.orderInfo(order);
106106
// return service.buildRequest(orderInfo, MethodType.POST);
@@ -117,7 +117,7 @@ public String toPay( BigDecimal price) {
117117
@RequestMapping(value = "toPay.json")
118118
public Map<String, Object> sendHttpRequest( BigDecimal price) {
119119
//手机控件支付产品
120-
PayOrder order = new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, UUID.randomUUID().toString().replace("-", "")
120+
PayOrder order = new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, UUID.randomUUID().toString().replace("-", "")
121121
,UnionTransactionType.WAP);
122122
return service.app(order);
123123
}
@@ -133,7 +133,7 @@ public Map<String, Object> sendHttpRequest( BigDecimal price) {
133133
public Map<String, Object> app() {
134134
Map<String, Object> data = new HashMap<>();
135135
data.put("code", 0);
136-
PayOrder order = new PayOrder("订单title", "摘要", new BigDecimal(0.01), SignUtils.randomStr());
136+
PayOrder order = new PayOrder("订单title", "摘要", BigDecimal.valueOf(0.01), SignUtils.randomStr());
137137
//App支付
138138
order.setTransactionType(UnionTransactionType.APP);
139139

@@ -155,7 +155,7 @@ public Map<String, Object> app() {
155155
public byte[] toWxQrPay( BigDecimal price) throws IOException {
156156
//获取对应的支付账户操作工具(可根据账户id)
157157
ByteArrayOutputStream baos = new ByteArrayOutputStream();
158-
ImageIO.write(service.genQrPay( new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, System.currentTimeMillis()+"", UnionTransactionType.APPLY_QR_CODE)), "JPEG", baos);
158+
ImageIO.write(service.genQrPay( new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, System.currentTimeMillis()+"", UnionTransactionType.APPLY_QR_CODE)), "JPEG", baos);
159159
return baos.toByteArray();
160160
}
161161
/**
@@ -168,7 +168,7 @@ public byte[] toWxQrPay( BigDecimal price) throws IOException {
168168
@RequestMapping(value = "getQrPay.json")
169169
public String getQrPay(BigDecimal price) throws IOException {
170170
//获取对应的支付账户操作工具(可根据账户id)
171-
return service.getQrPay( new PayOrder("订单title", "摘要", null == price ? new BigDecimal(0.01) : price, System.currentTimeMillis()+"", UnionTransactionType.APPLY_QR_CODE));
171+
return service.getQrPay( new PayOrder("订单title", "摘要", null == price ? BigDecimal.valueOf(0.01) : price, System.currentTimeMillis()+"", UnionTransactionType.APPLY_QR_CODE));
172172
}
173173

174174
/**
@@ -181,7 +181,7 @@ public String getQrPay(BigDecimal price) throws IOException {
181181
public Map<String, Object> microPay(BigDecimal price, String authCode) {
182182
//获取对应的支付账户操作工具(可根据账户id)
183183
//条码付
184-
PayOrder order = new PayOrder("egan order", "egan order", null == price ? new BigDecimal(0.01) : price, SignUtils.randomStr(), UnionTransactionType.CONSUME);
184+
PayOrder order = new PayOrder("egan order", "egan order", null == price ? BigDecimal.valueOf(0.01) : price, SignUtils.randomStr(), UnionTransactionType.CONSUME);
185185
//设置授权码,条码等
186186
order.setAuthCode(authCode);
187187
//支付结果

0 commit comments

Comments
 (0)