|
版本: |
|
小版本号: |
|
|
|
数据库: |
MySQL |
服务器操作系统: |
Windows |
应用服务器: |
Tomcat |
客户端操作系统: |
Windows 8 |
浏览器: |
Chrome |
|
|
本帖最后由 davidhuang 于 2017-4-22 11:48 编辑
这是我后台处理微信公众号上传图片的代码,
// 拦截图片消息
private void addImageRouter() {
WxMpMessageHandler handler = new WxMpMessageHandler() {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
System.out.println("响应图片接受指令********************");
//String mediaId = context.get("MediaId").toString();
String mediaId = wxMessage.getMediaId();
System.out.println("mediaId=" + mediaId );
//取得mediaId后,可以立刻去下载,也可以先插入一条获取图片的表记录,然后定时去取
try{
File imageFile = wxMpService.mediaDownload(mediaId);
System.out.println(imageFile.getPath());
}catch(Exception ex1){
throw new RuntimeException(ex1.getMessage());
}
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("图片上传成功。").fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName()).build();
return m;
}
};
//wxMpMessageRouter.rule().async(false).content("test").handler(handler).end();
wxMpMessageRouter.rule().async(false).msgType(WxConsts.CUSTOM_MSG_IMAGE).handler(handler).end();
}
接收微信公众号上传的图片时候,后台报错如下
四月 22, 2017 11:42:30 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet weixin default threw exception
java.lang.ArrayIndexOutOfBoundsException: 0
at me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor.getFileName(MediaDownloadRequestExecutor.java:69)
at me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor.execute(MediaDownloadRequestExecutor.java:57)
at me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor.execute(MediaDownloadRequestExecutor.java:27)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngme.chanjar.weixin.mp.api.WxMpServiceImpl.executeInternal(WxMpServiceImpl.java:578)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngme.chanjar.weixin.mp.api.WxMpServiceImpl.execute(WxMpServiceImpl.java:548)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngme.chanjar.weixin.mp.api.WxMpServiceImpl.mediaDownload(WxMpServiceImpl.java:243)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngcom.justep.weixin.mp.WxMpServiceInstance$3.handle(WxMpServiceInstance.java:161)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngme.chanjar.weixin.mp.api.WxMpMessageRouterRule.service(WxMpMessageRouterRule.java:252)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngme.chanjar.weixin.mp.api.WxMpMessageRouter.route(WxMpMessageRouter.java:171)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngcom.justep.weixin.mp.WxMpServiceInstance.doResponse(WxMpServiceInstance.java:222)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngcom.justep.weixin.mp.DefaultServlet.service(DefaultServlet.java:17)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at file:///C:\Users\hyj\AppData\Local\Temp\%W@GJ$ACOF(TYDYECOKVDYB.pngorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
|
|