From 601fde40c656a41ecd11a0872b83464422c63af3 Mon Sep 17 00:00:00 2001 From: zzs Date: Mon, 20 Feb 2017 18:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E5=B9=B6=E5=A3=B0=E6=98=8E?= =?UTF-8?q?=E6=9C=89=E5=85=B3=E7=9A=84=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/egan/pay/ali/api/AliPayService.java | 60 +--- .../egan/pay/ali/bean/AliPayCallMessage.java | 210 ------------- .../ali/util/SimpleGetRequestExecutor.java | 1 + .../egan/pay/common/api/BasePayService.java | 28 +- .../egan/pay/common/api/PayConfigStorage.java | 1 + .../in/egan/pay/common/api/PayConsts.java | 1 + .../common/api/PayErrorExceptionHandler.java | 1 + .../pay/common/api/PayMessageHandler.java | 1 + .../pay/common/api/PayMessageInterceptor.java | 2 +- .../egan/pay/common/api/PayMessageRouter.java | 1 + .../pay/common/api/PayMessageRouterRule.java | 1 + .../in/egan/pay/common/api/PayService.java | 1 + .../egan/pay/common/api/RequestExecutor.java | 1 + .../in/egan/pay/common/bean/BasePayType.java | 2 +- .../egan/pay/common/bean/PayCallMessage.java | 48 --- .../in/egan/pay/common/bean/PayMessage.java | 1 + .../egan/pay/common/bean/PayOutMessage.java | 1 + .../common/bean/outbuilder/BaseBuilder.java | 2 +- .../common/bean/outbuilder/JsonBuilder.java | 16 - .../common/bean/outbuilder/TextBuilder.java | 1 + .../common/bean/outbuilder/XmlBuilder.java | 1 + .../egan/pay/common/bean/result/PayError.java | 1 + .../common/exception/PayErrorException.java | 1 + .../pay/common/util/LogExceptionHandler.java | 1 + .../egan/pay/common/util/encrypt/Base64.java | 279 ------------------ .../in/egan/pay/common/util/encrypt/RSA.java | 143 --------- .../util/http/SimpleGetRequestExecutor.java | 1 + .../util/http/SimplePostRequestExecutor.java | 2 + .../common/util/http/Utf8ResponseHandler.java | 2 + .../egan/pay/common/util/sign/SignUtils.java | 40 +-- pay-java-fuiou/pom.xml | 1 - .../wx/youdian/api/WxYouDianPayService.java | 2 +- 32 files changed, 64 insertions(+), 790 deletions(-) delete mode 100644 pay-java-ali/src/main/java/in/egan/pay/ali/bean/AliPayCallMessage.java delete mode 100644 pay-java-common/src/main/java/in/egan/pay/common/bean/PayCallMessage.java delete mode 100644 pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/Base64.java delete mode 100644 pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/RSA.java diff --git a/pay-java-ali/src/main/java/in/egan/pay/ali/api/AliPayService.java b/pay-java-ali/src/main/java/in/egan/pay/ali/api/AliPayService.java index 2ecb716..44d758e 100644 --- a/pay-java-ali/src/main/java/in/egan/pay/ali/api/AliPayService.java +++ b/pay-java-ali/src/main/java/in/egan/pay/ali/api/AliPayService.java @@ -2,6 +2,7 @@ package in.egan.pay.ali.api; import in.egan.pay.ali.bean.AliTransactionType; import in.egan.pay.ali.util.SimpleGetRequestExecutor; +import in.egan.pay.common.api.BasePayService; import in.egan.pay.common.api.PayConfigStorage; import in.egan.pay.common.api.PayService; import in.egan.pay.common.api.RequestExecutor; @@ -39,18 +40,9 @@ import java.util.TreeMap; * @email egzosn@gmail.com * @date 2016-5-18 14:09:01 */ -public class AliPayService implements PayService { +public class AliPayService extends BasePayService { protected final Log log = LogFactory.getLog(AliPayService.class); - protected PayConfigStorage payConfigStorage; - - protected CloseableHttpClient httpClient; - - protected HttpHost httpProxy; - - private int retrySleepMillis = 1000; - - private int maxRetryTimes = 5; private String httpsReqUrl = "https://mapi.alipay.com/gateway.do"; @@ -104,6 +96,7 @@ public class AliPayService implements PayService { * @param data * @return * @throws PayErrorException + * @source chanjarster/weixin-java-tools */ @Override public T execute(RequestExecutor executor, String uri, E data) throws PayErrorException { @@ -365,7 +358,16 @@ public class AliPayService implements PayService { throw new UnsupportedOperationException(); } - + /** + * + * @param executor + * @param uri + * @param data + * @param + * @param + * @return + * @throws PayErrorException + */ protected T executeInternal(RequestExecutor executor, String uri, E data) throws PayErrorException { try { @@ -375,43 +377,7 @@ public class AliPayService implements PayService { } } - public HttpHost getHttpProxy() { - return httpProxy; - } - public CloseableHttpClient getHttpClient() { - return httpClient; - } - - public void setPayConfigStorage(PayConfigStorage payConfigStorage) { - this.payConfigStorage = payConfigStorage; - - String http_proxy_host = payConfigStorage.getHttpProxyHost(); - int http_proxy_port = payConfigStorage.getHttpProxyPort(); - String http_proxy_username = payConfigStorage.getHttpProxyUsername(); - String http_proxy_password = payConfigStorage.getHttpProxyPassword(); - - if (StringUtils.isNotBlank(http_proxy_host)) { - // 使用代理服务器 - if (StringUtils.isNotBlank(http_proxy_username)) { - // 需要用户认证的代理服务器 - CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials( - new AuthScope(http_proxy_host, http_proxy_port), - new UsernamePasswordCredentials(http_proxy_username, http_proxy_password)); - httpClient = HttpClients - .custom() - .setDefaultCredentialsProvider(credsProvider) - .build(); - } else { - // 无需用户认证的代理服务器 - httpClient = HttpClients.createDefault(); - } - httpProxy = new HttpHost(http_proxy_host, http_proxy_port); - } else { - httpClient = HttpClients.createDefault(); - } - } @Override public PayConfigStorage getPayConfigStorage() { diff --git a/pay-java-ali/src/main/java/in/egan/pay/ali/bean/AliPayCallMessage.java b/pay-java-ali/src/main/java/in/egan/pay/ali/bean/AliPayCallMessage.java deleted file mode 100644 index b5bd38d..0000000 --- a/pay-java-ali/src/main/java/in/egan/pay/ali/bean/AliPayCallMessage.java +++ /dev/null @@ -1,210 +0,0 @@ -package in.egan.pay.ali.bean; - -import in.egan.pay.common.bean.PayCallMessage; -import java.math.BigDecimal; -import java.util.Date; - -/** - * 阿里支付回调消息 - * @author egan - * @email egzosn@gmail.com - * @date 2016-5-18 14:09:01 - */ -public class AliPayCallMessage extends PayCallMessage { - - private Date notify_time; - private String notify_type; - private String notify_id ; - private String subject; - private String payment_type; - private String trade_no; - private String trade_status; - private String seller_id; - private String seller_email; - private String buyer_id; - private String buyer_email; - private Integer quantity; - private BigDecimal price; - private String body; - private Date gmt_create; - private Date gmt_payment; - private String is_total_fee_adjust; - private String use_coupon; - private String discount; - private String refund_status; - private String gmt_refund; - - public Date getNotify_time() { - return notify_time; - } - - public void setNotify_time(Date notify_time) { - this.notify_time = notify_time; - } - - public String getNotify_type() { - return notify_type; - } - - public void setNotify_type(String notify_type) { - this.notify_type = notify_type; - } - - public String getNotify_id() { - return notify_id; - } - - public void setNotify_id(String notify_id) { - this.notify_id = notify_id; - } - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - public String getPayment_type() { - return payment_type; - } - - public void setPayment_type(String payment_type) { - this.payment_type = payment_type; - } - - public String getTrade_no() { - return trade_no; - } - - public void setTrade_no(String trade_no) { - this.trade_no = trade_no; - } - - public String getTrade_status() { - return trade_status; - } - - public void setTrade_status(String trade_status) { - this.trade_status = trade_status; - } - - public String getSeller_id() { - return seller_id; - } - - public void setSeller_id(String seller_id) { - this.seller_id = seller_id; - } - - public String getSeller_email() { - return seller_email; - } - - public void setSeller_email(String seller_email) { - this.seller_email = seller_email; - } - - public String getBuyer_id() { - return buyer_id; - } - - public void setBuyer_id(String buyer_id) { - this.buyer_id = buyer_id; - } - - public String getBuyer_email() { - return buyer_email; - } - - public void setBuyer_email(String buyer_email) { - this.buyer_email = buyer_email; - } - - public Integer getQuantity() { - return quantity; - } - - public void setQuantity(Integer quantity) { - this.quantity = quantity; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public Date getGmt_create() { - return gmt_create; - } - - public void setGmt_create(Date gmt_create) { - this.gmt_create = gmt_create; - } - - public Date getGmt_payment() { - return gmt_payment; - } - - public void setGmt_payment(Date gmt_payment) { - this.gmt_payment = gmt_payment; - } - - public String getIs_total_fee_adjust() { - return is_total_fee_adjust; - } - - public void setIs_total_fee_adjust(String is_total_fee_adjust) { - this.is_total_fee_adjust = is_total_fee_adjust; - } - - public String getUse_coupon() { - return use_coupon; - } - - public void setUse_coupon(String use_coupon) { - this.use_coupon = use_coupon; - } - - public String getDiscount() { - return discount; - } - - public void setDiscount(String discount) { - this.discount = discount; - } - - public String getRefund_status() { - return refund_status; - } - - public void setRefund_status(String refund_status) { - this.refund_status = refund_status; - } - - public String getGmt_refund() { - return gmt_refund; - } - - public void setGmt_refund(String gmt_refund) { - this.gmt_refund = gmt_refund; - } - - - public AliPayCallMessage() { - } - - -} diff --git a/pay-java-ali/src/main/java/in/egan/pay/ali/util/SimpleGetRequestExecutor.java b/pay-java-ali/src/main/java/in/egan/pay/ali/util/SimpleGetRequestExecutor.java index fdca0bd..990f055 100644 --- a/pay-java-ali/src/main/java/in/egan/pay/ali/util/SimpleGetRequestExecutor.java +++ b/pay-java-ali/src/main/java/in/egan/pay/ali/util/SimpleGetRequestExecutor.java @@ -21,6 +21,7 @@ import java.io.IOException; /** * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String * @author Daniel Qian + * @source chanjarster/weixin-java-tools * */ public class SimpleGetRequestExecutor implements RequestExecutor { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/BasePayService.java b/pay-java-common/src/main/java/in/egan/pay/common/api/BasePayService.java index 789055d..56f53bf 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/BasePayService.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/BasePayService.java @@ -1,20 +1,3 @@ -/* - * Copyright 2002-2017 the original huodull or egan. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - package in.egan.pay.common.api; import in.egan.pay.common.exception.PayErrorException; @@ -33,6 +16,7 @@ import java.io.IOException; * @author: egan * @email egzosn@gmail.com * @date 2017/1/12 20:09 + * @source chanjarster/weixin-java-tools */ public abstract class BasePayService implements PayService { @@ -46,6 +30,16 @@ public abstract class BasePayService implements PayService { protected int maxRetryTimes = 5; + /** + * + * @param executor + * @param uri + * @param data + * @param + * @param + * @return + * @throws PayErrorException + */ protected T executeInternal(RequestExecutor executor, String uri, E data) throws PayErrorException { try { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayConfigStorage.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayConfigStorage.java index e063932..71aed52 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayConfigStorage.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayConfigStorage.java @@ -9,6 +9,7 @@ import java.util.concurrent.locks.Lock; * @author egan * @email egzosn@gmail.com * @date 2016-5-18 14:09:01 + * @source chanjarster/weixin-java-tools */ public interface PayConfigStorage { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayConsts.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayConsts.java index 5ab194a..ff0d55c 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayConsts.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayConsts.java @@ -2,6 +2,7 @@ package in.egan.pay.common.api; /** * 支付宝支付通知 + * @source chanjarster/weixin-java-tools * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:45:31 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayErrorExceptionHandler.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayErrorExceptionHandler.java index cfdea4a..7c517d9 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayErrorExceptionHandler.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayErrorExceptionHandler.java @@ -7,6 +7,7 @@ import in.egan.pay.common.exception.PayErrorException; /** * PayErrorExceptionHandler处理器 + * * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:33:01 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageHandler.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageHandler.java index f2cd88a..cba2092 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageHandler.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageHandler.java @@ -8,6 +8,7 @@ import java.util.Map; /** * 处理支付回调消息的处理器接口 + * @source Daniel Qian * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:40:30 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageInterceptor.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageInterceptor.java index a6319f6..625f440 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageInterceptor.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageInterceptor.java @@ -8,7 +8,7 @@ import java.util.Map; /** * 支付消息拦截器,可以用来做验证 - * + * @author Daniel Qian */ public interface PayMessageInterceptor { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouter.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouter.java index 86c0a1d..f15d3cb 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouter.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouter.java @@ -38,6 +38,7 @@ import java.util.concurrent.Future; * router.route(message); * * + * @source chanjarster/weixin-java-tools * @source Daniel Qian * @author egan * diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouterRule.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouterRule.java index a313a1d..cb31b04 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouterRule.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayMessageRouterRule.java @@ -17,6 +17,7 @@ import java.util.regex.Pattern; * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:28:01 + * @source chanjarster/weixin-java-tools */ public class PayMessageRouterRule { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/PayService.java b/pay-java-common/src/main/java/in/egan/pay/common/api/PayService.java index 82b16f9..d3f142b 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/PayService.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/PayService.java @@ -69,6 +69,7 @@ import java.util.Map; * @param 请求数据类型 * @return * @throws PayErrorException + * @source */ T execute(RequestExecutor executor, String uri, E data) throws PayErrorException; diff --git a/pay-java-common/src/main/java/in/egan/pay/common/api/RequestExecutor.java b/pay-java-common/src/main/java/in/egan/pay/common/api/RequestExecutor.java index 4b693fc..b76422b 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/api/RequestExecutor.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/api/RequestExecutor.java @@ -13,6 +13,7 @@ import java.io.IOException; * * @param 返回值类型 * @param 请求参数类型 + * @source chanjarster/weixin-java-tools */ public interface RequestExecutor { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/BasePayType.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/BasePayType.java index f3216ae..ce4eef8 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/BasePayType.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/BasePayType.java @@ -14,6 +14,6 @@ public interface BasePayType { * @param transactionType 类型值 * @return */ - public abstract TransactionType getTransactionType(String transactionType); + TransactionType getTransactionType(String transactionType); } diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayCallMessage.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/PayCallMessage.java deleted file mode 100644 index 33558d9..0000000 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayCallMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package in.egan.pay.common.bean; - -import java.math.BigDecimal; - -/** - * 支付回调消息 - * @author egan - * @email egzosn@gmail.com - * @date 2016-5-18 14:09:01 - */ -public class PayCallMessage { - private Boolean sign; - private String sign_type; - private String out_trade_no; - private BigDecimal total_fee; - - public Boolean getSign() { - return sign; - } - - public void setSign(Boolean sign) { - this.sign = sign; - } - - public String getSign_type() { - return sign_type; - } - - public void setSign_type(String sign_type) { - this.sign_type = sign_type; - } - - public String getOut_trade_no() { - return out_trade_no; - } - - public void setOut_trade_no(String out_trade_no) { - this.out_trade_no = out_trade_no; - } - - public BigDecimal getTotal_fee() { - return total_fee; - } - - public void setTotal_fee(BigDecimal total_fee) { - this.total_fee = total_fee; - } -} diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayMessage.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/PayMessage.java index 9117ba0..e818299 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayMessage.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/PayMessage.java @@ -14,6 +14,7 @@ import java.util.Map; * @author egan * @email egzosn@gmail.com * @date 2016-6-1 14:2:3 + * @source chanjarster/weixin-java-tools */ public class PayMessage implements Serializable { private Map payMessage = null; diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayOutMessage.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/PayOutMessage.java index 33ca87f..71b567e 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/PayOutMessage.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/PayOutMessage.java @@ -12,6 +12,7 @@ import java.io.Serializable; * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:40:30 + * @source chanjarster/weixin-java-tools */ public abstract class PayOutMessage implements Serializable { protected String content; diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/BaseBuilder.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/BaseBuilder.java index de94b70..f676df0 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/BaseBuilder.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/BaseBuilder.java @@ -3,7 +3,7 @@ package in.egan.pay.common.bean.outbuilder; import in.egan.pay.common.bean.PayOutMessage; /** - * + * @source chanjarster/weixin-java-tools * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:40:30 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/JsonBuilder.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/JsonBuilder.java index a51ba05..d11d1d9 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/JsonBuilder.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/JsonBuilder.java @@ -1,19 +1,3 @@ -/* - * Copyright 2002-2017 the original huodull or egan. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package in.egan.pay.common.bean.outbuilder; diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/TextBuilder.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/TextBuilder.java index bdb35e3..ad78579 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/TextBuilder.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/TextBuilder.java @@ -3,6 +3,7 @@ package in.egan.pay.common.bean.outbuilder; import in.egan.pay.common.bean.PayOutMessage; /** + * @source chanjarster/weixin-java-tools * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:40:30 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/XmlBuilder.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/XmlBuilder.java index 6652ccc..0dc6b17 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/XmlBuilder.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/outbuilder/XmlBuilder.java @@ -2,6 +2,7 @@ package in.egan.pay.common.bean.outbuilder; import in.egan.pay.common.bean.PayOutMessage; /** + * @source chanjarster/weixin-java-tools * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:40:30 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/bean/result/PayError.java b/pay-java-common/src/main/java/in/egan/pay/common/bean/result/PayError.java index 6a881a1..23c2a40 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/bean/result/PayError.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/bean/result/PayError.java @@ -12,6 +12,7 @@ import java.util.Map; * @author Daniel Qian * @dete 2017/1/12 9:57 * @author: egan + * @source chanjarster/weixin-java-tools */ public class PayError implements Serializable { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/exception/PayErrorException.java b/pay-java-common/src/main/java/in/egan/pay/common/exception/PayErrorException.java index f8e388c..96a132c 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/exception/PayErrorException.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/exception/PayErrorException.java @@ -6,6 +6,7 @@ import in.egan.pay.common.bean.result.PayError; * @author egan * @email egzosn@gmail.com * @date 2016-5-18 14:09:01 + * @source chanjarster/weixin-java-tools */ public class PayErrorException extends Exception { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/LogExceptionHandler.java b/pay-java-common/src/main/java/in/egan/pay/common/util/LogExceptionHandler.java index 7b94499..0978611 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/LogExceptionHandler.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/util/LogExceptionHandler.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.LogFactory; * @author egan * @email egzosn@gmail.com * @date 2016-6-1 11:28:01 + * @source chanjarster/weixin-java-tools */ public class LogExceptionHandler implements PayErrorExceptionHandler { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/Base64.java b/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/Base64.java deleted file mode 100644 index 9c1b3fb..0000000 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/Base64.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2010 The MobileSecurePay Project - * All right reserved. - * author: shiqun.shi@alipay.com - */ - -package in.egan.pay.common.util.encrypt; - -public final class Base64 { - - static private final int BASELENGTH = 128; - static private final int LOOKUPLENGTH = 64; - static private final int TWENTYFOURBITGROUP = 24; - static private final int EIGHTBIT = 8; - static private final int SIXTEENBIT = 16; - static private final int FOURBYTE = 4; - static private final int SIGN = -128; - static private final char PAD = '='; - static private final boolean fDebug = false; - static final private byte[] base64Alphabet = new byte[BASELENGTH]; - static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; - - static { - for (int i = 0; i < BASELENGTH; ++i) { - base64Alphabet[i] = -1; - } - for (int i = 'Z'; i >= 'A'; i--) { - base64Alphabet[i] = (byte) (i - 'A'); - } - for (int i = 'z'; i >= 'a'; i--) { - base64Alphabet[i] = (byte) (i - 'a' + 26); - } - - for (int i = '9'; i >= '0'; i--) { - base64Alphabet[i] = (byte) (i - '0' + 52); - } - - base64Alphabet['+'] = 62; - base64Alphabet['/'] = 63; - - for (int i = 0; i <= 25; i++) { - lookUpBase64Alphabet[i] = (char) ('A' + i); - } - - for (int i = 26, j = 0; i <= 51; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('a' + j); - } - - for (int i = 52, j = 0; i <= 61; i++, j++) { - lookUpBase64Alphabet[i] = (char) ('0' + j); - } - lookUpBase64Alphabet[62] = (char) '+'; - lookUpBase64Alphabet[63] = (char) '/'; - - } - - private static boolean isWhiteSpace(char octect) { - return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); - } - - private static boolean isPad(char octect) { - return (octect == PAD); - } - - private static boolean isData(char octect) { - return (octect < BASELENGTH && base64Alphabet[octect] != -1); - } - - /** - * Encodes hex octects into Base64 - * - * @param binaryData Array containing binaryData - * @return Encoded Base64 array - */ - public static String encode(byte[] binaryData) { - - if (binaryData == null) { - return null; - } - - int lengthDataBits = binaryData.length * EIGHTBIT; - if (lengthDataBits == 0) { - return ""; - } - - int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; - int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; - int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets; - char encodedData[] = null; - - encodedData = new char[numberQuartet * 4]; - - byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; - - int encodedIndex = 0; - int dataIndex = 0; - if (fDebug) { - System.out.println("number of triplets = " + numberTriplets); - } - - for (int i = 0; i < numberTriplets; i++) { - b1 = binaryData[dataIndex++]; - b2 = binaryData[dataIndex++]; - b3 = binaryData[dataIndex++]; - - if (fDebug) { - System.out.println("b1= " + b1 + ", b2= " + b2 + ", b3= " + b3); - } - - l = (byte) (b2 & 0x0f); - k = (byte) (b1 & 0x03); - - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); - byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc); - - if (fDebug) { - System.out.println("val2 = " + val2); - System.out.println("k4 = " + (k << 4)); - System.out.println("vak = " + (val2 | (k << 4))); - } - - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; - } - - // form integral number of 6-bit groups - if (fewerThan24bits == EIGHTBIT) { - b1 = binaryData[dataIndex]; - k = (byte) (b1 & 0x03); - if (fDebug) { - System.out.println("b1=" + b1); - System.out.println("b1<<2 = " + (b1 >> 2)); - } - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; - encodedData[encodedIndex++] = PAD; - encodedData[encodedIndex++] = PAD; - } else if (fewerThan24bits == SIXTEENBIT) { - b1 = binaryData[dataIndex]; - b2 = binaryData[dataIndex + 1]; - l = (byte) (b2 & 0x0f); - k = (byte) (b1 & 0x03); - - byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); - byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0); - - encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; - encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; - encodedData[encodedIndex++] = PAD; - } - - return new String(encodedData); - } - - /** - * Decodes Base64 data into octects - * - * @param encoded string containing Base64 data - * @return Array containind decoded data. - */ - public static byte[] decode(String encoded) { - - if (encoded == null) { - return null; - } - - char[] base64Data = encoded.toCharArray(); - // remove white spaces - int len = removeWhiteSpace(base64Data); - - if (len % FOURBYTE != 0) { - return null;//should be divisible by four - } - - int numberQuadruple = (len / FOURBYTE); - - if (numberQuadruple == 0) { - return new byte[0]; - } - - byte decodedData[] = null; - byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; - char d1 = 0, d2 = 0, d3 = 0, d4 = 0; - - int i = 0; - int encodedIndex = 0; - int dataIndex = 0; - decodedData = new byte[(numberQuadruple) * 3]; - - for (; i < numberQuadruple - 1; i++) { - - if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) - || !isData((d3 = base64Data[dataIndex++])) - || !isData((d4 = base64Data[dataIndex++]))) { - return null; - }//if found "no data" just return null - - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; - - decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); - } - - if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) { - return null;//if found "no data" just return null - } - - b1 = base64Alphabet[d1]; - b2 = base64Alphabet[d2]; - - d3 = base64Data[dataIndex++]; - d4 = base64Data[dataIndex++]; - if (!isData((d3)) || !isData((d4))) {//Check if they are PAD characters - if (isPad(d3) && isPad(d4)) { - if ((b2 & 0xf) != 0)//last 4 bits should be zero - { - return null; - } - byte[] tmp = new byte[i * 3 + 1]; - System.arraycopy(decodedData, 0, tmp, 0, i * 3); - tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); - return tmp; - } else if (!isPad(d3) && isPad(d4)) { - b3 = base64Alphabet[d3]; - if ((b3 & 0x3) != 0)//last 2 bits should be zero - { - return null; - } - byte[] tmp = new byte[i * 3 + 2]; - System.arraycopy(decodedData, 0, tmp, 0, i * 3); - tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - return tmp; - } else { - return null; - } - } else { //No PAD e.g 3cQl - b3 = base64Alphabet[d3]; - b4 = base64Alphabet[d4]; - decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); - decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); - decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); - - } - - return decodedData; - } - - /** - * remove WhiteSpace from MIME containing encoded Base64 data. - * - * @param data the byte array of base64 data (with WS) - * @return the new length - */ - private static int removeWhiteSpace(char[] data) { - if (data == null) { - return 0; - } - - // count characters that's not whitespace - int newSize = 0; - int len = data.length; - for (int i = 0; i < len; i++) { - if (!isWhiteSpace(data[i])) { - data[newSize++] = data[i]; - } - } - return newSize; - } -} diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/RSA.java b/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/RSA.java deleted file mode 100644 index 91d3ca9..0000000 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/encrypt/RSA.java +++ /dev/null @@ -1,143 +0,0 @@ - -package in.egan.pay.common.util.encrypt; - -import javax.crypto.Cipher; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; - -public class RSA{ - - public static final String SIGN_ALGORITHMS = "SHA1WithRSA"; - - /** - * RSA签名 - * @param content 待签名数据 - * @param privateKey 商户私钥 - * @param input_charset 编码格式 - * @return 签名值 - */ - public static String sign(String content, String privateKey, String signType ,String input_charset) - { - try - { - PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec( Base64.decode(privateKey) ); - KeyFactory keyf = KeyFactory.getInstance(signType); - PrivateKey priKey = keyf.generatePrivate(priPKCS8); - - java.security.Signature signature = java.security.Signature - .getInstance(SIGN_ALGORITHMS); - - signature.initSign(priKey); - signature.update( content.getBytes(input_charset) ); - - byte[] signed = signature.sign(); - - return Base64.encode(signed); - } - catch (Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * RSA验签名检查 - * @param content 待签名数据 - * @param sign 签名值 - * @param ali_public_key 支付宝公钥 - * @param input_charset 编码格式 - * @return 布尔值 - */ - public static boolean verify(String content, String sign, String ali_public_key, String input_charset) - { - try - { - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - byte[] encodedKey = Base64.decode(ali_public_key); - PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey)); - - - java.security.Signature signature = java.security.Signature - .getInstance(SIGN_ALGORITHMS); - - signature.initVerify(pubKey); - signature.update( content.getBytes(input_charset) ); - - boolean bverify = signature.verify( Base64.decode(sign) ); - return bverify; - - } - catch (Exception e) - { - e.printStackTrace(); - } - - return false; - } - - /** - * 解密 - * @param content 密文 - * @param private_key 商户私钥 - * @param input_charset 编码格式 - * @return 解密后的字符串 - */ - public static String decrypt(String content, String private_key, String input_charset) throws Exception { - PrivateKey prikey = getPrivateKey(private_key); - - Cipher cipher = Cipher.getInstance("RSA"); - cipher.init(Cipher.DECRYPT_MODE, prikey); - - InputStream ins = new ByteArrayInputStream(Base64.decode(content)); - ByteArrayOutputStream writer = new ByteArrayOutputStream(); - //rsa解密的字节大小最多是128,将需要解密的内容,按128位拆开解密 - byte[] buf = new byte[128]; - int bufl; - - while ((bufl = ins.read(buf)) != -1) { - byte[] block = null; - - if (buf.length == bufl) { - block = buf; - } else { - block = new byte[bufl]; - for (int i = 0; i < bufl; i++) { - block[i] = buf[i]; - } - } - - writer.write(cipher.doFinal(block)); - } - - return new String(writer.toByteArray(), input_charset); - } - - - /** - * 得到私钥 - * @param key 密钥字符串(经过base64编码) - * @throws Exception - */ - public static PrivateKey getPrivateKey(String key) throws Exception { - - byte[] keyBytes; - - keyBytes = Base64.decode(key); - - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); - - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - - PrivateKey privateKey = keyFactory.generatePrivate(keySpec); - - return privateKey; - } -} diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimpleGetRequestExecutor.java b/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimpleGetRequestExecutor.java index c33a12b..1483399 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimpleGetRequestExecutor.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimpleGetRequestExecutor.java @@ -4,6 +4,7 @@ package in.egan.pay.common.util.http; * @author egan * @email egzosn@gmail.com * @date 2016-5-24 + * @source chanjarster/weixin-java-tools */ import in.egan.pay.common.api.RequestExecutor; diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimplePostRequestExecutor.java b/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimplePostRequestExecutor.java index 23f2d9b..88b63f3 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimplePostRequestExecutor.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/util/http/SimplePostRequestExecutor.java @@ -19,6 +19,8 @@ import java.util.Map; * @author egan * @email egzosn@gmail.com * @date 2016-5-18 14:09:01 + * @author Daniel Qian + * @source chanjarster/weixin-java-tools */ public class SimplePostRequestExecutor implements RequestExecutor { diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/http/Utf8ResponseHandler.java b/pay-java-common/src/main/java/in/egan/pay/common/util/http/Utf8ResponseHandler.java index f6d10da..a5d74d0 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/http/Utf8ResponseHandler.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/util/http/Utf8ResponseHandler.java @@ -11,6 +11,8 @@ import org.apache.http.util.EntityUtils; import java.io.IOException; /** + * @source chanjarster/weixin-java-tools + * @author Daniel Qian * @author egan * @email egzosn@gmail.com * @date 2016-5-24 diff --git a/pay-java-common/src/main/java/in/egan/pay/common/util/sign/SignUtils.java b/pay-java-common/src/main/java/in/egan/pay/common/util/sign/SignUtils.java index 66daa5a..a7dd0c3 100644 --- a/pay-java-common/src/main/java/in/egan/pay/common/util/sign/SignUtils.java +++ b/pay-java-common/src/main/java/in/egan/pay/common/util/sign/SignUtils.java @@ -1,24 +1,8 @@ -/* - * Copyright 2002-2017 the original huodull or egan. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - package in.egan.pay.common.util.sign; import in.egan.pay.common.util.str.StringUtils; +import org.apache.http.message.BasicNameValuePair; import java.util.*; @@ -132,7 +116,7 @@ public enum SignUtils { if (null == valueStr || "".equals(valueStr.toString().trim()) || "sign".equals(k) || "key".equals(k) || "appId".equals(k) || "sign_type".equalsIgnoreCase(k)) { continue; } - sb.append(k ).append("=").append( valueStr).append(separator); + sb.append(k ).append("=").append( valueStr).append(separator); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); @@ -147,17 +131,23 @@ public enum SignUtils { * @param separator * @return */ - public static String parameters2MD5Str(Map parameters, String separator){ + public static String parameters2MD5Str(Object parameters, String separator){ StringBuffer sb = new StringBuffer(); - Set keys = (Set) parameters.keySet(); if (parameters instanceof LinkedHashMap) { - for(String key : keys){ - String val = parameters.get(key).toString(); - if(StringUtils.isNotBlank(val)){ - sb.append(val).append(separator); - } + Set keys = (Set) ((LinkedHashMap)parameters).keySet(); + for(String key : keys){ + String val = ((LinkedHashMap)parameters).get(key).toString(); + if(StringUtils.isNotBlank(val)){ + sb.append(val).append(separator); } + } + }else if(parameters instanceof List){ + for(BasicNameValuePair bnv :((List)parameters) ){ + if(StringUtils.isNotBlank(bnv.getValue())){ + sb.append(bnv.getValue()).append(separator); + } + } } return StringUtils.isBlank(sb.toString())?"":sb.deleteCharAt(sb.length() - 1).toString(); diff --git a/pay-java-fuiou/pom.xml b/pay-java-fuiou/pom.xml index 95b6eee..8597c5f 100644 --- a/pay-java-fuiou/pom.xml +++ b/pay-java-fuiou/pom.xml @@ -18,7 +18,6 @@ in.egan pay-java-common - 1.0.RELEASE diff --git a/pay-java-wx-youdian/src/main/java/in/egan/pay/wx/youdian/api/WxYouDianPayService.java b/pay-java-wx-youdian/src/main/java/in/egan/pay/wx/youdian/api/WxYouDianPayService.java index a4770f8..9aa12cc 100644 --- a/pay-java-wx-youdian/src/main/java/in/egan/pay/wx/youdian/api/WxYouDianPayService.java +++ b/pay-java-wx-youdian/src/main/java/in/egan/pay/wx/youdian/api/WxYouDianPayService.java @@ -133,7 +133,7 @@ public class WxYouDianPayService extends BasePayService { TreeMap data = new TreeMap<>(); data.put("username", payConfigStorage.getSeller()); data.put("password", payConfigStorage.getKeyPrivate()); - String apbNonce = "6863fc0308af4550993ad4a57693ed9d";//SignUtils.randomStr(); + String apbNonce = SignUtils.randomStr(); // 1、确定请求主体为用户登录,即需要传登录的用户名username和密码password并且要生成唯一的随机数命名为apb_nonce,长度为32位 // 2、将所有的参数集进行key排序 // 3、将排序后的数组从起始位置拼接成字符串如:password=XXXXXXXusername=XXXXX