merge
This commit is contained in:
@@ -116,12 +116,13 @@
|
||||
<artifactId>jdom</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<!-- aliPay -->
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<!-- alipay工具包会用到-->
|
||||
<!-- aliPay工具包会用到-->
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝扫码支付参数
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:34
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import com.alipay.api.domain.TradeFundBill;
|
||||
import lombok.Data;
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明: 条形码支付结果
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@@ -62,6 +62,6 @@ public class AlipayBarCodePayResult extends AlipayBaseResult {
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
//如果已支付过也认为是成功
|
||||
return super.getCode().equals("10000");
|
||||
return "10000".equals(super.getCode());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝接口基础类
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:35
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝返回状态码
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:37
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+7
-10
@@ -1,11 +1,16 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝查询状态
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:38
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class AlipayQueryResult extends AlipayBaseResult {
|
||||
/**
|
||||
* 交易支付状态
|
||||
@@ -15,13 +20,5 @@ public class AlipayQueryResult extends AlipayBaseResult {
|
||||
public AlipayQueryResult(boolean success) {
|
||||
this.setSuccess(success);
|
||||
}
|
||||
|
||||
public String getTradeStatus() {
|
||||
return tradeStatus;
|
||||
}
|
||||
|
||||
public void setTradeStatus(String tradeStatus) {
|
||||
this.tradeStatus = tradeStatus;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝退款参数
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:38
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
@@ -8,7 +8,7 @@ import java.util.Date;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝退款结果
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:39
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.xwbing.domain.entity.alipay;
|
||||
package com.xwbing.domain.entity.pay.alipay;
|
||||
|
||||
/**
|
||||
* 说明: 支付宝交易状态
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:39
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-3
@@ -1,11 +1,11 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 说明: 微信扫码支付接口参数
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:41
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@@ -40,5 +40,4 @@ public class WxBarCodePayParam {
|
||||
this.body = body;
|
||||
this.totalFee = totalFee;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,18 +1,18 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 说明: 微信扫码支付接口结果
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:42
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class WxBarCodePayResult extends WxBaseResult {
|
||||
public static final String HASPAYED = "ORDERPAID";
|
||||
public static final String HAS_PAYED = "ORDERPAID";
|
||||
/**
|
||||
* 公众账号ID
|
||||
*/
|
||||
+5
-24
@@ -1,14 +1,15 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 说明: 微信支付结果基础类
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:42
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class WxBaseResult {
|
||||
/**
|
||||
* 返回状态码
|
||||
@@ -25,31 +26,11 @@ public class WxBaseResult {
|
||||
|
||||
public boolean isSuccess() {
|
||||
if (StringUtils.isNotEmpty(resultCode)) {
|
||||
return resultCode.equals("SUCCESS");
|
||||
return ("SUCCESS".equals(resultCode));
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
isSuccess = success;
|
||||
}
|
||||
|
||||
public String getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
public void setResultCode(String resultCode) {
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BaseResult{" + "resultCode='" + resultCode + '\'' + ", message='" + message + '\'' + ", isSuccess=" + isSuccess + '}';
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 说明: 微信查询状态
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:43
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 说明: 微信退款参数
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:43
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
@@ -6,7 +6,7 @@ import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 说明: 退款返回结果
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:44
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
+2
-3
@@ -1,8 +1,8 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
/**
|
||||
* 说明: 微信退款状态
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/12 10:05
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@@ -12,7 +12,6 @@ public enum WxRefundStatusEnum {
|
||||
REFUNDCLOSE("退款关闭", "REFUNDCLOSE"),
|
||||
PROCESSING("退款处理中", "PROCESSING"),
|
||||
CHANGE("退款失败", "CHANGE");
|
||||
// 成员变量
|
||||
private String code;
|
||||
private String name;
|
||||
|
||||
+2
-3
@@ -1,8 +1,8 @@
|
||||
package com.xwbing.domain.entity.wxpay;
|
||||
package com.xwbing.domain.entity.pay.wxpay;
|
||||
|
||||
/**
|
||||
* 说明: 微信支付结果状态
|
||||
* 项目名称: spring-demo
|
||||
* 项目名称: boot-module-demo
|
||||
* 创建时间: 2017/5/10 17:44
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@@ -15,7 +15,6 @@ public enum WxTradeStatusEnum {
|
||||
REVOKED("已撤销(刷卡支付)", "REVOKED"),
|
||||
USERPAYING("用户支付中", "USERPAYING"),
|
||||
PAYERROR("支付失败", "PAYERROR");
|
||||
// 成员变量
|
||||
private String code;
|
||||
private String name;
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.alipay.api.request.AlipayTradeRefundRequest;
|
||||
import com.alipay.api.response.AlipayTradePayResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import com.alipay.api.response.AlipayTradeRefundResponse;
|
||||
import com.xwbing.domain.entity.alipay.*;
|
||||
import com.xwbing.domain.entity.pay.alipay.*;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.exception.PayException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -59,43 +59,38 @@ public class AlipayService {
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public AlipayBarCodePayResult barCodePay(AlipayBarCodePayParam param) throws PayException {
|
||||
param.setScene("bar_code");//设置条码支付
|
||||
public AlipayBarCodePayResult barCodePay(AlipayBarCodePayParam param) {
|
||||
//设置条码支付
|
||||
param.setScene("bar_code");
|
||||
AlipayBarCodePayResult result = new AlipayBarCodePayResult(false);
|
||||
String checkArgument = checkArgument(param);
|
||||
if (StringUtils.isNotEmpty(checkArgument)) {
|
||||
result.setMessage(checkArgument);
|
||||
return result;
|
||||
}
|
||||
//获得初始化的AlipayClient
|
||||
//获得初始化的aliPayClient
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(requestUrl, appId, privateKey, "json", "UTF-8", publicKey, "RSA2");
|
||||
//创建API对应的request类
|
||||
AlipayTradePayRequest request = new AlipayTradePayRequest();
|
||||
request.setBizContent(JSONObject.toJSONString(param));
|
||||
//通过alipayClient调用API,获得对应的response类
|
||||
AlipayTradePayResponse response = null;
|
||||
//通过aliPayClient调用API,获得对应的response类
|
||||
AlipayTradePayResponse response;
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
} catch (AlipayApiException e) {
|
||||
logger.info(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
if (response==null) {
|
||||
logger.info("alipay response is null!");
|
||||
result.setMessage("alipay response is null!");
|
||||
return result;
|
||||
logger.error(e.getMessage());
|
||||
throw new PayException("扫码支付异常");
|
||||
}
|
||||
result.setSuccess(response.isSuccess()); //源码StringUtils.isEmpty(this.subCode)
|
||||
//根据response中的结果继续业务逻辑处理:subCode不为空,表示接口调用失败|code为10000,代表接口调用成功,subCode为空
|
||||
if (StringUtils.isNotEmpty(response.getSubCode())) {
|
||||
result.setCode(response.getSubCode());
|
||||
result.setMessage(response.getSubMsg());
|
||||
logger.info(response.getSubMsg());
|
||||
return result;
|
||||
} else {
|
||||
if (StringUtils.isEmpty(response.getSubCode())) {
|
||||
result.setCode(response.getCode());
|
||||
result.setMessage(response.getMsg());
|
||||
} else {
|
||||
result.setCode(response.getSubCode());
|
||||
result.setMessage(response.getSubMsg());
|
||||
logger.error(response.getSubMsg());
|
||||
return result;
|
||||
}
|
||||
result.setTradeNo(response.getTradeNo());
|
||||
result.setOutTradeNo(response.getOutTradeNo());
|
||||
@@ -116,31 +111,25 @@ public class AlipayService {
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public AlipayRefundResult refund(AlipayRefundParam param) throws PayException {
|
||||
public AlipayRefundResult refund(AlipayRefundParam param) {
|
||||
AlipayRefundResult result = new AlipayRefundResult(false);
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(requestUrl, appId, privateKey, "json", "UTF-8", publicKey, "RSA2");
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
request.setBizContent(JSONObject.toJSONString(param));
|
||||
//通过alipayClient调用API,获得对应的response类
|
||||
AlipayTradeRefundResponse response = null;
|
||||
//通过aliPayClient调用API,获得对应的response类
|
||||
AlipayTradeRefundResponse response;
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
} catch (AlipayApiException e) {
|
||||
logger.info(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
if (response==null) {
|
||||
logger.info("alipay response is null!");
|
||||
result.setMessage("alipay response is null!");
|
||||
return result;
|
||||
logger.error(e.getMessage());
|
||||
throw new PayException("退款异常");
|
||||
}
|
||||
result.setSuccess(response.isSuccess());
|
||||
//如果subCode存在,代表调用接接口失败
|
||||
//如果subCode存在,代表调用接口失败
|
||||
if (StringUtils.isNotEmpty(response.getSubCode())) {
|
||||
logger.error(response.getSubMsg());
|
||||
result.setCode(response.getSubCode());
|
||||
result.setMessage(response.getSubMsg());
|
||||
logger.info(response.getSubMsg());
|
||||
return result;
|
||||
} else {
|
||||
result.setCode(response.getCode());
|
||||
@@ -165,7 +154,7 @@ public class AlipayService {
|
||||
* @param tradeNo 交易号(推荐)
|
||||
* @return
|
||||
*/
|
||||
public AlipayQueryResult queryOrder(String outTradeNo, String tradeNo) throws PayException {
|
||||
public AlipayQueryResult queryOrder(String outTradeNo, String tradeNo) {
|
||||
if (StringUtils.isEmpty(outTradeNo) && StringUtils.isEmpty(tradeNo)) {
|
||||
throw new PayException("订单号和交易号不能同时为空!");
|
||||
}
|
||||
@@ -180,48 +169,32 @@ public class AlipayService {
|
||||
jsonObject.put("trade_no", tradeNo);
|
||||
}
|
||||
request.setBizContent(jsonObject.toString());
|
||||
//通过alipayClient调用API,获得对应的response类
|
||||
AlipayTradeQueryResponse response = null;
|
||||
//通过aliPayClient调用API,获得对应的response类
|
||||
AlipayTradeQueryResponse response;
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
} catch (AlipayApiException e) {
|
||||
logger.info(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
if (response==null) {
|
||||
logger.info("alipay response is null!");
|
||||
result.setMessage("alipay response is null!");
|
||||
return result;
|
||||
logger.error(e.getMessage());
|
||||
throw new PayException("查询订单异常");
|
||||
}
|
||||
result.setSuccess(response.isSuccess());
|
||||
//如果subCode存在,代表调用接接口失败
|
||||
if (StringUtils.isNotEmpty(response.getSubCode())) {
|
||||
result.setCode(response.getSubCode());
|
||||
result.setMessage(response.getSubMsg());
|
||||
logger.info(response.getSubMsg());
|
||||
return result;
|
||||
} else {
|
||||
result.setCode(response.getCode());
|
||||
result.setMessage(response.getMsg());
|
||||
}
|
||||
//返回支付状态,业务调用时,遍历AlipayTradeStatusEnum与tradeStatus做比较
|
||||
//如果subCode存在,代表调用接口失败
|
||||
checkSubCode(result, response);
|
||||
//返回支付状态,业务调用时,遍历AliPayTradeStatusEnum与tradeStatus做比较
|
||||
result.setTradeStatus(response.getTradeStatus());
|
||||
logger.info(response.getTradeStatus());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款查询 没有tradeStatus,isSuccess即为成功
|
||||
* 退款查询 没有tradeStatus,isSuccess即为成功
|
||||
* 订单号和交易号2选1
|
||||
*
|
||||
* @param outTradeNo 订单号
|
||||
* @param tradeNo 交易号(推荐)
|
||||
* @param outRequestNo 退款请求号
|
||||
* @return
|
||||
* @throws PayException
|
||||
*/
|
||||
public AlipayQueryResult queryRefund(String outTradeNo, String tradeNo, String outRequestNo) throws PayException {
|
||||
public AlipayQueryResult queryRefund(String outTradeNo, String tradeNo, String outRequestNo) {
|
||||
if (StringUtils.isEmpty(outTradeNo) && StringUtils.isEmpty(tradeNo)) {
|
||||
throw new PayException("订单号和交易号不能同时为空!");
|
||||
}
|
||||
@@ -237,32 +210,34 @@ public class AlipayService {
|
||||
jsonObject.put("trade_no", tradeNo);
|
||||
}
|
||||
request.setBizContent(jsonObject.toString());
|
||||
//通过alipayClient调用API,获得对应的response类
|
||||
AlipayTradeQueryResponse response = null;
|
||||
//通过aliPayClient调用API,获得对应的response类
|
||||
AlipayTradeQueryResponse response;
|
||||
try {
|
||||
response = alipayClient.execute(request);
|
||||
} catch (AlipayApiException e) {
|
||||
logger.info(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
if (response==null) {
|
||||
logger.info("alipay response is null!");
|
||||
result.setMessage("alipay response is null!");
|
||||
return result;
|
||||
logger.error(e.getMessage());
|
||||
throw new PayException("退款查询异常");
|
||||
}
|
||||
result.setSuccess(response.isSuccess());
|
||||
//如果subCode存在,代表调用接接口失败。业务调用时只需判断result是否为success即可
|
||||
//如果subCode存在,代表调用接口失败
|
||||
checkSubCode(result, response);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询接口校验subCode是否存在。如果subCode存在,代表调用接口失败。业务调用时只需判断result是否为success即可
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private void checkSubCode(AlipayQueryResult result, AlipayTradeQueryResponse response) {
|
||||
if (StringUtils.isNotEmpty(response.getSubCode())) {
|
||||
result.setCode(response.getSubCode());
|
||||
result.setMessage(response.getSubMsg());
|
||||
logger.info(response.getSubMsg());
|
||||
logger.error(response.getSubMsg());
|
||||
} else {
|
||||
result.setCode(response.getCode());
|
||||
result.setMessage(response.getMsg());
|
||||
logger.info(response.getMsg());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,15 +245,15 @@ public class AlipayService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String checkArgument(AlipayBarCodePayParam parma) {
|
||||
private String checkArgument(AlipayBarCodePayParam param) {
|
||||
String message;
|
||||
if (StringUtils.isEmpty(parma.getOutTradeNo())) {
|
||||
if (StringUtils.isEmpty(param.getOutTradeNo())) {
|
||||
message = "订单号为空";
|
||||
} else if (StringUtils.isEmpty(parma.getAuthCode())) {
|
||||
} else if (StringUtils.isEmpty(param.getAuthCode())) {
|
||||
message = "授权码为空";
|
||||
} else if (StringUtils.isEmpty(parma.getSubject())) {
|
||||
} else if (StringUtils.isEmpty(param.getSubject())) {
|
||||
message = "产品名称为空";
|
||||
} else if (0 >= parma.getTotalAmount()) {
|
||||
} else if (0 >= param.getTotalAmount()) {
|
||||
message = "金额必须大于0";
|
||||
} else {
|
||||
message = StringUtils.EMPTY;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.xwbing.service.other;
|
||||
|
||||
import com.xwbing.domain.entity.wxpay.*;
|
||||
import com.xwbing.domain.entity.pay.wxpay.*;
|
||||
import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.exception.PayException;
|
||||
import com.xwbing.util.payWxpay.ClientCustomSSL;
|
||||
@@ -76,14 +76,14 @@ public class WxPayService {
|
||||
|
||||
/**
|
||||
* 条形码扫码付
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
* @throws PayException
|
||||
*/
|
||||
public WxBarCodePayResult barCodePay(WxBarCodePayParam param) throws PayException {
|
||||
public WxBarCodePayResult barCodePay(WxBarCodePayParam param) {
|
||||
WxBarCodePayResult result = new WxBarCodePayResult(false);
|
||||
HttpPost post = new HttpPost(barCodePayUrl);
|
||||
//输入参数为转为strxml
|
||||
//输入参数为转为strXml
|
||||
String reqBody = buildBarCodeRequestBody(param);
|
||||
post.setEntity(new StringEntity(reqBody, "UTF-8"));
|
||||
CloseableHttpClient httpclient;
|
||||
@@ -93,9 +93,8 @@ public class WxPayService {
|
||||
CloseableHttpResponse response = httpclient.execute(post);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
//返回结果为strxml
|
||||
//返回结果为strXml
|
||||
String content = EntityUtils.toString(entity, "UTF-8");
|
||||
logger.info(content + "===========++++");
|
||||
// 解析返回值
|
||||
Map<String, String> returnMap;
|
||||
returnMap = XmlUtil.doXMLParse(content);
|
||||
@@ -151,14 +150,14 @@ public class WxPayService {
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
* @throws PayException
|
||||
*/
|
||||
public WxRefundResult refund(WxRefundParam param) throws PayException {
|
||||
public WxRefundResult refund(WxRefundParam param) {
|
||||
WxRefundResult result = new WxRefundResult(false);
|
||||
HttpPost post = new HttpPost(refundUrl);
|
||||
//输入参数为转为strxml
|
||||
//输入参数为转为strXml
|
||||
String reqBody = buildRefundBarCodeRequestBody(param);
|
||||
post.setEntity(new StringEntity(reqBody, "UTF-8"));
|
||||
CloseableHttpClient httpclient;
|
||||
@@ -167,10 +166,9 @@ public class WxPayService {
|
||||
httpclient = ClientCustomSSL.getCloseableHttpClient(mchId);
|
||||
CloseableHttpResponse response = httpclient.execute(post);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
//返回结果为strxml
|
||||
//返回结果为strXml
|
||||
HttpEntity entity = response.getEntity();
|
||||
String content = EntityUtils.toString(entity, "UTF-8");
|
||||
logger.info(content + "===========++++");
|
||||
// 解析返回值
|
||||
Map<String, String> returnMap;
|
||||
returnMap = com.xwbing.util.payWxpay.XmlUtil.doXMLParse(content);
|
||||
@@ -231,10 +229,10 @@ public class WxPayService {
|
||||
* @param transactionId 微信的订单号(推荐)
|
||||
* @return
|
||||
*/
|
||||
public WxQueryResult oderQuery(String outTradeNo, String transactionId) throws PayException {
|
||||
public WxQueryResult orderQuery(String outTradeNo, String transactionId) {
|
||||
WxQueryResult result = new WxQueryResult(false);
|
||||
HttpPost post = new HttpPost(orderQueryUrl);
|
||||
//输入参数为转为strxml
|
||||
//输入参数为转为strXml
|
||||
String reqBody = buildQueryRequestBody(outTradeNo, transactionId);
|
||||
post.setEntity(new StringEntity(reqBody, "UTF-8"));
|
||||
CloseableHttpClient httpclient;
|
||||
@@ -244,9 +242,8 @@ public class WxPayService {
|
||||
CloseableHttpResponse response = httpclient.execute(post);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
//返回结果为strxml
|
||||
//返回结果为strXml
|
||||
String content = EntityUtils.toString(entity, "UTF-8");
|
||||
logger.info(content + "===========++++");
|
||||
// 解析返回值
|
||||
Map<String, String> returnMap;
|
||||
returnMap = XmlUtil.doXMLParse(content);
|
||||
@@ -299,12 +296,11 @@ public class WxPayService {
|
||||
* @param ouRefundNo 商户退款单号(推荐)
|
||||
* @param refundid 微信退款单号(推荐)
|
||||
* @return
|
||||
* @throws PayException
|
||||
*/
|
||||
public WxQueryResult refundQuery(String outTradeNo, String transactionId, String ouRefundNo, String refundid) throws PayException {
|
||||
public WxQueryResult refundQuery(String outTradeNo, String transactionId, String ouRefundNo, String refundid) {
|
||||
WxQueryResult result = new WxQueryResult(false);
|
||||
HttpPost post = new HttpPost(refundQueryUrl);
|
||||
//输入参数为转为strxml
|
||||
//输入参数为转为strXml
|
||||
String reqBody = buildRefundQueryRequestBody(outTradeNo, transactionId, ouRefundNo, refundid);
|
||||
post.setEntity(new StringEntity(reqBody, "UTF-8"));
|
||||
CloseableHttpClient httpclient;
|
||||
@@ -314,9 +310,8 @@ public class WxPayService {
|
||||
CloseableHttpResponse response = httpclient.execute(post);
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
//返回结果为strxml
|
||||
//返回结果为strXml
|
||||
String content = EntityUtils.toString(entity, "UTF-8");
|
||||
logger.info(content + "===========++++");
|
||||
// 解析返回值
|
||||
Map<String, String> returnMap;
|
||||
returnMap = XmlUtil.doXMLParse(content);
|
||||
@@ -324,7 +319,7 @@ public class WxPayService {
|
||||
result.setMessage(returnMap.get("return_msg"));
|
||||
//此字段是通信标识,非交易标识
|
||||
if ("FAIL".equalsIgnoreCase(returnMap.get("return_code"))) {
|
||||
logger.info("wx barCodePay failed!");
|
||||
logger.error("wx barCodePay failed!");
|
||||
result.setSuccess(false);
|
||||
return result;
|
||||
}
|
||||
@@ -369,8 +364,8 @@ public class WxPayService {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("appid", appId);
|
||||
params.put("mch_id", mchId);
|
||||
String nonce_str = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonce_str);
|
||||
String nonceStr = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonceStr);
|
||||
params.put("body", param.getBody());
|
||||
params.put("out_trade_no", param.getOutTradeNo());
|
||||
//单位分
|
||||
@@ -380,7 +375,7 @@ public class WxPayService {
|
||||
//签名放最后的
|
||||
String sign = WxSignKit.buildSign(params, apiKey);
|
||||
params.put("sign", sign);
|
||||
StringBuffer reqBody = new StringBuffer();
|
||||
StringBuilder reqBody = new StringBuilder();
|
||||
reqBody.append("<xml>");
|
||||
for (String key : params.keySet()) {
|
||||
String value = params.get(key);
|
||||
@@ -398,11 +393,11 @@ public class WxPayService {
|
||||
* @return
|
||||
*/
|
||||
private String buildRefundBarCodeRequestBody(WxRefundParam param) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("appid", appId);
|
||||
params.put("mch_id", mchId);
|
||||
String nonce_str = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonce_str);
|
||||
String nonceStr = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonceStr);
|
||||
if (StringUtils.isEmpty(param.getTransactionId()) && StringUtils.isEmpty(param.getOutTradeNo())) {
|
||||
throw new PayException("商户订单号和微信订单号不能同时为空!");
|
||||
}
|
||||
@@ -419,7 +414,7 @@ public class WxPayService {
|
||||
String sign = WxSignKit.buildSign(params, apiKey);
|
||||
params.put("sign", sign);
|
||||
//签名放最后的
|
||||
StringBuffer reqBody = new StringBuffer();
|
||||
StringBuilder reqBody = new StringBuilder();
|
||||
reqBody.append("<xml>");
|
||||
for (String key : params.keySet()) {
|
||||
String value = params.get(key);
|
||||
@@ -438,7 +433,7 @@ public class WxPayService {
|
||||
* @return
|
||||
*/
|
||||
private String buildQueryRequestBody(String outTradeNo, String transactionId) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("appid", appId);
|
||||
params.put("mch_id", mchId);
|
||||
if (StringUtils.isEmpty(transactionId) && StringUtils.isEmpty(outTradeNo)) {
|
||||
@@ -450,12 +445,12 @@ public class WxPayService {
|
||||
if (StringUtils.isNotEmpty(outTradeNo)) {
|
||||
params.put("out_trade_no", outTradeNo);
|
||||
}
|
||||
String nonce_str = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonce_str);
|
||||
String nonceStr = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonceStr);
|
||||
//签名放最后的
|
||||
String sign = WxSignKit.buildSign(params, apiKey);
|
||||
params.put("sign", sign);
|
||||
StringBuffer reqBody = new StringBuffer();
|
||||
StringBuilder reqBody = new StringBuilder();
|
||||
reqBody.append("<xml>");
|
||||
for (String key : params.keySet()) {
|
||||
String value = params.get(key);
|
||||
@@ -476,7 +471,7 @@ public class WxPayService {
|
||||
* @return
|
||||
*/
|
||||
private String buildRefundQueryRequestBody(String outTradeNo, String transactionId, String ouRefundNo, String refundid) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("appid", appId);
|
||||
params.put("mch_id", mchId);
|
||||
if (StringUtils.isEmpty(transactionId) && StringUtils.isEmpty(outTradeNo) && StringUtils.isEmpty(ouRefundNo) && StringUtils.isEmpty(refundid)) {
|
||||
@@ -494,12 +489,12 @@ public class WxPayService {
|
||||
if (StringUtils.isNotEmpty(refundid)) {
|
||||
params.put("refund_id", refundid);
|
||||
}
|
||||
String nonce_str = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonce_str);
|
||||
String nonceStr = RandomKit.buildRandom(32);
|
||||
params.put("nonce_str", nonceStr);
|
||||
//签名放最后的
|
||||
String sign = WxSignKit.buildSign(params, apiKey);
|
||||
params.put("sign", sign);
|
||||
StringBuffer reqBody = new StringBuffer();
|
||||
StringBuilder reqBody = new StringBuilder();
|
||||
reqBody.append("<xml>");
|
||||
for (String key : params.keySet()) {
|
||||
String value = params.get(key);
|
||||
@@ -521,7 +516,7 @@ public class WxPayService {
|
||||
//查询订单
|
||||
String outTradeNo = "2017051200";
|
||||
String transactionId = "4001082001201705120512385115";
|
||||
WxQueryResult queryResult = wxPayBuilder.oderQuery(outTradeNo, transactionId);
|
||||
WxQueryResult queryResult = wxPayBuilder.orderQuery(outTradeNo, transactionId);
|
||||
if (!queryResult.isSuccess()) {
|
||||
throw new BusinessException(queryResult.getMessage());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
jdbc.driver=com.mysql.jdbc.Driver
|
||||
jdbc.url=jdbc:mysql://127.0.0.1:3306/springboot2?useUnicode=true&characterEncoding=utf8
|
||||
jdbc.username=root
|
||||
jdbc.password=
|
||||
jdbc.password=xwbing
|
||||
# 初始化大小,最小,最大
|
||||
jdbc.initSize=1
|
||||
jdbc.minIdle=3
|
||||
|
||||
Reference in New Issue
Block a user