oyww123
oyww123
2021-05-16 11:16
采纳率: 100%
浏览 105
已采纳

微信支付成功回调异常

这是回调方法

}
@RequestMapping("/xcxNotify")
@PostMapping(value = "pay",produces = "application/xml")//声明返回结果为xml类型
public Map<String,String> hello(@RequestBody Map<String,String> result){//在pom文件中引入了xml解析器


    System.err.println("[订单服务] 接收微信支付回调");

    Map<String,String> msg = new HashMap<>();
    msg.put("return_code", "SUCCESS");
    msg.put("return_msg", "OK");

    return msg;
}

下面是异常

com.alibaba.fastjson.JSONException: syntax error, expect {, actual 1
    at com.alibaba.fastjson.parser.deserializer.MapDeserializer.parseMap(MapDeserializer.java:67)
    at com.alibaba.fastjson.parser.deserializer.MapDeserializer.deserialze(MapDeserializer.java:53)
    at com.alibaba.fastjson.parser.deserializer.MapDeserializer.deserialze(MapDeserializer.java:39)
    at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:642)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:350)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:318)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:281)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:381)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:463)
    at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.read(FastJsonHttpMessageConverter.java:192)
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:206)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.shopx5.config.ServletFilter.doFilter(ServletFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • technologist_36
    CSDN专家-sinjack 2021-05-16 11:30
    已采纳

    看错误是json解析异常,你看下官方文档,有demo的

    点赞 1 评论
  • technologist_15
    CSDN专家-三岁丫 2021-05-16 11:42

    微信的回调是一个 xml 格式的,是没有办法直接转成 map 的,至少通过 json 的工具不行。你要获取到原始内容,然后通过其他的方式解析这个 xml。然后再提取你想要的信息。

    点赞 1 评论
  • technologist_36
    CSDN专家-sinjack 2021-05-16 15:25
    //回调接口
    @RequestMapping("/payNotify")
    	@ResponseBody
    	public void payNotify(HttpServletRequest request, HttpServletResponse response) {
    		String res = "";
    		try {
    			Map<String, String> map =getPostXmlData(request);
    		} catch (Exception e) {
    			e.printStackTrace();
    			res = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>";
    		} finally {
    			try {
    				response.getWriter().write(res);
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    
    
    //工具方法
    public Map<String, String> getPostXmlData(HttpServletRequest request) throws BussinessException {
    		String xmlData = null;
    		ServletInputStream sis = null;
    		Map<String, String> resMap = new HashMap();
    		try {
    			// 取HTTP请求流
    			sis = request.getInputStream();
    			// 取HTTP请求流长度
    			int size = request.getContentLength();
    			// 用于缓存每次读取的数据
    			byte[] buffer = new byte[size];
    			// 用于存放结果的数组
    			byte[] xmldataByte = new byte[size];
    			int count = 0;
    			int rbyte = 0;
    			// 循环读取
    			while (count < size) {
    				// 每次实际读取长度存于rbyte中
    				rbyte = sis.read(buffer);
    				for (int i = 0; i < rbyte; i++) {
    					xmldataByte[count + i] = buffer[i];
    				}
    				count += rbyte;
    			}
    			xmlData = new String(xmldataByte, "UTF-8");
    			resMap = WxPayV3Util.readStringXmlOut(xmlData);
    		} catch (IOException e) {
    			logger.error("文件流异常", e);
    		} catch (Exception e) {
    			logger.error("系统异常", e);
    		} finally {
    			if (sis != null) {
    				try {
    					sis.close();
    				} catch (IOException e) {
    					logger.error("文件流异常", e);
    				}
    			}
    		}
    		return resMap;
    	}
    
    点赞 评论
  • QA_Assistant
    有问必答小助手 2021-05-17 16:45

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    点赞 评论

相关推荐