mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-17 12:09:45 +08:00
http连接池案例设置
This commit is contained in:
@@ -5,39 +5,24 @@ package com.egzosn.pay.demo.controller;
|
||||
import com.egzosn.pay.ali.api.AliPayConfigStorage;
|
||||
import com.egzosn.pay.ali.api.AliPayService;
|
||||
import com.egzosn.pay.ali.bean.AliTransactionType;
|
||||
import com.egzosn.pay.common.api.Callback;
|
||||
import com.egzosn.pay.common.api.PayConfigStorage;
|
||||
import com.egzosn.pay.common.api.PayService;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.UriVariables;
|
||||
import com.egzosn.pay.common.util.MatrixToImageWriter;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.common.util.str.StringUtils;
|
||||
import com.egzosn.pay.demo.entity.ApyAccount;
|
||||
import com.egzosn.pay.demo.entity.PayType;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
import com.egzosn.pay.demo.service.ApyAccountService;
|
||||
import com.egzosn.pay.demo.service.PayResponse;
|
||||
import com.egzosn.pay.payoneer.api.PayoneerPayService;
|
||||
import com.egzosn.pay.wx.bean.WxTransactionType;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.egzosn.pay.demo.dao.ApyAccountRepository.apyAccounts;
|
||||
|
||||
/**
|
||||
* 发起支付入口
|
||||
@@ -67,7 +52,13 @@ public class AliPayController {
|
||||
//是否为测试账号,沙箱环境
|
||||
aliPayConfigStorage.setTest(true);
|
||||
|
||||
service = new AliPayService(aliPayConfigStorage);
|
||||
//请求连接池配置
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
service = new AliPayService(aliPayConfigStorage, httpConfigStorage);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.egzosn.pay.common.bean.CurType;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.paypal.api.PayPalConfigStorage;
|
||||
import com.egzosn.pay.paypal.api.PayPalPayService;
|
||||
import com.egzosn.pay.paypal.bean.PayPalTransactionType;
|
||||
@@ -47,6 +48,14 @@ public class PayPalPayController {
|
||||
//取消按钮转跳地址,这里用异步通知地址的兼容的做法
|
||||
storage.setNotifyUrl("http://127.0.0.1:8088/pay/cancel");
|
||||
service = new PayPalPayService(storage);
|
||||
|
||||
//请求连接池配置
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
service.setRequestTemplateConfigStorage(httpConfigStorage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,14 @@ public class PayoneerPayController {
|
||||
configStorage.setTest(true);
|
||||
service = new PayoneerPayService(configStorage);
|
||||
|
||||
//请求连接池配置
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
service.setRequestTemplateConfigStorage(httpConfigStorage);
|
||||
|
||||
//以下不建议进行使用,会引起两次请求的问题
|
||||
//Basic Auth
|
||||
/* HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.egzosn.pay.demo.controller;
|
||||
|
||||
import com.egzosn.pay.common.api.PayService;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
import com.egzosn.pay.union.api.UnionPayConfigStorage;
|
||||
@@ -58,6 +59,13 @@ public class UnionPayController {
|
||||
unionPayConfigStorage.setTest(true);
|
||||
service = new UnionPayService(unionPayConfigStorage);
|
||||
|
||||
//请求连接池配置
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
service.setRequestTemplateConfigStorage(httpConfigStorage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package com.egzosn.pay.demo.controller;
|
||||
import com.egzosn.pay.common.api.Callback;
|
||||
import com.egzosn.pay.common.api.PayService;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.common.http.UriVariables;
|
||||
import com.egzosn.pay.demo.entity.PayType;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
@@ -39,6 +40,10 @@ public class WxPayController {
|
||||
|
||||
private PayService service = null;
|
||||
|
||||
//ssl 退款证书相关 不使用可注释
|
||||
private static String KEYSTORE = "ssl 退款证书";
|
||||
private static String STORE_PASSWORD = "ssl 证书对应的密码, 默认为商户号";
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
WxPayConfigStorage wxPayConfigStorage = new WxPayConfigStorage();
|
||||
@@ -54,7 +59,22 @@ public class WxPayController {
|
||||
|
||||
service = new WxPayService(wxPayConfigStorage);
|
||||
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
|
||||
//ssl 退款证书相关 不使用可注释
|
||||
if(!"ssl 退款证书".equals(KEYSTORE)){
|
||||
httpConfigStorage.setKeystore(KEYSTORE);
|
||||
httpConfigStorage.setStorePassword(STORE_PASSWORD);
|
||||
httpConfigStorage.setPath(true);
|
||||
}
|
||||
|
||||
|
||||
//请求连接池配置
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
service.setRequestTemplateConfigStorage(httpConfigStorage);
|
||||
}
|
||||
|
||||
|
||||
@@ -218,6 +238,9 @@ public class WxPayController {
|
||||
*/
|
||||
@RequestMapping("refund")
|
||||
public Map<String, Object> refund(RefundOrder order) {
|
||||
if("ssl 退款证书".equals(KEYSTORE)){
|
||||
throw new RuntimeException("请设置好SSL退款证书");
|
||||
}
|
||||
return service.refund(order);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,11 @@ public enum PayType implements BasePayType {
|
||||
configStorage.setMsgType(apyAccount.getMsgType());
|
||||
configStorage.setInputCharset(apyAccount.getInputCharset());
|
||||
configStorage.setTest(apyAccount.isTest());
|
||||
//
|
||||
//请求连接池配置
|
||||
HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
|
||||
//最大连接数
|
||||
httpConfigStorage.setMaxTotal(20);
|
||||
//默认的每个路由的最大连接数
|
||||
httpConfigStorage.setDefaultMaxPerRoute(10);
|
||||
return new AliPayService(configStorage, httpConfigStorage);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ApyAccountService {
|
||||
*/
|
||||
public PayResponse getPayResponse(Integer id) {
|
||||
|
||||
PayResponse payResponse = null;
|
||||
PayResponse payResponse = payResponses.get(id);
|
||||
if (payResponse == null) {
|
||||
ApyAccount apyAccount = dao.findByPayId(id);
|
||||
if (apyAccount == null) {
|
||||
|
||||
Reference in New Issue
Block a user