NutzCN Logo
问答 微信信息接收后由于Streams关闭,返回报错
发布于 2053天前 作者 qq_6d75074b 1811 次浏览 复制 上一个帖子 下一个帖子
标签:
	// protected WxHandler wxHandler = new BasicWxHandler("1234567890");
	@At // 拼起来的全路径就是 /weixin/msgin
	@Filters
	@AdaptBy(type = VoidAdaptor.class)
	public View msgin(HttpServletRequest req, HttpServletResponse res) throws IOException {
		System.out.println(11111);
		System.out.println(res.getCharacterEncoding());
		System.out.println(req.getQueryString());
		Map xx = req.getParameterMap();
		String postData = Streams.readAndClose(new InputStreamReader(req.getInputStream(), "utf8"));
		System.out.println(postData);
		return Wxs.handle(wxHandler, req, "default"); // 最后面的default,可以不写,只是个标识符.
	}

signature=b7eaf99ff181e726fa4c739952a02f8d5f571fbb&timestamp=1557505428&nonce=335255918&openid=ofw7L1dqcaJ5mPmxxnISprWCiVWU
<xml><ToUserName><![CDATA[gh_db3a698b1ae0]]></ToUserName>
<FromUserName><![CDATA[ofw7L1dqcaJ5mPmxxnISprWCiVWU]]></FromUserName>
<CreateTime>1557505428</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[unsubscribe]]></Event>
<EventKey><![CDATA[]]></EventKey>
</xml>
2019-05-11 00:23:46,365 cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:28) DEBUG - [POST]URI=/alfx/weixin/msgin/ 352ms
2019-05-11 00:23:46,365 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/weixin/msgin/ :
java.lang.RuntimeException: java.io.IOException: Stream closed
	at org.nutz.lang.Lang.wrapThrow(Lang.java:184)
	at org.nutz.lang.Streams.readAndClose(Streams.java:293)
	at org.nutz.weixin.util.Wxs.handle(Wxs.java:688)
	at cn.wx.WeixinModule.msgin(WeixinModule.java:55)
	at cn.wx.WeixinModule$FM$msgin$00511e4c15a70da1bf58aade44c3ac07.invoke(WeixinModule.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:23)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at cn.core.mvc.MyNutFilter.doFilter(MyNutFilter.java:37)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at cn.core.util.XFilter.doFilter(XFilter.java:25)
	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:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Stream closed
	at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:355)
	at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:132)
	at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
	at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
	at sun.nio.cs.StreamDecoder.read(Unknown Source)
	at java.io.InputStreamReader.read(Unknown Source)
	at java.io.Reader.read(Unknown Source)
	at org.nutz.lang.Streams.read(Streams.java:316)
	at org.nutz.lang.Streams.read(Streams.java:274)
	at org.nutz.lang.Streams.readAndClose(Streams.java:290)
	... 46 more

19 回复
		System.out.println(11111);
		System.out.println(res.getCharacterEncoding());
		System.out.println(req.getQueryString());
		Map xx = req.getParameterMap();
		String postData = Streams.readAndClose(new InputStreamReader(req.getInputStream(), "utf8"));
		System.out.println(postData);

这堆东西把请求的内容都读完了, 后续的代码读不到xml内容的

我要回复的 XML 怎么放到 req中?

wxHandler里面的方法, 返回WxOutMsg就行啦

DefaultWxHandler 中有WxOutMsg函数的,现在报 Streams.close关闭错误,怎么处理才不报错,将信息返回回去?

@IocBean(create = "init", name = "wxHandler")
public class DefaultWxHandler extends BasicWxHandler {

	@Inject
	protected PropertiesProxy conf; // 注入配置信息加载类

	public void init() {
		// 将读取 weixin.token/weixin.aes/weixin.appid, 他们通常会写在weixin.properties或从数据库读取.
		configure(conf, "weixin.");
		// 把下面这行取消注释.
		// token = "1234567890";
	}

	@Override
	public WxOutMsg text(WxInMsg msg) {
		if ("1".equals(msg.getContent())) {
			return Wxs.respText("广告法说不能自称第一");
		} else if ("2".equals(msg.getContent())) {
			return Wxs.respText("就是这么2");
		}
		return super.text(msg);
	}

}

把那堆System.out.println统统删掉

	// protected WxHandler wxHandler = new BasicWxHandler("1234567890");
	@At // 拼起来的全路径就是 /weixin/msgin
	@Filters
	@AdaptBy(type = VoidAdaptor.class)
	public View msgin(HttpServletRequest req) throws IOException {
		Map xx = req.getParameterMap();
		String postData = Streams.readAndClose(new InputStreamReader(req.getInputStream(), "utf8"));
		return Wxs.handle(wxHandler, req, "default"); // 最后面的default,可以不写,只是个标识符.
	}

删了还是报一样的错误,Streams.readAndClose(new InputStreamReader(req.getInputStream(), "utf8")); 错误应该是这条语句把 Stream关了。。

                Map xx = req.getParameterMap();
		String postData = Streams.readAndClose(new InputStreamReader(req.getInputStream(), "utf8"));

统统删掉

那么我怎么获取 微信接口回调数据?

你获取来干啥?? Wxs.handle 会处理呀

比如说 关注人的Openid 代参数的二维码 要获取参数。。。

WxInMsg里面有

谢谢,初学,不好意思

还是没搞懂,怎么主动获取微信返回的参数,通过WxHandler中的什么函数监听获取关注事件?

发消息1或者2,测试过没

订阅会调用eventSubscribe,复写它就行啦

测试通过了,这个函数对于微信回调的不同功能,什么地方有帮助文档?还是函数命名有什么规则?

看超类的代码

已经下载源码,参照微信接口返回的XML,应该没问题了,谢谢!晚安,明天继续奋战

添加回复
请先登陆
回到顶部