mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-06-04 23:49:46 +08:00
新增回调参数对象,回调处理
This commit is contained in:
@@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.egzosn.pay.common.bean.BillType;
|
||||
import com.egzosn.pay.common.bean.DefaultNoticeRequest;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.NoticeParams;
|
||||
import com.egzosn.pay.common.bean.NoticeRequest;
|
||||
@@ -56,7 +57,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
/**
|
||||
* 支付消息拦截器
|
||||
*/
|
||||
protected List<PayMessageInterceptor> interceptors = new ArrayList<PayMessageInterceptor>();
|
||||
protected List<PayMessageInterceptor<PayMessage, PayService>> interceptors = new ArrayList<PayMessageInterceptor<PayMessage, PayService>>();
|
||||
;
|
||||
|
||||
/**
|
||||
@@ -191,6 +192,17 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getParameter2Map(Map<String, String[]> parameterMap, InputStream is) {
|
||||
return getNoticeParams(new DefaultNoticeRequest(parameterMap, is)).getBody();
|
||||
}
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
* @param request 通知请求
|
||||
* @return 获得回调的请求参数
|
||||
*/
|
||||
@Override
|
||||
public NoticeParams getNoticeParams(NoticeRequest request) {
|
||||
final Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
|
||||
Map<String, Object> params = new TreeMap<String, Object>();
|
||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||
@@ -212,10 +224,9 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
}
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
return params;
|
||||
return new NoticeParams(params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 交易查询接口,带处理器
|
||||
*
|
||||
@@ -399,16 +410,7 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
* @param request 通知请求
|
||||
* @return 获得回调的请求参数
|
||||
*/
|
||||
@Override
|
||||
public NoticeParams getNoticeParams(NoticeRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
@@ -417,16 +419,29 @@ public abstract class BasePayService<PC extends PayConfigStorage> implements Pay
|
||||
* @param is 请求流
|
||||
* @return 获得回调响应信息
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public PayOutMessage payBack(Map<String, String[]> parameterMap, InputStream is) {
|
||||
Map<String, Object> data = getParameter2Map(parameterMap, is);
|
||||
return payBack(new DefaultNoticeRequest(parameterMap, is));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回调处理
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @return 获得回调响应信息
|
||||
*/
|
||||
@Override
|
||||
public PayOutMessage payBack(NoticeRequest request) {
|
||||
final NoticeParams noticeParams = getNoticeParams(request);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("回调响应:" + JSON.toJSONString(data));
|
||||
LOG.debug("回调响应:{}" , JSON.toJSONString(noticeParams));
|
||||
}
|
||||
if (!verify(data)) {
|
||||
if (!verify(noticeParams)) {
|
||||
return getPayOutMessage("fail", "失败");
|
||||
}
|
||||
PayMessage payMessage = this.createMessage(data);
|
||||
PayMessage payMessage = this.createMessage(noticeParams.getBody());
|
||||
Map<String, Object> context = new HashMap<String, Object>();
|
||||
for (PayMessageInterceptor interceptor : interceptors) {
|
||||
if (!interceptor.intercept(payMessage, context, this)) {
|
||||
|
||||
@@ -351,13 +351,21 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
<T> T transferQuery(String outNo, String tradeNo, Callback<T> callback);
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
* 回调处理
|
||||
*
|
||||
* @param parameterMap 请求参数
|
||||
* @param is 请求流
|
||||
* @return 获得回调响应信息
|
||||
* 过时方法,详情查看 {@link #payBack(NoticeRequest)}
|
||||
*/
|
||||
@Deprecated
|
||||
PayOutMessage payBack(Map<String, String[]> parameterMap, InputStream is);
|
||||
/**
|
||||
* 回调处理
|
||||
* @param request 请求参数
|
||||
* @return 获得回调响应信息
|
||||
*/
|
||||
PayOutMessage payBack(NoticeRequest request);
|
||||
|
||||
/**
|
||||
* 使用转换过的参数进行回调处理
|
||||
@@ -371,7 +379,7 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
* 设置支付消息处理器,这里用于处理具体的支付业务
|
||||
*
|
||||
* @param handler 消息处理器
|
||||
* 配合{@link com.egzosn.pay.common.api.PayService#payBack(java.util.Map, java.io.InputStream)}进行使用
|
||||
* 配合{@link com.egzosn.pay.common.api.PayService#payBack(NoticeRequest)}进行使用
|
||||
* <p>
|
||||
* 默认使用{@link com.egzosn.pay.common.api.DefaultPayMessageHandler }进行实现
|
||||
*/
|
||||
@@ -381,7 +389,7 @@ public interface PayService<PC extends PayConfigStorage> {
|
||||
* 设置支付消息处理器,这里用于处理具体的支付业务
|
||||
*
|
||||
* @param interceptor 消息拦截器
|
||||
* 配合{@link com.egzosn.pay.common.api.PayService#payBack(java.util.Map, java.io.InputStream)}进行使用
|
||||
* 配合{@link com.egzosn.pay.common.api.PayService#payBack(NoticeRequest)}进行使用
|
||||
* <p>
|
||||
* 默认使用{@link com.egzosn.pay.common.api.DefaultPayMessageHandler }进行实现
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.egzosn.pay.common.bean;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**`
|
||||
*
|
||||
* 默认的通知请求
|
||||
* @author Egan
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2021/8/18
|
||||
* </pre>
|
||||
*/
|
||||
public class DefaultNoticeRequest implements NoticeRequest {
|
||||
|
||||
private Map<String, String[]> parameterMap;
|
||||
private InputStream inputStream;
|
||||
|
||||
private Map<String, List<String>> headers;
|
||||
|
||||
public DefaultNoticeRequest(Map<String, String[]> parameterMap, InputStream inputStream) {
|
||||
this.parameterMap = parameterMap;
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
|
||||
public DefaultNoticeRequest(Map<String, String[]> parameterMap, InputStream inputStream, Map<String, List<String>> headers) {
|
||||
this.parameterMap = parameterMap;
|
||||
this.inputStream = inputStream;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public DefaultNoticeRequest(InputStream inputStream, Map<String, List<String>> headers) {
|
||||
this.inputStream = inputStream;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据请求头名称获取请求头信息
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 请求头值
|
||||
*/
|
||||
@Override
|
||||
public String getHeader(String name) {
|
||||
List<String> value = this.headers.get(name);
|
||||
return (null == value || value.isEmpty()) ? null : value.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据请求头名称获取请求头信息
|
||||
*
|
||||
* @param name 名称
|
||||
* @return 请求头值
|
||||
*/
|
||||
@Override
|
||||
public Enumeration<String> getHeaders(String name) {
|
||||
return Collections.enumeration(this.headers.get(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的请求头名称
|
||||
*
|
||||
* @return 请求头名称
|
||||
*/
|
||||
@Override
|
||||
public Enumeration<String> getHeaderNames() {
|
||||
return Collections.enumeration(this.headers.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入流
|
||||
*
|
||||
* @return 输入流
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的请求参数
|
||||
*
|
||||
* @return 请求参数
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
return parameterMap;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@ public class NoticeParams {
|
||||
*/
|
||||
private Map<String, Object> attr;
|
||||
|
||||
public NoticeParams() {
|
||||
}
|
||||
|
||||
public NoticeParams(Map<String, Object> body) {
|
||||
this.body = body;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MapGen<K, V> {
|
||||
keyValue(key, value);
|
||||
}
|
||||
|
||||
public MapGen keyValue(K key, V value) {
|
||||
public MapGen<K, V> keyValue(K key, V value) {
|
||||
attr.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.egzosn.pay.common.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class Util {
|
||||
/**
|
||||
@@ -69,9 +71,11 @@ public class Util {
|
||||
if (n.toByteArray().length == 33) {
|
||||
tmpd = new byte[32];
|
||||
System.arraycopy(n.toByteArray(), 1, tmpd, 0, 32);
|
||||
} else if (n.toByteArray().length == 32) {
|
||||
}
|
||||
else if (n.toByteArray().length == 32) {
|
||||
tmpd = n.toByteArray();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tmpd = new byte[32];
|
||||
for (int i = 0; i < 32 - n.toByteArray().length; i++) {
|
||||
tmpd[i] = 0;
|
||||
@@ -348,7 +352,8 @@ public class Util {
|
||||
int algorism = 0;
|
||||
if (c >= '0' && c <= '9') {
|
||||
algorism = c - '0';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
algorism = c - 55;
|
||||
}
|
||||
result += Math.pow(16, max - i) * algorism;
|
||||
@@ -493,7 +498,8 @@ public class Util {
|
||||
int i = 0;
|
||||
try {
|
||||
i = Integer.parseInt(s, radix);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
i = defaultInt;
|
||||
}
|
||||
return i;
|
||||
@@ -510,7 +516,8 @@ public class Util {
|
||||
int i = 0;
|
||||
try {
|
||||
i = Integer.parseInt(s);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
i = defaultInt;
|
||||
}
|
||||
return i;
|
||||
@@ -574,7 +581,7 @@ public class Util {
|
||||
/**
|
||||
* 一百
|
||||
*/
|
||||
public static final BigDecimal HUNDRED = new BigDecimal(100);
|
||||
public static final BigDecimal HUNDRED = new BigDecimal(100);
|
||||
|
||||
/**
|
||||
* 元转分
|
||||
@@ -597,4 +604,13 @@ public class Util {
|
||||
}
|
||||
|
||||
|
||||
public static <K, V> boolean isEmpty(Map<K, V> map) {
|
||||
return null == map || map.isEmpty();
|
||||
}
|
||||
|
||||
public static <V> boolean isEmpty(Collection<V> collection) {
|
||||
return null == collection || collection.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -31,6 +31,11 @@
|
||||
<artifactId>pay-java-wx</artifactId>
|
||||
<version>${pay.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<artifactId>pay-java-web-support</artifactId>
|
||||
<version>${pay.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.egzosn</groupId>
|
||||
<artifactId>pay-java-ali</artifactId>
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.egzosn.pay.ali.bean.AliTransferOrder;
|
||||
import com.egzosn.pay.ali.bean.AliTransferType;
|
||||
import com.egzosn.pay.ali.bean.OrderSettle;
|
||||
import com.egzosn.pay.common.bean.CertStoreType;
|
||||
import com.egzosn.pay.common.bean.NoticeParams;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
@@ -34,6 +35,7 @@ import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
import com.egzosn.pay.demo.service.handler.AliPayMessageHandler;
|
||||
import com.egzosn.pay.demo.service.interceptor.AliPayMessageInterceptor;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
|
||||
|
||||
/**
|
||||
@@ -223,13 +225,13 @@ public class AliPayController {
|
||||
public String payBackBefore(HttpServletRequest request) throws IOException {
|
||||
|
||||
//获取支付方返回的对应参数
|
||||
Map<String, Object> params = service.getParameter2Map(request.getParameterMap(), request.getInputStream());
|
||||
if (null == params) {
|
||||
NoticeParams noticeParams = service.getNoticeParams(new HttpRequestNoticeParams(request));
|
||||
if (null == noticeParams) {
|
||||
return service.getPayOutMessage("fail", "失败").toMessage();
|
||||
}
|
||||
|
||||
//校验
|
||||
if (service.verify(params)) {
|
||||
if (service.verify(noticeParams)) {
|
||||
//这里处理业务逻辑
|
||||
//......业务逻辑处理块........
|
||||
return service.successPayOutMessage(null).toMessage();
|
||||
@@ -242,7 +244,25 @@ public class AliPayController {
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 返回对应的响应码
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@Deprecated
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
@@ -250,12 +270,11 @@ public class AliPayController {
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.fuiou.api.FuiouPayConfigStorage;
|
||||
import com.egzosn.pay.fuiou.api.FuiouPayService;
|
||||
import com.egzosn.pay.fuiou.bean.FuiouTransactionType;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -112,15 +114,32 @@ public class FuiouPayController {
|
||||
*
|
||||
* @return 是否成功
|
||||
*
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
*
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
@Deprecated
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.egzosn.pay.common.api.PayConfigStorage;
|
||||
import com.egzosn.pay.common.api.PayMessageInterceptor;
|
||||
import com.egzosn.pay.common.api.PayService;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.NoticeParams;
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.PayOutMessage;
|
||||
@@ -41,6 +42,7 @@ 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.web.support.HttpRequestNoticeParams;
|
||||
import com.egzosn.pay.wx.bean.WxTransactionType;
|
||||
|
||||
/**
|
||||
@@ -319,32 +321,52 @@ public class PayController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调地址 方式一
|
||||
* <p>
|
||||
* 方式二,{@link #payBack(HttpServletRequest, Integer)} 是属于简化方式, 试用与简单的业务场景
|
||||
* 支付回调地址
|
||||
* 方式三
|
||||
*
|
||||
* @param request 请求
|
||||
* @param payId 账户id
|
||||
* @return 支付是否成功
|
||||
* @throws IOException IOException
|
||||
* 拦截器相关增加, 详情查看{@link com.egzosn.pay.common.api.PayService#addPayMessageInterceptor(PayMessageInterceptor)}
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* </p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
*/
|
||||
@RequestMapping(value = "payBack{payId}.json")
|
||||
public String payBack(HttpServletRequest request, @PathVariable Integer payId) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
PayResponse payResponse = service.getPayResponse(payId);
|
||||
return payResponse.getService().payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调地址 方式一
|
||||
* <p>
|
||||
* 建议使用 方式三,{@link #payBack(HttpServletRequest, Integer)} 是属于简化方式, 试用与简单的业务场景
|
||||
*
|
||||
* @param request 请求
|
||||
* @param payId 账户id
|
||||
* @return 支付是否成功
|
||||
*/
|
||||
@RequestMapping(value = "payBackOne{payId}.json")
|
||||
public String payBackOne(HttpServletRequest request, @PathVariable Integer payId) throws IOException {
|
||||
public String payBackOne(HttpServletRequest request, @PathVariable Integer payId) {
|
||||
//根据账户id,获取对应的支付账户操作工具
|
||||
PayResponse payResponse = service.getPayResponse(payId);
|
||||
PayConfigStorage storage = payResponse.getStorage();
|
||||
//获取支付方返回的对应参数
|
||||
Map<String, Object> params = payResponse.getService().getParameter2Map(request.getParameterMap(), request.getInputStream());
|
||||
// Map<String, Object> params = JSONObject.parseObject("{\"bizType\":\"000201\",\"signPubKeyCert\":\"-----BEGIN CERTIFICATE-----\\r\\nMIIEQzCCAyugAwIBAgIFEBJJZVgwDQYJKoZIhvcNAQEFBQAwWDELMAkGA1UEBhMC\\r\\nQ04xMDAuBgNVBAoTJ0NoaW5hIEZpbmFuY2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhv\\r\\ncml0eTEXMBUGA1UEAxMOQ0ZDQSBURVNUIE9DQTEwHhcNMTcxMTAxMDcyNDA4WhcN\\r\\nMjAxMTAxMDcyNDA4WjB3MQswCQYDVQQGEwJjbjESMBAGA1UEChMJQ0ZDQSBPQ0Ex\\r\\nMQ4wDAYDVQQLEwVDVVBSQTEUMBIGA1UECxMLRW50ZXJwcmlzZXMxLjAsBgNVBAMU\\r\\nJTA0MUBaMjAxNy0xMS0xQDAwMDQwMDAwOlNJR05AMDAwMDAwMDEwggEiMA0GCSqG\\r\\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDDIWO6AESrg+34HgbU9mSpgef0sl6avr1d\\r\\nbD/IjjZYM63SoQi3CZHZUyoyzBKodRzowJrwXmd+hCmdcIfavdvfwi6x+ptJNp9d\\r\\nEtpfEAnJk+4quriQFj1dNiv6uP8ARgn07UMhgdYB7D8aA1j77Yk1ROx7+LFeo7rZ\\r\\nDdde2U1opPxjIqOPqiPno78JMXpFn7LiGPXu75bwY2rYIGEEImnypgiYuW1vo9UO\\r\\nG47NMWTnsIdy68FquPSw5FKp5foL825GNX3oJSZui8d2UDkMLBasf06Jz0JKz5AV\\r\\nblaI+s24/iCfo8r+6WaCs8e6BDkaijJkR/bvRCQeQpbX3V8WoTLVAgMBAAGjgfQw\\r\\ngfEwHwYDVR0jBBgwFoAUz3CdYeudfC6498sCQPcJnf4zdIAwSAYDVR0gBEEwPzA9\\r\\nBghggRyG7yoBATAxMC8GCCsGAQUFBwIBFiNodHRwOi8vd3d3LmNmY2EuY29tLmNu\\r\\nL3VzL3VzLTE0Lmh0bTA5BgNVHR8EMjAwMC6gLKAqhihodHRwOi8vdWNybC5jZmNh\\r\\nLmNvbS5jbi9SU0EvY3JsMjQ4NzIuY3JsMAsGA1UdDwQEAwID6DAdBgNVHQ4EFgQU\\r\\nmQQLyuqYjES7qKO+zOkzEbvdFwgwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUF\\r\\nBwMEMA0GCSqGSIb3DQEBBQUAA4IBAQAujhBuOcuxA+VzoUH84uoFt5aaBM3vGlpW\\r\\nKVMz6BUsLbIpp1ho5h+LaMnxMs6jdXXDh/du8X5SKMaIddiLw7ujZy1LibKy2jYi\\r\\nYYfs3tbZ0ffCKQtv78vCgC+IxUUurALY4w58fRLLdu8u8p9jyRFHsQEwSq+W5+bP\\r\\nMTh2w7cDd9h+6KoCN6AMI1Ly7MxRIhCbNBL9bzaxF9B5GK86ARY7ixkuDCEl4XCF\\r\\nJGxeoye9R46NqZ6AA/k97mJun//gmUjStmb9PUXA59fR5suAB5o/5lBySZ8UXkrI\\r\\npp/iLT8vIl1hNgLh0Ghs7DBSx99I+S3VuUzjHNxL6fGRhlix7Rb8\\r\\n-----END CERTIFICATE-----\",\"orderId\":\"20171213224128\",\"signature\":\"l8xBYSoMNzt01DDa9/JYcrQKWxN5tasUgSxf6NNsQK5t+DqMr2G9qhHXnDg5bEzeRyTFP4bM3htX9RTRhXYDy7EEsL46ZD4ib5I6mp2wXx+26zscUcLdJUiddkY5eFvQK4tPC8blw7Y6p858yiVJpHgbOK3cONhS7vwPJtK2jMbkY+GATu3aZ4iygkQc75cG+EW8nJQVwLNh7q9A6A6II18EFxR7XubdlIHXv/InVaS6ux8Wh2nmQlhRRnLtHq1ri7v1QPlu2FzM+kaf7/fn61iGr8zEPj62NzWDXue62LUfb4kTRgdkcJnfJBJl8vjZ/w93UtsnK3zjzJC/Nu+wCw==\",\"txnSubType\":\"01\",\"traceNo\":\"492156\",\"accNo\":\"6221********0000\",\"settleAmt\":\"1000\",\"settleCurrencyCode\":\"156\",\"settleDate\":\"1213\",\"txnType\":\"01\",\"encoding\":\"UTF-8\",\"version\":\"5.1.0\",\"queryId\":\"511712132241284921568\",\"accessType\":\"0\",\"exchangeRate\":\"0\",\"respMsg\":\"success\",\"traceTime\":\"1213224128\",\"txnTime\":\"20171213224128\",\"merId\":\"777290058154626\",\"currencyCode\":\"156\",\"respCode\":\"00\",\"signMethod\":\"01\",\"txnAmt\":\"1000\"}");
|
||||
final PayService service = payResponse.getService();
|
||||
final NoticeParams noticeParams = service.getNoticeParams(new HttpRequestNoticeParams(request));
|
||||
|
||||
if (null == params) {
|
||||
if (null == noticeParams) {
|
||||
return payResponse.getService().getPayOutMessage("fail", "失败").toMessage();
|
||||
}
|
||||
|
||||
//校验
|
||||
if (payResponse.getService().verify(params)) {
|
||||
if (payResponse.getService().verify(noticeParams)) {
|
||||
Map<String, Object> params = noticeParams.getBody();
|
||||
//方式一 或者创建PayMessage的子类,AliPayMessage,WxPayMessage等等
|
||||
/* PayMessage message = new PayMessage(params, storage.getPayType(), storage.getMsgType().name());
|
||||
PayOutMessage outMessage = payResponse.getRouter().route(message);*/
|
||||
@@ -379,8 +401,9 @@ public class PayController {
|
||||
* </p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
*/
|
||||
@RequestMapping(value = "payBack{payId}.json")
|
||||
public String payBack(HttpServletRequest request, @PathVariable Integer payId) throws IOException {
|
||||
@Deprecated
|
||||
@RequestMapping(value = "payBackOld{payId}.json")
|
||||
public String payBackOld(HttpServletRequest request, @PathVariable Integer payId) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
PayResponse payResponse = service.getPayResponse(payId);
|
||||
return payResponse.getService().payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
|
||||
@@ -22,6 +22,7 @@ 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;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
|
||||
/**
|
||||
* 发起支付入口
|
||||
@@ -129,17 +130,35 @@ public class PayPalPayController {
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 结果
|
||||
*
|
||||
* @return 是否成功
|
||||
*
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
*
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.egzosn.pay.paypal.v2.bean.PayPalOrder;
|
||||
import com.egzosn.pay.paypal.v2.bean.order.AddressPortable;
|
||||
import com.egzosn.pay.paypal.v2.bean.order.Name;
|
||||
import com.egzosn.pay.paypal.v2.bean.order.ShippingDetail;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
|
||||
/**
|
||||
* 发起支付入口
|
||||
@@ -138,25 +139,38 @@ public class PayPalV2PayController {
|
||||
return "failure";
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
/**
|
||||
* 支付回调地址
|
||||
* 注意:这里不是异步回调的通知 IPN 地址设置的路径:https://developer.paypal.com/developer/ipnSimulator/
|
||||
* 参数解析与校验 https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNIntro/#id08CKFJ00JYK
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 结果
|
||||
*
|
||||
* @return 是否成功
|
||||
*
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
*
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
// 参数解析与校验 https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNIntro/#id08CKFJ00JYK
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ import com.egzosn.pay.union.api.UnionPayConfigStorage;
|
||||
import com.egzosn.pay.union.api.UnionPayService;
|
||||
import com.egzosn.pay.union.bean.UnionRefundResult;
|
||||
import com.egzosn.pay.union.bean.UnionTransactionType;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -231,19 +233,34 @@ public class UnionPayController {
|
||||
*
|
||||
* @param request 请求
|
||||
*
|
||||
* @return 是否成功
|
||||
* @return 是否成功
|
||||
*
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
*
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ package com.egzosn.pay.demo.controller;
|
||||
import com.egzosn.pay.common.bean.*;
|
||||
import com.egzosn.pay.common.http.HttpConfigStorage;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
import com.egzosn.pay.wx.api.WxPayConfigStorage;
|
||||
import com.egzosn.pay.wx.api.WxPayService;
|
||||
import com.egzosn.pay.wx.bean.*;
|
||||
@@ -245,13 +246,13 @@ public class WxPayController {
|
||||
public String payBackBefore(HttpServletRequest request) throws IOException {
|
||||
|
||||
//获取支付方返回的对应参数
|
||||
Map<String, Object> params = service.getParameter2Map(request.getParameterMap(), request.getInputStream());
|
||||
if (null == params) {
|
||||
NoticeParams noticeParams = service.getNoticeParams(new HttpRequestNoticeParams(request));
|
||||
if (null == noticeParams) {
|
||||
return service.getPayOutMessage("fail", "失败").toMessage();
|
||||
}
|
||||
|
||||
//校验
|
||||
if (service.verify(params)) {
|
||||
if (service.verify(noticeParams)) {
|
||||
//这里处理业务逻辑
|
||||
//......业务逻辑处理块........
|
||||
return service.successPayOutMessage(null).toMessage();
|
||||
@@ -271,11 +272,27 @@ public class WxPayController {
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
@RequestMapping(value = "payBackOld.json")
|
||||
public String payBackOld(HttpServletRequest request) throws IOException {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
}
|
||||
/**
|
||||
* 支付回调地址
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* <p>
|
||||
* 业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看{@link com.egzosn.pay.common.api.PayService#setPayMessageHandler(com.egzosn.pay.common.api.PayMessageHandler)}
|
||||
* <p>
|
||||
* 如果未设置 {@link com.egzosn.pay.common.api.PayMessageHandler} 那么会使用默认的 {@link com.egzosn.pay.common.api.DefaultPayMessageHandler}
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,10 +17,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.egzosn.pay.common.bean.CertStoreType;
|
||||
import com.egzosn.pay.common.bean.NoticeRequest;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
import com.egzosn.pay.common.bean.RefundOrder;
|
||||
import com.egzosn.pay.common.bean.TransferOrder;
|
||||
import com.egzosn.pay.demo.request.QueryOrder;
|
||||
import com.egzosn.pay.demo.service.handler.WxPayMessageHandler;
|
||||
import com.egzosn.pay.web.support.HttpRequestNoticeParams;
|
||||
import com.egzosn.pay.wx.bean.WxBank;
|
||||
import com.egzosn.pay.wx.bean.WxTransferType;
|
||||
import com.egzosn.pay.wx.v3.api.WxPayConfigStorage;
|
||||
@@ -67,7 +70,7 @@ public class WxV3PayController {
|
||||
service = new WxPayService(wxPayConfigStorage);
|
||||
//设置回调消息处理
|
||||
//TODO {@link com.egzosn.pay.demo.controller.WxPayController#payBack}
|
||||
// service.setPayMessageHandler(new WxPayMessageHandler(null));
|
||||
service.setPayMessageHandler(new WxPayMessageHandler(null));
|
||||
}
|
||||
|
||||
|
||||
@@ -162,35 +165,6 @@ public class WxV3PayController {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 支付回调地址 方式一
|
||||
* <p>
|
||||
* 方式二,{@link #payBack(HttpServletRequest)} 是属于简化方式, 试用与简单的业务场景
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 是否成功
|
||||
* @throws IOException IOException
|
||||
* @see #payBack(HttpServletRequest)
|
||||
*/
|
||||
@Deprecated
|
||||
@RequestMapping(value = "payBackBefore.json")
|
||||
public String payBackBefore(HttpServletRequest request) throws IOException {
|
||||
|
||||
//获取支付方返回的对应参数
|
||||
Map<String, Object> params = service.getParameter2Map(request.getParameterMap(), request.getInputStream());
|
||||
if (null == params) {
|
||||
return service.getPayOutMessage("fail", "失败").toMessage();
|
||||
}
|
||||
|
||||
//校验
|
||||
if (service.verify(params)) {
|
||||
//这里处理业务逻辑
|
||||
//......业务逻辑处理块........
|
||||
return service.successPayOutMessage(null).toMessage();
|
||||
}
|
||||
|
||||
return service.getPayOutMessage("fail", "失败").toMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付回调地址
|
||||
@@ -204,9 +178,9 @@ public class WxV3PayController {
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
@RequestMapping(value = "payBack.json")
|
||||
public String payBack(HttpServletRequest request) throws IOException {
|
||||
public String payBack(HttpServletRequest request) {
|
||||
//业务处理在对应的PayMessageHandler里面处理,在哪里设置PayMessageHandler,详情查看com.egzosn.pay.common.api.PayService.setPayMessageHandler()
|
||||
return service.payBack(request.getParameterMap(), request.getInputStream()).toMessage();
|
||||
return service.payBack(new HttpRequestNoticeParams(request)).toMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,11 +5,13 @@ import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
|
||||
@@ -19,6 +21,7 @@ import static com.egzosn.pay.wx.api.WxConst.RETURN_MSG_CODE;
|
||||
import static com.egzosn.pay.wx.api.WxConst.SANDBOXNEW;
|
||||
import static com.egzosn.pay.wx.api.WxConst.SUCCESS;
|
||||
import static com.egzosn.pay.wx.v3.utils.AntCertificationUtil.getCertificate;
|
||||
import static com.egzosn.pay.wx.v3.utils.WxConst.FAILURE;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -27,6 +30,7 @@ import com.egzosn.pay.common.bean.BillType;
|
||||
import com.egzosn.pay.common.bean.CurType;
|
||||
import com.egzosn.pay.common.bean.MethodType;
|
||||
import com.egzosn.pay.common.bean.NoticeParams;
|
||||
import com.egzosn.pay.common.bean.NoticeRequest;
|
||||
import com.egzosn.pay.common.bean.OrderParaStructure;
|
||||
import com.egzosn.pay.common.bean.PayMessage;
|
||||
import com.egzosn.pay.common.bean.PayOrder;
|
||||
@@ -41,8 +45,8 @@ import com.egzosn.pay.common.http.ResponseEntity;
|
||||
import com.egzosn.pay.common.http.UriVariables;
|
||||
import com.egzosn.pay.common.util.DateUtils;
|
||||
import com.egzosn.pay.common.util.IOUtils;
|
||||
import com.egzosn.pay.common.util.MapGen;
|
||||
import com.egzosn.pay.common.util.Util;
|
||||
import com.egzosn.pay.common.util.XML;
|
||||
import com.egzosn.pay.common.util.sign.SignTextUtils;
|
||||
import com.egzosn.pay.common.util.sign.SignUtils;
|
||||
import com.egzosn.pay.common.util.sign.encrypt.RSA2;
|
||||
@@ -82,12 +86,11 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
private volatile WxPayAssistService wxPayAssistService;
|
||||
|
||||
/**
|
||||
* 微信参数构造器
|
||||
* 微信参数构造器
|
||||
*/
|
||||
private volatile WxParameterStructure wxParameterStructure;
|
||||
|
||||
|
||||
|
||||
public WxPayAssistService getAssistService() {
|
||||
if (null == wxPayAssistService) {
|
||||
wxPayAssistService = new DefaultWxPayAssistService(this);
|
||||
@@ -190,8 +193,17 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
String signature = noticeParams.getHeader("Wechatpay-Signature");
|
||||
|
||||
Certificate certificate = getCertificate(serial);
|
||||
|
||||
Map<String, Object> attr = noticeParams.getAttr();
|
||||
|
||||
if (Util.isEmpty(attr)) {
|
||||
throw new PayErrorException(new WxPayError(FAILURE, "请勿置空NoticeParams.attr中的数据"));
|
||||
}
|
||||
|
||||
//这里为微信回调时的请求内容体,原值数据
|
||||
String body = (String) attr.get(WxConst.RESP_BODY);
|
||||
//签名信息
|
||||
String signText = StringUtils.joining("\n", timestamp, nonce, JSON.toJSONString(noticeParams.getBody()));
|
||||
String signText = StringUtils.joining("\n", timestamp, nonce, body);
|
||||
|
||||
return RSA2.verify(signText, signature, certificate, payConfigStorage.getInputCharset());
|
||||
}
|
||||
@@ -304,14 +316,35 @@ public class WxPayService extends BasePayService<WxPayConfigStorage> {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getParameter2Map(Map<String, String[]> parameterMap, InputStream is) {
|
||||
TreeMap<String, Object> map = new TreeMap<String, Object>();
|
||||
try {
|
||||
return XML.inputStream2Map(is, map);
|
||||
throw new PayErrorException(new WxPayError(FAILURE, "微信V3不支持方式"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将请求参数或者请求流转化为 Map
|
||||
*
|
||||
* @param request 通知请求
|
||||
* @return 获得回调的请求参数
|
||||
*/
|
||||
@Override
|
||||
public NoticeParams getNoticeParams(NoticeRequest request) {
|
||||
NoticeParams noticeParams = new NoticeParams();
|
||||
Map<String, List<String>> headers = new HashMap<>();
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String name = headerNames.nextElement();
|
||||
headers.put(name, Collections.list(request.getHeaders(name)));
|
||||
}
|
||||
noticeParams.setHeaders(headers);
|
||||
try (InputStream is = request.getInputStream()) {
|
||||
String body = IOUtils.toString(is);
|
||||
noticeParams.setAttr(new MapGen<String, Object>(WxConst.RESP_BODY, body).getAttr());
|
||||
noticeParams.setBody(JSON.parseObject(body));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new PayErrorException(new PayException("IOException", e.getMessage()));
|
||||
LOG.error("获取回调参数异常", e);
|
||||
}
|
||||
|
||||
return super.getNoticeParams(request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.egzosn.pay.wx.v3.utils;
|
||||
|
||||
import com.egzosn.pay.wx.v3.api.WxPayService;
|
||||
|
||||
/**
|
||||
* 微信所需常量
|
||||
*
|
||||
@@ -44,4 +46,6 @@ public final class WxConst {
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String SCENE_INFO = "scene_info";
|
||||
public static final String FAILURE = "failure";
|
||||
|
||||
public static final String RESP_BODY = WxPayService.class.getName() + "$RESP_BODY";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user