Commit 34feebb5 authored by zhuxiao's avatar zhuxiao
Browse files

优化微信V3回调 获取参数

parent 43b46d31
...@@ -26,6 +26,9 @@ import org.springframework.web.context.request.RequestAttributes; ...@@ -26,6 +26,9 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
...@@ -46,6 +49,23 @@ public class RequestKitBean { ...@@ -46,6 +49,23 @@ public class RequestKitBean {
/** reqContext对象中的key: 转换好的json对象 */ /** reqContext对象中的key: 转换好的json对象 */
private static final String REQ_CONTEXT_KEY_PARAMJSON = "REQ_CONTEXT_KEY_PARAMJSON"; private static final String REQ_CONTEXT_KEY_PARAMJSON = "REQ_CONTEXT_KEY_PARAMJSON";
/**request.getParameter 获取参数 并转换为JSON格式 **/
public String getReqParamFromBody() {
String body = "";
try {
String str;
while((str = request.getReader().readLine()) != null){
body += str;
}
return body;
} catch (Exception e) {
log.error("请求参数转换异常! params=[{}]", body);
throw new BizException(ApiCodeEnum.PARAMS_ERROR, "转换异常");
}
}
/**request.getParameter 获取参数 并转换为JSON格式 **/ /**request.getParameter 获取参数 并转换为JSON格式 **/
public JSONObject reqParam2JSON() { public JSONObject reqParam2JSON() {
......
...@@ -72,8 +72,8 @@ public abstract class AbstractChannelNoticeService implements IChannelNoticeServ ...@@ -72,8 +72,8 @@ public abstract class AbstractChannelNoticeService implements IChannelNoticeServ
} }
/**request.getParameter 获取参数 并转换为JSON格式 **/ /**request.getParameter 获取参数 并转换为JSON格式 **/
protected JSONObject reqParam2JSON() { protected String getReqParamFromBody() {
return requestKitBean.reqParam2JSON(); return requestKitBean.getReqParamFromBody();
} }
/** 获取文件路径 **/ /** 获取文件路径 **/
......
...@@ -198,9 +198,9 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService { ...@@ -198,9 +198,9 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
header.setSignature(request.getHeader("Wechatpay-Signature")); header.setSignature(request.getHeader("Wechatpay-Signature"));
// 获取加密信息 // 获取加密信息
JSONObject params = reqParam2JSON(); String params = getReqParamFromBody();
log.info("\n【请求头信息】:{}\n【加密数据】:{}", header.toString(), params.toJSONString()); log.info("\n【请求头信息】:{}\n【加密数据】:{}", header.toString(), params);
WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService(); WxPayService wxPayService = mchAppConfigContext.getWxServiceWrapper().getWxPayService();
WxPayConfig wxPayConfig = wxPayService.getConfig(); WxPayConfig wxPayConfig = wxPayService.getConfig();
...@@ -212,7 +212,7 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService { ...@@ -212,7 +212,7 @@ public class WxpayChannelNoticeService extends AbstractChannelNoticeService {
wxPayConfig.setVerifier(verifier); wxPayConfig.setVerifier(verifier);
wxPayService.setConfig(wxPayConfig); wxPayService.setConfig(wxPayConfig);
WxPayOrderNotifyV3Result result = wxPayService.parseOrderNotifyV3Result(params.toJSONString(), header); WxPayOrderNotifyV3Result result = wxPayService.parseOrderNotifyV3Result(params, header);
return result.getResult(); return result.getResult();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment