├── .settings ├── org.eclipse.wst.jsdt.ui.superType.name ├── org.eclipse.wst.validation.prefs ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component └── .jsdtscope ├── src ├── main │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── lib │ │ │ │ └── wx-tools-1.0.1.jar │ │ │ └── web.xml │ │ └── resources │ │ │ └── weather_ico │ │ │ ├── day │ │ │ ├── 00.png │ │ │ ├── 01.png │ │ │ ├── 02.png │ │ │ ├── 03.png │ │ │ ├── 04.png │ │ │ ├── 05.png │ │ │ ├── 06.png │ │ │ ├── 07.png │ │ │ ├── 08.png │ │ │ ├── 09.png │ │ │ ├── 10.png │ │ │ ├── 11.png │ │ │ ├── 12.png │ │ │ ├── 13.png │ │ │ ├── 14.png │ │ │ ├── 15.png │ │ │ ├── 16.png │ │ │ ├── 17.png │ │ │ ├── 18.png │ │ │ ├── 19.png │ │ │ ├── 20.png │ │ │ ├── 21.png │ │ │ ├── 22.png │ │ │ ├── 23.png │ │ │ ├── 24.png │ │ │ ├── 25.png │ │ │ ├── 26.png │ │ │ ├── 27.png │ │ │ ├── 28.png │ │ │ ├── 29.png │ │ │ ├── 30.png │ │ │ ├── 31.png │ │ │ ├── 53.png │ │ │ └── undefined.png │ │ │ └── night │ │ │ ├── 00.png │ │ │ ├── 01.png │ │ │ ├── 02.png │ │ │ ├── 03.png │ │ │ ├── 04.png │ │ │ ├── 05.png │ │ │ ├── 06.png │ │ │ ├── 07.png │ │ │ ├── 08.png │ │ │ ├── 09.png │ │ │ ├── 10.png │ │ │ ├── 11.png │ │ │ ├── 12.png │ │ │ ├── 13.png │ │ │ ├── 14.png │ │ │ ├── 15.png │ │ │ ├── 16.png │ │ │ ├── 17.png │ │ │ ├── 18.png │ │ │ ├── 19.png │ │ │ ├── 20.png │ │ │ ├── 21.png │ │ │ ├── 22.png │ │ │ ├── 23.png │ │ │ ├── 24.png │ │ │ ├── 25.png │ │ │ ├── 26.png │ │ │ ├── 27.png │ │ │ ├── 28.png │ │ │ ├── 29.png │ │ │ ├── 30.png │ │ │ ├── 31.png │ │ │ └── 53.png │ └── java │ │ └── com │ │ └── soecode │ │ └── xfshxzs │ │ ├── po │ │ ├── movie │ │ │ ├── MovieStoryResult.java │ │ │ ├── MovieCommentResult.java │ │ │ ├── MovieResult.java │ │ │ ├── BaseMovieCountResult.java │ │ │ ├── MovieUser.java │ │ │ ├── MovieComment.java │ │ │ ├── Movie.java │ │ │ ├── MovieStory.java │ │ │ └── MovieDetail.java │ │ ├── one │ │ │ ├── Question.java │ │ │ ├── Article.java │ │ │ ├── Picture.java │ │ │ ├── Music.java │ │ │ └── One.java │ │ ├── express │ │ │ ├── ExpressItem.java │ │ │ └── Express.java │ │ └── weather │ │ │ ├── WeatherItem.java │ │ │ └── Weather.java │ │ ├── matcher │ │ └── ExpressMatcher.java │ │ ├── enums │ │ └── ExpressStateEnum.java │ │ ├── interceptor │ │ └── DemoInterceptor.java │ │ ├── util │ │ ├── EmojiUtil.java │ │ └── HttpUitl.java │ │ ├── init │ │ └── WxInitListener.java │ │ ├── handler │ │ ├── SubscribeEventHandler.java │ │ ├── ExpressMessageHandler.java │ │ ├── MovieMessageHandler.java │ │ ├── OneMessageHandler.java │ │ ├── WeatherMessageHandler.java │ │ └── TextMessageHandler.java │ │ ├── service │ │ ├── ExpressService.java │ │ ├── OneService.java │ │ ├── MovieService.java │ │ └── WeatherService.java │ │ └── servlet │ │ └── WxServlet.java └── test │ └── java │ └── com │ └── soecode │ └── xfshxzs │ └── service │ ├── ExpressServiceTest.java │ ├── OneServiceTest.java │ ├── WeatherServiceTest.java │ └── MovieServiceTest.java ├── .gitattributes ├── README.md ├── .gitignore ├── LICENSE ├── .classpath ├── .project └── pom.xml /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/wx-tools-1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/WEB-INF/lib/wx-tools-1.0.1.jar -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/00.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/01.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/02.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/03.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/04.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/05.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/06.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/07.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/08.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/09.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/10.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/11.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/12.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/13.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/14.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/15.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/16.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/17.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/18.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/19.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/20.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/21.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/22.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/23.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/24.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/25.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/26.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/27.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/28.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/29.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/30.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/31.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/53.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/00.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/01.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/02.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/03.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/04.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/05.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/06.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/07.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/08.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/09.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/10.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/11.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/12.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/13.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/14.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/15.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/16.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/17.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/18.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/19.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/20.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/21.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/22.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/23.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/24.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/25.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/26.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/27.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/28.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/29.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/30.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/31.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/night/53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/night/53.png -------------------------------------------------------------------------------- /src/main/webapp/resources/weather_ico/day/undefined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyifeng1994/xfshxzs/HEAD/src/main/webapp/resources/weather_ico/day/undefined.png -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieStoryResult.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影故事结果实体 5 | */ 6 | public class MovieStoryResult extends BaseMovieCountResult { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieCommentResult.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影评论结果实体 5 | */ 6 | public class MovieCommentResult extends BaseMovieCountResult { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.5 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 关于 2 | 小锋生活小助手是一个JAVA开发的基于爬虫和API实现的查询类微信公众号,功能包括电影资讯,每日福利,小测试,小游戏,查公交,查天气,查快递等等。 3 | 4 | # 博客 5 | https://blog.csdn.net/qq598535550/article/details/52014201 6 | 7 | # 截图 8 | ![](http://img.blog.csdn.net/20160724171659263) 9 | 10 | ![](http://img.blog.csdn.net/20160725104103695) 11 | 12 | # 环境 13 | - jdk 1.8 14 | - tomcat 8.5 15 | 16 | # 依赖 17 | - [wx-tools](https://github.com/antgan/wx-tools) 18 | 19 | ![](https://img-ask.csdn.net/upload/201806/05/1528204838_152827.png) 20 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | xfshxzs 7 | 8 | 9 | WxInitListener 10 | com.soecode.xfshxzs.init.WxInitListener 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/com/soecode/xfshxzs/service/ExpressServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import org.junit.Test; 4 | 5 | import com.soecode.xfshxzs.po.express.Express; 6 | import com.soecode.xfshxzs.service.ExpressService; 7 | 8 | public class ExpressServiceTest { 9 | 10 | ExpressService expressService = new ExpressService(); 11 | 12 | @Test 13 | public void testGetExpressByPostId() { 14 | Express express = expressService.getExpressByPostId("20146073240"); 15 | System.out.println(express); 16 | System.out.println(express.getUrl()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieResult.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 基本电影结果实体 5 | * 6 | * @param 7 | */ 8 | public class MovieResult { 9 | 10 | private int res; 11 | 12 | private T data; 13 | 14 | public int getRes() { 15 | return res; 16 | } 17 | 18 | public void setRes(int res) { 19 | this.res = res; 20 | } 21 | 22 | public T getData() { 23 | return data; 24 | } 25 | 26 | public void setData(T data) { 27 | this.data = data; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "BaseResult [res=" + res + ", data=" + data + "]"; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/soecode/xfshxzs/service/OneServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import org.junit.Test; 4 | 5 | import com.soecode.xfshxzs.po.one.One; 6 | import com.soecode.xfshxzs.service.OneService; 7 | 8 | public class OneServiceTest { 9 | 10 | OneService oneService = new OneService(); 11 | 12 | @Test 13 | public void testGetOne() { 14 | One one = oneService.getOne(); 15 | System.out.println(one.getVol()); 16 | System.out.println(one.getDate()); 17 | System.out.println(one.getPicture()); 18 | System.out.println(one.getArticle()); 19 | System.out.println(one.getQuestion()); 20 | System.out.println(one.getMusic()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/BaseMovieCountResult.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 基本电影含数量结果实体 7 | * 8 | * @param 9 | */ 10 | public class BaseMovieCountResult { 11 | 12 | // 结果数量 13 | private int count; 14 | 15 | // 结果集合 16 | private List data; 17 | 18 | public int getCount() { 19 | return count; 20 | } 21 | 22 | public void setCount(int count) { 23 | this.count = count; 24 | } 25 | 26 | public List getData() { 27 | return data; 28 | } 29 | 30 | public void setData(List data) { 31 | this.data = data; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "BaseMovieCountResult [count=" + count + "]"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/soecode/xfshxzs/service/WeatherServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import org.codehaus.jackson.map.JsonMappingException; 4 | import org.junit.Test; 5 | 6 | import com.soecode.xfshxzs.po.weather.Weather; 7 | 8 | public class WeatherServiceTest { 9 | 10 | WeatherService weatherService = new WeatherService(); 11 | 12 | @Test 13 | public void testGetWeather() throws JsonMappingException { 14 | String cityCode = weatherService.getCityCodeByCityName("珠海"); 15 | Weather weather = weatherService.getWeatherByCityCode(cityCode); 16 | System.out.println(weather); 17 | System.out.println(weather.getToday()); 18 | System.out.println(weather.getForecast()); 19 | System.out.println(weather.getHistory()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/matcher/ExpressMatcher.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.matcher; 2 | 3 | import com.soecode.wxtools.api.WxMessageMatcher; 4 | import com.soecode.wxtools.bean.WxXmlMessage; 5 | import java.util.regex.Pattern; 6 | import java.util.regex.Matcher; 7 | 8 | /** 9 | * 快递单号匹配器 10 | */ 11 | public class ExpressMatcher implements WxMessageMatcher { 12 | 13 | public boolean match(WxXmlMessage message) { 14 | String content = message.getContent(); 15 | Pattern pattern = Pattern.compile("[0-9]*"); 16 | Matcher matcher = pattern.matcher(content); 17 | // 如果是数字且长度不小于10位则匹配 18 | if (matcher.matches() && content.length() >= 10) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/one/Question.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.one; 2 | 3 | /** 4 | * 问答实体 5 | */ 6 | public class Question { 7 | 8 | // 问答ID 9 | private String id; 10 | 11 | // 问题 12 | private String title; 13 | 14 | // WEB地址 15 | private String web_url; 16 | 17 | public String getId() { 18 | return id; 19 | } 20 | 21 | public void setId(String id) { 22 | this.id = id; 23 | } 24 | 25 | public String getTitle() { 26 | return title; 27 | } 28 | 29 | public void setTitle(String title) { 30 | this.title = title; 31 | } 32 | 33 | public String getWeb_url() { 34 | return web_url; 35 | } 36 | 37 | public void setWeb_url(String web_url) { 38 | this.web_url = web_url; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Question [id=" + id + ", title=" + title + ", web_url=" + web_url + "]"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/enums/ExpressStateEnum.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.enums; 2 | 3 | /** 4 | * 物流状态枚举 5 | */ 6 | public enum ExpressStateEnum { 7 | 8 | ON(0, "在途"), PULL(1, "揽件"), DOUBT(2, "疑难"), SIGN(3, "签收"), RETURN_SIGN(4, "退签"), DELIVER(5, "派件"), SEND_BACK(6, 9 | "退回"); 10 | 11 | // 状态码 12 | private int state; 13 | 14 | // 状态码信息 15 | private String stateInfo; 16 | 17 | private ExpressStateEnum(int state, String stateInfo) { 18 | this.state = state; 19 | this.stateInfo = stateInfo; 20 | } 21 | 22 | public int getState() { 23 | return state; 24 | } 25 | 26 | public String getStateInfo() { 27 | return stateInfo; 28 | } 29 | 30 | public static ExpressStateEnum stateOf(int index) { 31 | for (ExpressStateEnum state : values()) { 32 | if (state.getState() == index) { 33 | return state; 34 | } 35 | } 36 | return null; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/interceptor/DemoInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.interceptor; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageInterceptor; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.exception.WxErrorException; 9 | 10 | /** 11 | * 拦截器,可以做身份验证,权限验证等操作 12 | */ 13 | public class DemoInterceptor implements WxMessageInterceptor { 14 | public boolean intercept(WxXmlMessage wxMessage, Map context, WxService wxService) 15 | throws WxErrorException { 16 | // 可以使用wxService的微信API方法 17 | // 可以在Handler和Interceptor传递消息,使用context上下文 18 | // 可以实现自己的业务逻辑 19 | 20 | // 这里就不编写验证关注三天以上的用户了 21 | if (1 == 1) {/* 用户关注时长大于3天 */ 22 | return true; 23 | } 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/express/ExpressItem.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.express; 2 | 3 | /** 4 | * 物流跟踪项 5 | */ 6 | public class ExpressItem { 7 | 8 | //时间 9 | private String time; 10 | 11 | //内容 12 | private String context; 13 | 14 | private String ftime; 15 | 16 | public String getTime() { 17 | return time; 18 | } 19 | 20 | public void setTime(String time) { 21 | this.time = time; 22 | } 23 | 24 | public String getContext() { 25 | return context; 26 | } 27 | 28 | public void setContext(String context) { 29 | this.context = context; 30 | } 31 | 32 | public String getFtime() { 33 | return ftime; 34 | } 35 | 36 | public void setFtime(String ftime) { 37 | this.ftime = ftime; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "ExpressItem [time=" + time + ", context=" + context + ", ftime=" + ftime + "]"; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieUser.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影用户实体 5 | */ 6 | public class MovieUser { 7 | 8 | // 用户ID 9 | private String user_id; 10 | 11 | // 用户名 12 | private String user_name; 13 | 14 | // 头像URL 15 | private String web_url; 16 | 17 | public String getUser_id() { 18 | return user_id; 19 | } 20 | 21 | public void setUser_id(String user_id) { 22 | this.user_id = user_id; 23 | } 24 | 25 | public String getUser_name() { 26 | return user_name; 27 | } 28 | 29 | public void setUser_name(String user_name) { 30 | this.user_name = user_name; 31 | } 32 | 33 | public String getWeb_url() { 34 | return web_url; 35 | } 36 | 37 | public void setWeb_url(String web_url) { 38 | this.web_url = web_url; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "MovieUser [user_id=" + user_id + ", user_name=" + user_name + ", web_url=" + web_url + "]"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | #*.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # ========================= 15 | # Operating System Files 16 | # ========================= 17 | 18 | # OSX 19 | # ========================= 20 | 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Thumbnails 26 | ._* 27 | 28 | # Files that might appear on external disk 29 | .Spotlight-V100 30 | .Trashes 31 | 32 | # Directories potentially created on remote AFP share 33 | .AppleDB 34 | .AppleDesktop 35 | Network Trash Folder 36 | Temporary Items 37 | .apdisk 38 | 39 | # Windows 40 | # ========================= 41 | 42 | # Windows image file caches 43 | Thumbs.db 44 | ehthumbs.db 45 | 46 | # Folder config file 47 | Desktop.ini 48 | 49 | # Recycle Bin used on file shares 50 | $RECYCLE.BIN/ 51 | 52 | # Windows Installer files 53 | *.cab 54 | *.msi 55 | *.msm 56 | *.msp 57 | 58 | # Windows shortcuts 59 | *.lnk 60 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/one/Article.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.one; 2 | 3 | /** 4 | * 文章实体 5 | */ 6 | public class Article { 7 | 8 | // 文章ID 9 | private String id; 10 | 11 | // 标题 12 | private String title; 13 | 14 | // 作者 15 | private String author; 16 | 17 | // WEB地址 18 | private String web_url; 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getTitle() { 29 | return title; 30 | } 31 | 32 | public void setTitle(String title) { 33 | this.title = title; 34 | } 35 | 36 | public String getAuthor() { 37 | return author; 38 | } 39 | 40 | public void setAuthor(String author) { 41 | this.author = author; 42 | } 43 | 44 | public String getWeb_url() { 45 | return web_url; 46 | } 47 | 48 | public void setWeb_url(String web_url) { 49 | this.web_url = web_url; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Article [id=" + id + ", title=" + title + ", author=" + author + ", web_url=" + web_url + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 李奕锋 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/one/Picture.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.one; 2 | 3 | /** 4 | * 图片实体 5 | */ 6 | public class Picture { 7 | 8 | // 图片ID 9 | private String id; 10 | 11 | // 内容描述 12 | private String content; 13 | 14 | // 图片地址 15 | private String image_url; 16 | 17 | // WEB地址 18 | private String web_url; 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getContent() { 29 | return content; 30 | } 31 | 32 | public void setContent(String content) { 33 | this.content = content; 34 | } 35 | 36 | public String getImage_url() { 37 | return image_url; 38 | } 39 | 40 | public void setImage_url(String image_url) { 41 | this.image_url = image_url; 42 | } 43 | 44 | public String getWeb_url() { 45 | return web_url; 46 | } 47 | 48 | public void setWeb_url(String web_url) { 49 | this.web_url = web_url; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Picture [id=" + id + ", content=" + content + ", image_url=" + image_url + ", web_url=" + web_url + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/util/EmojiUtil.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.util; 2 | 3 | /** 4 | *
 5 |  * Emoji表情工具类
 6 |  * 
 7 |  * {@link http://www.oicqzone.com/tool/emoji/}
 8 |  * 
9 | */ 10 | public class EmojiUtil { 11 | 12 | // 十字架 13 | public static final int CROSS = 0x274C; 14 | 15 | // 右手 16 | public static final int RIGHT_HAND = 0x1F449; 17 | 18 | // 公交 19 | public static final int BUS = 0x1F68C; 20 | 21 | // 天气 22 | public static final int WEATHER = 0x26C5; 23 | 24 | // 货车(快递) 25 | public static final int TRUCK = 0x1F69A; 26 | 27 | // 游戏 28 | public static final int GAME = 0x1F3AE; 29 | 30 | // 笔(测试) 31 | public static final int PENCEIL = 0x270F; 32 | 33 | // 电影 34 | public static final int MOVIE = 0x1F3A5; 35 | 36 | // 阅读 37 | public static final int ARTICLE = 0x1F4D6; 38 | 39 | // 问答 40 | public static final int QUESTION = 0x2753; 41 | 42 | // 音乐 43 | public static final int MUSIC = 0x1F3B5; 44 | 45 | // 猴子(来一发) 46 | public static final int MONKEY = 0x1F648; 47 | 48 | /** 49 | * emoji表情转换(hex -> utf-16) 50 | * 51 | * @param hexEmoji 52 | * @return 53 | */ 54 | public static String emoji(int hexEmoji) { 55 | return String.valueOf(Character.toChars(hexEmoji)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/one/Music.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.one; 2 | 3 | /** 4 | * 音乐实体 5 | */ 6 | public class Music { 7 | 8 | // 音乐ID 9 | private String id; 10 | 11 | // 音乐名称 12 | private String title; 13 | 14 | // 封面URL 15 | private String cover; 16 | 17 | // WEB地址 18 | private String web_url; 19 | 20 | // 作者信息 21 | private String author; 22 | 23 | public String getId() { 24 | return id; 25 | } 26 | 27 | public void setId(String id) { 28 | this.id = id; 29 | } 30 | 31 | public String getTitle() { 32 | return title; 33 | } 34 | 35 | public void setTitle(String title) { 36 | this.title = title; 37 | } 38 | 39 | public String getCover() { 40 | return cover; 41 | } 42 | 43 | public void setCover(String cover) { 44 | this.cover = cover; 45 | } 46 | 47 | public String getWeb_url() { 48 | return web_url; 49 | } 50 | 51 | public void setWeb_url(String web_url) { 52 | this.web_url = web_url; 53 | } 54 | 55 | public String getAuthor() { 56 | return author; 57 | } 58 | 59 | public void setAuthor(String author) { 60 | this.author = author; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "Music [id=" + id + ", title=" + title + ", cover=" + cover + ", web_url=" + web_url + ", author=" 66 | + author + "]"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | xfshxzs 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/init/WxInitListener.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.init; 2 | 3 | import java.io.File; 4 | 5 | import javax.servlet.ServletContextEvent; 6 | 7 | import org.apache.commons.logging.impl.ServletContextCleaner; 8 | 9 | import com.soecode.wxtools.api.WxConfigStorage; 10 | import com.soecode.wxtools.api.WxInMemoryConfigStorage; 11 | import com.soecode.wxtools.api.WxService; 12 | import com.soecode.wxtools.api.WxServiceImpl; 13 | 14 | /** 15 | * 初始化配置库和微信API服务 16 | */ 17 | public class WxInitListener extends ServletContextCleaner { 18 | 19 | // 配置库 20 | private WxConfigStorage config = null; 21 | // API Service 22 | private WxService wxService = null; 23 | 24 | public void contextInitialized(ServletContextEvent arg0) { 25 | System.out.println("------实例化config和service----------"); 26 | // 调用默认基于内存的配置库WxInMemoryConfigStorage的getInstance获得实例。注意这里是单例模式 27 | config = WxInMemoryConfigStorage.getInstance(); 28 | // 设置AppId 29 | config.setAppId("***"); 30 | // 设置AppSecret 31 | config.setAppSecret("***"); 32 | // 设置token 33 | config.setToken("***"); 34 | // 设置临时资源文件存放路径 35 | config.setTmpDirFile(new File("C://test")); 36 | // 设置永久资源文件存放路径 37 | config.setMaterialDirFile(new File("C://test")); 38 | // 获得WxService实例,注意这里也是调用getInstance()方法获取唯一的业务对象 39 | wxService = WxServiceImpl.getInstance(); 40 | // 注入配置库 41 | wxService.setWxConfigStorage(config); 42 | } 43 | 44 | public void contextDestroyed(ServletContextEvent arg0) { 45 | // ... 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/SubscribeEventHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageHandler; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.bean.WxXmlOutMessage; 9 | import com.soecode.wxtools.exception.WxErrorException; 10 | import com.soecode.xfshxzs.util.EmojiUtil; 11 | 12 | /** 13 | * 文本消息处理器 14 | */ 15 | public class SubscribeEventHandler implements WxMessageHandler { 16 | 17 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 18 | throws WxErrorException { 19 | StringBuffer sb = new StringBuffer(); 20 | sb.append("欢迎关注小锋生活小助手!\n"); 21 | sb.append("请根据提示回复关键字:\n\n"); 22 | sb.append(EmojiUtil.emoji(EmojiUtil.MOVIE) + "【电影】查看近期电影评分\n"); 23 | sb.append(EmojiUtil.emoji(EmojiUtil.MONKEY) + "【来一发】每天都有福利\n"); 24 | sb.append(EmojiUtil.emoji(EmojiUtil.PENCEIL) + "【测试】查看所有测试\n"); 25 | sb.append(EmojiUtil.emoji(EmojiUtil.GAME) + "【游戏】查看所有游戏\n"); 26 | sb.append(EmojiUtil.emoji(EmojiUtil.BUS) + "【公交】查实时公交地铁图\n"); 27 | sb.append(EmojiUtil.emoji(EmojiUtil.WEATHER) + "【XX天气】查询天气预报\n"); 28 | sb.append(EmojiUtil.emoji(EmojiUtil.TRUCK) + "【快递单号】查询快递信息\n\n"); 29 | sb.append("回复【?】查看主菜单"); 30 | String message = sb.toString(); 31 | return WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 32 | .fromUser(wxMessage.getToUserName()).build(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/one/One.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.one; 2 | 3 | /** 4 | * 一个实体 5 | */ 6 | public class One { 7 | 8 | // VOL编号 9 | private String vol; 10 | 11 | // 日期 12 | private String date; 13 | 14 | // 图片 15 | private Picture picture; 16 | 17 | // 文章 18 | private Article article; 19 | 20 | // 问答 21 | private Question question; 22 | 23 | // 音乐 24 | private Music music; 25 | 26 | public String getVol() { 27 | return vol; 28 | } 29 | 30 | public void setVol(String vol) { 31 | this.vol = vol; 32 | } 33 | 34 | public String getDate() { 35 | return date; 36 | } 37 | 38 | public void setDate(String date) { 39 | this.date = date; 40 | } 41 | 42 | public Picture getPicture() { 43 | return picture; 44 | } 45 | 46 | public void setPicture(Picture picture) { 47 | this.picture = picture; 48 | } 49 | 50 | public Article getArticle() { 51 | return article; 52 | } 53 | 54 | public void setArticle(Article article) { 55 | this.article = article; 56 | } 57 | 58 | public Question getQuestion() { 59 | return question; 60 | } 61 | 62 | public void setQuestion(Question question) { 63 | this.question = question; 64 | } 65 | 66 | public Music getMusic() { 67 | return music; 68 | } 69 | 70 | public void setMusic(Music music) { 71 | this.music = music; 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "One [vol=" + vol + ", date=" + date + ", picture=" + picture + ", article=" + article + ", question=" 77 | + question + ", music=" + music + "]"; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.soecode.xfshxzs 5 | xfshxzs 6 | war 7 | 0.0.1-SNAPSHOT 8 | xfshxzs Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | junit 13 | junit 14 | 4.12 15 | test 16 | 17 | 18 | 19 | 20 | org.apache.httpcomponents 21 | httpclient 22 | 4.3.6 23 | 24 | 25 | org.apache.httpcomponents 26 | httpmime 27 | 4.3.6 28 | 29 | 30 | 31 | org.codehaus.jackson 32 | jackson-mapper-asl 33 | 1.9.13 34 | 35 | 36 | 37 | com.thoughtworks.xstream 38 | xstream 39 | 1.4.7 40 | 41 | 42 | 43 | org.jsoup 44 | jsoup 45 | 1.9.2 46 | 47 | 48 | 49 | commons-io 50 | commons-io 51 | 2.4 52 | 53 | 54 | 55 | xfshxzs 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/test/java/com/soecode/xfshxzs/service/MovieServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | 7 | import com.soecode.xfshxzs.po.movie.Movie; 8 | import com.soecode.xfshxzs.po.movie.MovieCommentResult; 9 | import com.soecode.xfshxzs.po.movie.MovieDetail; 10 | import com.soecode.xfshxzs.po.movie.MovieStoryResult; 11 | import com.soecode.xfshxzs.service.MovieService; 12 | 13 | public class MovieServiceTest { 14 | 15 | MovieService movieService = new MovieService(); 16 | 17 | @Test 18 | public void testGetMovieList() { 19 | List list = movieService.getMovieList(); 20 | for (Movie movie : list) { 21 | System.out.println(movie); 22 | } 23 | } 24 | 25 | @Test 26 | public void testGetMovieDetailById() { 27 | MovieDetail movieDetail = movieService.getMovieDetailById("89"); 28 | System.out.println(movieDetail); 29 | } 30 | 31 | @Test 32 | public void testGetMovieURLById() { 33 | String url = movieService.getMovieURLById("89"); 34 | System.out.println(url); 35 | } 36 | 37 | @Test 38 | public void teetGetFirstMovieStoryById() { 39 | MovieStoryResult storyResult = movieService.getMovieStoryById("first", "89"); 40 | System.out.println(storyResult); 41 | } 42 | 43 | @Test 44 | public void teetGetAllMovieStoryById() { 45 | MovieStoryResult storyResult = movieService.getMovieStoryById("all", "89"); 46 | System.out.println(storyResult); 47 | } 48 | 49 | @Test 50 | public void testGetPraiseMovieCommentById() { 51 | MovieCommentResult commentResult = movieService.getMovieCommentById("praise", "89"); 52 | System.out.println(commentResult); 53 | } 54 | 55 | @Test 56 | public void testGetTimeMovieCommentById() { 57 | MovieCommentResult commentResult = movieService.getMovieCommentById("time", "89"); 58 | System.out.println(commentResult); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/service/ExpressService.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.client.ClientProtocolException; 6 | import org.codehaus.jackson.JsonNode; 7 | import org.codehaus.jackson.map.ObjectMapper; 8 | 9 | import com.soecode.xfshxzs.po.express.Express; 10 | import com.soecode.xfshxzs.util.HttpUitl; 11 | 12 | /** 13 | * 快递业务 14 | * 15 | * {@link https://www.kuaidi100.com/openapi/api_post.shtml} 16 | */ 17 | public class ExpressService { 18 | 19 | // 判断快递公司 20 | private static final String EXPRESS_AUTOCOMNUM_URL = "http://www.kuaidi100.com/autonumber/autoComNum?text=POSTID"; 21 | 22 | // 查询物流信息 23 | private static final String EXPRESS_QUERY_URL = "http://www.kuaidi100.com/query?type=TYPE&postid=POSTID"; 24 | 25 | // 手机版 26 | private static final String EXPRESS_MOBILE_URL = "http://m.kuaidi100.com/index_all.html?type=TYPE&postid=POSTID"; 27 | 28 | /** 29 | * 根据快递单号查询物流信息 30 | * 31 | * @param postId 32 | * @return 33 | */ 34 | public Express getExpressByPostId(String postId) { 35 | Express express = new Express(); 36 | try { 37 | String json = HttpUitl.doGet(EXPRESS_AUTOCOMNUM_URL.replace("POSTID", postId)); 38 | ObjectMapper mapper = new ObjectMapper(); 39 | JsonNode root = mapper.readTree(json); 40 | JsonNode auto = root.path("auto"); 41 | if (!auto.isNull()) { 42 | String comCode = auto.get(0).path("comCode").asText(); 43 | json = HttpUitl.doGet(EXPRESS_QUERY_URL.replace("TYPE", comCode).replace("POSTID", postId)); 44 | mapper = new ObjectMapper(); 45 | express = mapper.readValue(json, Express.class); 46 | express.setUrl(EXPRESS_MOBILE_URL.replace("POSTID", postId)); 47 | } else { 48 | return null; 49 | } 50 | } catch (ClientProtocolException e) { 51 | e.printStackTrace(); 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | } 55 | return express; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/ExpressMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageHandler; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.bean.WxXmlOutMessage; 9 | import com.soecode.wxtools.exception.WxErrorException; 10 | import com.soecode.xfshxzs.enums.ExpressStateEnum; 11 | import com.soecode.xfshxzs.po.express.Express; 12 | import com.soecode.xfshxzs.service.ExpressService; 13 | import com.soecode.xfshxzs.util.EmojiUtil; 14 | 15 | /** 16 | * 快递消息处理器 17 | */ 18 | public class ExpressMessageHandler implements WxMessageHandler { 19 | 20 | ExpressService expressService = new ExpressService(); 21 | 22 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 23 | throws WxErrorException { 24 | String postId = wxMessage.getContent().trim(); 25 | try { 26 | Express express = expressService.getExpressByPostId(postId); 27 | StringBuffer sb = new StringBuffer(); 28 | sb.append("【物流公司】" + express.getCom() + "\n"); 29 | sb.append("【快递单号】" + express.getNu() + "\n"); 30 | sb.append("【状态】" + ExpressStateEnum.stateOf(express.getState()).getStateInfo() + "\n"); 31 | sb.append("【最新物流】" + express.getData().get(0).getContext() + "\n"); 32 | sb.append("【更新时间】" + express.getData().get(0).getTime() + "\n"); 33 | sb.append(EmojiUtil.emoji(EmojiUtil.RIGHT_HAND) + "点击这里查看详细物流信息"); 34 | String message = sb.toString(); 35 | return WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 36 | .fromUser(wxMessage.getToUserName()).build(); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | String message = EmojiUtil.emoji(EmojiUtil.CROSS) + "查询不到订单号为\"" + postId + "\"的物流信息!"; 40 | return WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 41 | .fromUser(wxMessage.getToUserName()).build(); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieComment.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影评论实体 5 | */ 6 | public class MovieComment { 7 | 8 | // 评论ID 9 | private String id; 10 | 11 | // 引用内容 12 | private String quote; 13 | 14 | // 评论内容 15 | private String content; 16 | 17 | // 点赞数 18 | private int praisenum; 19 | 20 | // 发表时间 21 | private String input_date; 22 | 23 | // 评论者 24 | private MovieUser user; 25 | 26 | // 被引用者 27 | private MovieUser touser; 28 | 29 | // 评分 30 | private int score; 31 | 32 | // 类型 33 | private int tyoe; 34 | 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | public void setId(String id) { 40 | this.id = id; 41 | } 42 | 43 | public String getQuote() { 44 | return quote; 45 | } 46 | 47 | public void setQuote(String quote) { 48 | this.quote = quote; 49 | } 50 | 51 | public String getContent() { 52 | return content; 53 | } 54 | 55 | public void setContent(String content) { 56 | this.content = content; 57 | } 58 | 59 | public int getPraisenum() { 60 | return praisenum; 61 | } 62 | 63 | public void setPraisenum(int praisenum) { 64 | this.praisenum = praisenum; 65 | } 66 | 67 | public String getInput_date() { 68 | return input_date; 69 | } 70 | 71 | public void setInput_date(String input_date) { 72 | this.input_date = input_date; 73 | } 74 | 75 | public MovieUser getUser() { 76 | return user; 77 | } 78 | 79 | public void setUser(MovieUser user) { 80 | this.user = user; 81 | } 82 | 83 | public MovieUser getTouser() { 84 | return touser; 85 | } 86 | 87 | public void setTouser(MovieUser touser) { 88 | this.touser = touser; 89 | } 90 | 91 | public int getScore() { 92 | return score; 93 | } 94 | 95 | public void setScore(int score) { 96 | this.score = score; 97 | } 98 | 99 | public int getTyoe() { 100 | return tyoe; 101 | } 102 | 103 | public void setTyoe(int tyoe) { 104 | this.tyoe = tyoe; 105 | } 106 | 107 | @Override 108 | public String toString() { 109 | return "MovieComment [id=" + id + ", quote=" + quote + ", content=" + content + ", praisenum=" + praisenum 110 | + ", input_date=" + input_date + ", user=" + user + ", touser=" + touser + ", score=" + score 111 | + ", tyoe=" + tyoe + "]"; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/weather/WeatherItem.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.weather; 2 | 3 | /** 4 | * 天气项 5 | */ 6 | public class WeatherItem { 7 | 8 | // 天日期 9 | private String date; 10 | 11 | // 今日星期 12 | private String week; 13 | 14 | // 当前温度 15 | private String curTemp; 16 | 17 | // pm值 18 | private int aqi; 19 | 20 | // 风向 21 | private String fengxiang; 22 | 23 | // 风力 24 | private String fengli; 25 | 26 | // 最高温度 27 | private String hightemp; 28 | 29 | // 最低温度 30 | private String lowtemp; 31 | 32 | // 天气状态 33 | private String type; 34 | 35 | public String getDate() { 36 | return date; 37 | } 38 | 39 | public void setDate(String date) { 40 | this.date = date; 41 | } 42 | 43 | public String getWeek() { 44 | return week; 45 | } 46 | 47 | public void setWeek(String week) { 48 | this.week = week; 49 | } 50 | 51 | public String getCurTemp() { 52 | return curTemp; 53 | } 54 | 55 | public void setCurTemp(String curTemp) { 56 | this.curTemp = curTemp; 57 | } 58 | 59 | public int getAqi() { 60 | return aqi; 61 | } 62 | 63 | public void setAqi(int aqi) { 64 | this.aqi = aqi; 65 | } 66 | 67 | public String getFengxiang() { 68 | return fengxiang; 69 | } 70 | 71 | public void setFengxiang(String fengxiang) { 72 | this.fengxiang = fengxiang; 73 | } 74 | 75 | public String getFengli() { 76 | return fengli; 77 | } 78 | 79 | public void setFengli(String fengli) { 80 | this.fengli = fengli; 81 | } 82 | 83 | public String getHightemp() { 84 | return hightemp; 85 | } 86 | 87 | public void setHightemp(String hightemp) { 88 | this.hightemp = hightemp; 89 | } 90 | 91 | public String getLowtemp() { 92 | return lowtemp; 93 | } 94 | 95 | public void setLowtemp(String lowtemp) { 96 | this.lowtemp = lowtemp; 97 | } 98 | 99 | public String getType() { 100 | return type; 101 | } 102 | 103 | public void setType(String type) { 104 | this.type = type; 105 | } 106 | 107 | @Override 108 | public String toString() { 109 | return "WeatherItem [date=" + date + ", week=" + week + ", curTemp=" + curTemp + ", aqi=" + aqi + ", fengxiang=" 110 | + fengxiang + ", fengli=" + fengli + ", hightemp=" + hightemp + ", lowtemp=" + lowtemp + ", type=" 111 | + type + "]"; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/weather/Weather.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.weather; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 天气实体 7 | */ 8 | public class Weather { 9 | 10 | // 城市名称 11 | private String city; 12 | 13 | // 城市ID 14 | private String cityid; 15 | 16 | // 今天天气 17 | private WeatherItem today; 18 | 19 | // 未来天气 20 | private List forecast; 21 | 22 | // 历史天气 23 | private List history; 24 | 25 | // 首页URL 26 | private String webUrl; 27 | 28 | // 逐小时URL 29 | private String hoursUrl; 30 | 31 | // 未来15天URL 32 | private String daysUrl; 33 | 34 | public String getCity() { 35 | return city; 36 | } 37 | 38 | public void setCity(String city) { 39 | this.city = city; 40 | } 41 | 42 | public String getCityid() { 43 | return cityid; 44 | } 45 | 46 | public void setCityid(String cityid) { 47 | this.cityid = cityid; 48 | } 49 | 50 | public WeatherItem getToday() { 51 | return today; 52 | } 53 | 54 | public void setToday(WeatherItem today) { 55 | this.today = today; 56 | } 57 | 58 | public List getForecast() { 59 | return forecast; 60 | } 61 | 62 | public void setForecast(List forecast) { 63 | this.forecast = forecast; 64 | } 65 | 66 | public List getHistory() { 67 | return history; 68 | } 69 | 70 | public void setHistory(List history) { 71 | this.history = history; 72 | } 73 | 74 | public String getWebUrl() { 75 | return webUrl; 76 | } 77 | 78 | public void setWebUrl(String webUrl) { 79 | this.webUrl = webUrl; 80 | } 81 | 82 | public String getHoursUrl() { 83 | return hoursUrl; 84 | } 85 | 86 | public void setHoursUrl(String hoursUrl) { 87 | this.hoursUrl = hoursUrl; 88 | } 89 | 90 | public String getDaysUrl() { 91 | return daysUrl; 92 | } 93 | 94 | public void setDaysUrl(String daysUrl) { 95 | this.daysUrl = daysUrl; 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | return "Weather [city=" + city + ", cityid=" + cityid + ", today=" + today + ", forecast=" + forecast 101 | + ", history=" + history + ", webUrl=" + webUrl + ", hoursUrl=" + hoursUrl + ", daysUrl=" + daysUrl 102 | + ", getCity()=" + getCity() + ", getCityid()=" + getCityid() + ", getToday()=" + getToday() 103 | + ", getForecast()=" + getForecast() + ", getHistory()=" + getHistory() + ", getClass()=" + getClass() 104 | + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]"; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/Movie.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影实体 5 | */ 6 | public class Movie { 7 | 8 | // 电影ID 9 | private String id; 10 | 11 | // 电影名 12 | private String title; 13 | 14 | private String verse; 15 | 16 | private String verse_en; 17 | 18 | // 评分 19 | private int score; 20 | 21 | private int revisedscore; 22 | 23 | private String releasetime; 24 | 25 | private String scoretime; 26 | 27 | // 首页封面URL 28 | private String cover; 29 | 30 | private String servertime; 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | public void setId(String id) { 37 | this.id = id; 38 | } 39 | 40 | public String getTitle() { 41 | return title; 42 | } 43 | 44 | public void setTitle(String title) { 45 | this.title = title; 46 | } 47 | 48 | public String getVerse() { 49 | return verse; 50 | } 51 | 52 | public void setVerse(String verse) { 53 | this.verse = verse; 54 | } 55 | 56 | public String getVerse_en() { 57 | return verse_en; 58 | } 59 | 60 | public void setVerse_en(String verse_en) { 61 | this.verse_en = verse_en; 62 | } 63 | 64 | public int getScore() { 65 | return score; 66 | } 67 | 68 | public void setScore(int score) { 69 | this.score = score; 70 | } 71 | 72 | public int getRevisedscore() { 73 | return revisedscore; 74 | } 75 | 76 | public void setRevisedscore(int revisedscore) { 77 | this.revisedscore = revisedscore; 78 | } 79 | 80 | public String getReleasetime() { 81 | return releasetime; 82 | } 83 | 84 | public void setReleasetime(String releasetime) { 85 | this.releasetime = releasetime; 86 | } 87 | 88 | public String getScoretime() { 89 | return scoretime; 90 | } 91 | 92 | public void setScoretime(String scoretime) { 93 | this.scoretime = scoretime; 94 | } 95 | 96 | public String getCover() { 97 | return cover; 98 | } 99 | 100 | public void setCover(String cover) { 101 | this.cover = cover; 102 | } 103 | 104 | public String getServertime() { 105 | return servertime; 106 | } 107 | 108 | public void setServertime(String servertime) { 109 | this.servertime = servertime; 110 | } 111 | 112 | @Override 113 | public String toString() { 114 | return "Movie [id=" + id + ", title=" + title + ", verse=" + verse + ", verse_en=" + verse_en + ", score=" 115 | + score + ", revisedscore=" + revisedscore + ", releasetime=" + releasetime + ", scoretime=" + scoretime 116 | + ", cover=" + cover + ", servertime=" + servertime + "]"; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieStory.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | /** 4 | * 电影故事实体 5 | */ 6 | public class MovieStory { 7 | 8 | // 故事ID 9 | private String id; 10 | 11 | // 电影ID 12 | private String movie_id; 13 | 14 | // 标题 15 | private String title; 16 | 17 | // 内容 18 | private String content; 19 | 20 | // 用户ID 21 | private String user_id; 22 | 23 | private int sort; 24 | 25 | // 点赞数 26 | private int praisenum; 27 | 28 | // 最后更新时间 29 | private String input_date; 30 | 31 | private int story_type; 32 | 33 | // 用户 34 | private MovieUser user; 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id; 42 | } 43 | 44 | public String getMovie_id() { 45 | return movie_id; 46 | } 47 | 48 | public void setMovie_id(String movie_id) { 49 | this.movie_id = movie_id; 50 | } 51 | 52 | public String getTitle() { 53 | return title; 54 | } 55 | 56 | public void setTitle(String title) { 57 | this.title = title; 58 | } 59 | 60 | public String getContent() { 61 | return content; 62 | } 63 | 64 | public void setContent(String content) { 65 | this.content = content; 66 | } 67 | 68 | public String getUser_id() { 69 | return user_id; 70 | } 71 | 72 | public void setUser_id(String user_id) { 73 | this.user_id = user_id; 74 | } 75 | 76 | public int getSort() { 77 | return sort; 78 | } 79 | 80 | public void setSort(int sort) { 81 | this.sort = sort; 82 | } 83 | 84 | public int getPraisenum() { 85 | return praisenum; 86 | } 87 | 88 | public void setPraisenum(int praisenum) { 89 | this.praisenum = praisenum; 90 | } 91 | 92 | public String getInput_date() { 93 | return input_date; 94 | } 95 | 96 | public void setInput_date(String input_date) { 97 | this.input_date = input_date; 98 | } 99 | 100 | public int getStory_type() { 101 | return story_type; 102 | } 103 | 104 | public void setStory_type(int story_type) { 105 | this.story_type = story_type; 106 | } 107 | 108 | public MovieUser getUser() { 109 | return user; 110 | } 111 | 112 | public void setUser(MovieUser user) { 113 | this.user = user; 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return "MovieStory [id=" + id + ", movie_id=" + movie_id + ", title=" + title + ", content=" + content 119 | + ", user_id=" + user_id + ", sort=" + sort + ", praisenum=" + praisenum + ", input_date=" + input_date 120 | + ", story_type=" + story_type + ", user=" + user + "]"; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/express/Express.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.express; 2 | 3 | import java.util.List; 4 | 5 | import com.soecode.xfshxzs.enums.ExpressStateEnum; 6 | 7 | /** 8 | * 物流信息实体 9 | */ 10 | public class Express { 11 | 12 | // 状态码 13 | private int status; 14 | 15 | // 状态码信息 16 | private String message; 17 | 18 | private int ischeck; 19 | 20 | // 快递公司代码 21 | private String com; 22 | 23 | // 快递单号 24 | private String nu; 25 | 26 | private String condition; 27 | 28 | /** 29 | *
 30 | 	 * 快递单状态
 31 | 	 * 
 32 | 	 * 0:在途,即货物处于运输过程中
 33 | 	 * 1:揽件,货物已由快递公司揽收并且产生了第一条跟踪信息
 34 | 	 * 2:疑难,货物寄送过程出了问题
 35 | 	 * 3:签收,收件人已签收
 36 | 	 * 4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收
 37 | 	 * 5:派件,即快递正在进行同城派件
 38 | 	 * 6:退回,货物正处于退回发件人的途中
 39 | 	 * 
 40 | 	 * 订单状态枚举 {@link ExpressStateEnum}
 41 | 	 * 
42 | * 43 | */ 44 | private int state; 45 | 46 | // 物流跟踪项 47 | private List data; 48 | 49 | // WEB地址 50 | private String url; 51 | 52 | public int getStatus() { 53 | return status; 54 | } 55 | 56 | public void setStatus(int status) { 57 | this.status = status; 58 | } 59 | 60 | public String getMessage() { 61 | return message; 62 | } 63 | 64 | public void setMessage(String message) { 65 | this.message = message; 66 | } 67 | 68 | public int getIscheck() { 69 | return ischeck; 70 | } 71 | 72 | public void setIscheck(int ischeck) { 73 | this.ischeck = ischeck; 74 | } 75 | 76 | public String getCom() { 77 | return com; 78 | } 79 | 80 | public void setCom(String com) { 81 | this.com = com; 82 | } 83 | 84 | public String getNu() { 85 | return nu; 86 | } 87 | 88 | public void setNu(String nu) { 89 | this.nu = nu; 90 | } 91 | 92 | public String getCondition() { 93 | return condition; 94 | } 95 | 96 | public void setCondition(String condition) { 97 | this.condition = condition; 98 | } 99 | 100 | public int getState() { 101 | return state; 102 | } 103 | 104 | public void setState(int state) { 105 | this.state = state; 106 | } 107 | 108 | public List getData() { 109 | return data; 110 | } 111 | 112 | public void setData(List data) { 113 | this.data = data; 114 | } 115 | 116 | public String getUrl() { 117 | return url; 118 | } 119 | 120 | public void setUrl(String url) { 121 | this.url = url; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return "Express [status=" + status + ", message=" + message + ", ischeck=" + ischeck + ", com=" + com + ", nu=" 127 | + nu + ", condition=" + condition + ", state=" + state + ", data=" + data + ", url=" + url + "]"; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/MovieMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.soecode.wxtools.api.WxMessageHandler; 7 | import com.soecode.wxtools.api.WxService; 8 | import com.soecode.wxtools.bean.WxXmlMessage; 9 | import com.soecode.wxtools.bean.WxXmlOutMessage; 10 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage.Item; 11 | import com.soecode.wxtools.bean.outxmlbuilder.NewsBuilder; 12 | import com.soecode.wxtools.exception.WxErrorException; 13 | import com.soecode.xfshxzs.po.movie.Movie; 14 | import com.soecode.xfshxzs.po.movie.MovieDetail; 15 | import com.soecode.xfshxzs.service.MovieService; 16 | 17 | /** 18 | * 电影消息处理器 19 | */ 20 | public class MovieMessageHandler implements WxMessageHandler { 21 | 22 | private MovieService movieService = new MovieService(); 23 | 24 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 25 | throws WxErrorException { 26 | String content = wxMessage.getContent(); 27 | NewsBuilder builder = WxXmlOutMessage.NEWS(); 28 | if ("电影".equals(content)) { 29 | List list = movieService.getMovieList(); 30 | for (int i = 0; i < 7; i++) { 31 | MovieDetail movieDetail = movieService.getMovieDetailById(list.get(i).getId()); 32 | Item item = new Item(); 33 | item.setTitle(movieDetail.getScore() + "分 " + createStarsByScore(movieDetail.getScore()) + " | " 34 | + movieDetail.getTitle()); 35 | item.setPicUrl(movieDetail.getDetailcover()); 36 | item.setUrl(movieDetail.getWeb_url()); 37 | builder.addArticle(item); 38 | } 39 | Item item = new Item(); 40 | item.setTitle("回复【更多】查看更多电影推荐"); 41 | builder.addArticle(item); 42 | } else if ("更多".equals(content)) { 43 | List list = movieService.getMovieList(); 44 | for (int i = 7; i < 15; i++) { 45 | MovieDetail movieDetail = movieService.getMovieDetailById(list.get(i).getId()); 46 | Item item = new Item(); 47 | item.setTitle(movieDetail.getScore() + "分 " + createStarsByScore(movieDetail.getScore()) + " | " 48 | + movieDetail.getTitle()); 49 | item.setPicUrl(movieDetail.getDetailcover()); 50 | item.setUrl(movieDetail.getWeb_url()); 51 | builder.addArticle(item); 52 | } 53 | } 54 | return builder.toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build(); 55 | } 56 | 57 | /** 58 | * 根据分数创建星星 59 | * 60 | * @param score 61 | * @return 62 | */ 63 | private String createStarsByScore(int score) { 64 | String stars = ""; 65 | int solidStarsNum = Math.floorDiv(score + 10, 20); 66 | for (int i = 0; i < solidStarsNum; i++) { 67 | stars += "★"; 68 | } 69 | int hollowStarsNum = 5 - solidStarsNum; 70 | for (int i = 0; i < hollowStarsNum; i++) { 71 | stars += "☆"; 72 | } 73 | return stars; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/OneMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageHandler; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.bean.WxXmlOutMessage; 9 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage.Item; 10 | import com.soecode.wxtools.bean.outxmlbuilder.NewsBuilder; 11 | import com.soecode.wxtools.exception.WxErrorException; 12 | import com.soecode.xfshxzs.po.one.Article; 13 | import com.soecode.xfshxzs.po.one.Music; 14 | import com.soecode.xfshxzs.po.one.One; 15 | import com.soecode.xfshxzs.po.one.Picture; 16 | import com.soecode.xfshxzs.po.one.Question; 17 | import com.soecode.xfshxzs.service.OneService; 18 | 19 | /** 20 | * ONE消息处理器 21 | */ 22 | public class OneMessageHandler implements WxMessageHandler { 23 | 24 | private OneService oneService = new OneService(); 25 | 26 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 27 | throws WxErrorException { 28 | NewsBuilder builder = WxXmlOutMessage.NEWS(); 29 | One one = oneService.getOne(); 30 | // 1.图片 31 | Picture picture = one.getPicture(); 32 | Item item1 = new Item(); 33 | item1.setTitle(one.getVol() + " | " + picture.getContent()); 34 | item1.setPicUrl(picture.getImage_url()); 35 | item1.setUrl(picture.getWeb_url()); 36 | builder.addArticle(item1); 37 | // 2.阅读 38 | Article article = one.getArticle(); 39 | Item item2 = new Item(); 40 | item2.setTitle("阅读 | " + article.getTitle() + " | 作者/" + article.getAuthor()); 41 | item2.setPicUrl("http://www.easyicon.net/api/resizeApi.php?id=1199738&size=72"); 42 | item2.setUrl(article.getWeb_url()); 43 | builder.addArticle(item2); 44 | // 3.问答 45 | Question question = one.getQuestion(); 46 | Item item3 = new Item(); 47 | item3.setTitle("问答 | " + question.getTitle()); 48 | item3.setPicUrl("http://www.easyicon.net/api/resizeApi.php?id=1197806&size=64"); 49 | item3.setUrl(question.getWeb_url()); 50 | builder.addArticle(item3); 51 | // 4.音乐 52 | Music music = one.getMusic(); 53 | Item item4 = new Item(); 54 | item4.setTitle("音乐 | " + music.getTitle() + " | 作者/" + music.getAuthor()); 55 | item4.setPicUrl(music.getCover()); 56 | item4.setUrl(music.getWeb_url()); 57 | builder.addArticle(item4); 58 | // 5.往期 59 | Item item5 = new Item(); 60 | item5.setTitle("更多 | 查看往期内容"); 61 | item5.setPicUrl("http://www.easyicon.net/api/resizeApi.php?id=1137914&size=64"); 62 | item5.setUrl("http://m.wufazhuce.com/index"); 63 | builder.addArticle(item5); 64 | // 6.电影 65 | Item item6 = new Item(); 66 | item6.setTitle("回复【电影】查看近期电影评分"); 67 | item6.setPicUrl("http://www.easyicon.net/api/resizeApi.php?id=1194530&size=72"); 68 | builder.addArticle(item6); 69 | return builder.toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/service/OneService.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.client.ClientProtocolException; 6 | import org.codehaus.jackson.JsonNode; 7 | import org.codehaus.jackson.map.ObjectMapper; 8 | import org.jsoup.Jsoup; 9 | import org.jsoup.nodes.Document; 10 | 11 | import com.soecode.xfshxzs.po.one.Article; 12 | import com.soecode.xfshxzs.po.one.Music; 13 | import com.soecode.xfshxzs.po.one.One; 14 | import com.soecode.xfshxzs.po.one.Picture; 15 | import com.soecode.xfshxzs.po.one.Question; 16 | import com.soecode.xfshxzs.util.HttpUitl; 17 | 18 | /** 19 | * ONE业务(图片、阅读、问答、音乐) 20 | * 21 | * {@link http://m.wufazhuce.com} 22 | */ 23 | public class OneService { 24 | 25 | // ONE首页URL(图片、阅读、问答) 26 | private static final String ONE_URL = "http://m.wufazhuce.com"; 27 | 28 | // 音乐列表URL 29 | private static final String MUSIC_LIST_URL = "http://v3.wufazhuce.com:8000/api/music/idlist/0"; 30 | 31 | // 音乐详细URL 32 | private static final String MUSIC_DETAIL_URL = "http://v3.wufazhuce.com:8000/api/music/detail/ID"; 33 | 34 | public One getOne() { 35 | One one = new One(); 36 | try { 37 | String html = HttpUitl.doGet(ONE_URL); 38 | Document document = Jsoup.parse(html); 39 | 40 | // ONE 41 | String vol = document.select(".month").text().split("\\|")[0].trim(); 42 | String date = document.select(".day").text() + document.select(".month").text().split("\\|")[1]; 43 | one.setVol(vol); 44 | one.setDate(date); 45 | 46 | // 图片 47 | Picture picture = new Picture(); 48 | String picture_imageUrl = document.select(".home-img").attr("style").split("\\(")[1].replace(")", ""); 49 | String picture_content = document.select("#quote").text(); 50 | String pucture_webUrl = document.select(".sentence .div-link").attr("href"); 51 | String picture_id = pucture_webUrl.split("/")[pucture_webUrl.split("/").length - 1]; 52 | picture.setId(picture_id); 53 | picture.setContent(picture_content); 54 | picture.setImage_url(picture_imageUrl); 55 | picture.setWeb_url(pucture_webUrl); 56 | one.setPicture(picture); 57 | 58 | // 阅读 59 | Article article = new Article(); 60 | String article_title = document.select(".article .text-title").text(); 61 | String article_author = document.select(".article .text-author").text().split("/")[1]; 62 | String article_webUlr = document.select(".article .div-link").attr("href"); 63 | String article_id = article_webUlr.split("/")[article_webUlr.split("/").length - 1]; 64 | article.setId(article_id); 65 | article.setTitle(article_title); 66 | article.setAuthor(article_author); 67 | article.setWeb_url(article_webUlr); 68 | one.setArticle(article); 69 | 70 | // 问答 71 | Question question = new Question(); 72 | String question_title = document.select(".question .text-title").text(); 73 | String question_webUrl = document.select(".question .div-link").attr("href"); 74 | String question_id = question_webUrl.split("/")[question_webUrl.split("/").length - 1]; 75 | question.setId(question_id); 76 | question.setTitle(question_title); 77 | question.setWeb_url(question_webUrl); 78 | one.setQuestion(question); 79 | 80 | // 音乐 81 | Music music = new Music(); 82 | String json1 = HttpUitl.doGet(MUSIC_LIST_URL);// 加载音乐ID列表 83 | ObjectMapper mapper = new ObjectMapper(); 84 | JsonNode root1 = mapper.readTree(json1); 85 | String music_id = root1.path("data").get(0).asText();// 获取第一个音乐ID 86 | String json2 = HttpUitl.doGet(MUSIC_DETAIL_URL.replace("ID", music_id));// 加载音乐详细 87 | JsonNode root2 = mapper.readTree(json2); 88 | JsonNode data = root2.path("data"); 89 | music.setId(music_id); 90 | music.setTitle(data.path("title").asText()); 91 | music.setAuthor(data.path("author").path("user_name").asText()); 92 | music.setCover(data.path("cover").asText()); 93 | music.setWeb_url(data.path("web_url").asText()); 94 | one.setMusic(music); 95 | } catch (ClientProtocolException e) { 96 | e.printStackTrace(); 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | } 100 | return one; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/WeatherMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageHandler; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.bean.WxXmlOutMessage; 9 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage.Item; 10 | import com.soecode.wxtools.bean.outxmlbuilder.NewsBuilder; 11 | import com.soecode.wxtools.exception.WxErrorException; 12 | import com.soecode.xfshxzs.po.weather.Weather; 13 | import com.soecode.xfshxzs.po.weather.WeatherItem; 14 | import com.soecode.xfshxzs.service.WeatherService; 15 | import com.soecode.xfshxzs.util.EmojiUtil; 16 | 17 | /** 18 | * 天气消息处理器 19 | */ 20 | public class WeatherMessageHandler implements WxMessageHandler { 21 | 22 | WeatherService weatherService = new WeatherService(); 23 | 24 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 25 | throws WxErrorException { 26 | String cityName = wxMessage.getContent().replace("天气", "").trim(); 27 | try { 28 | String cityCode = weatherService.getCityCodeByCityName(cityName); 29 | Weather weather = weatherService.getWeatherByCityCode(cityCode); 30 | NewsBuilder builder = WxXmlOutMessage.NEWS(); 31 | // 1.今天 32 | Item item1 = new Item(); 33 | WeatherItem today = weather.getToday(); 34 | item1.setTitle(cityName + " " + today.getType() + " 当前" + today.getCurTemp() + " 今日" + today.getLowtemp() 35 | + "~" + today.getHightemp() + " " + today.getFengxiang() + " " + today.getFengli() + " PM" 36 | + today.getAqi()); 37 | item1.setPicUrl(weatherService.getUrlByWeather(today.getType())); 38 | item1.setUrl(weather.getWebUrl()); 39 | builder.addArticle(item1); 40 | // 2.逐小时 41 | Item item2 = new Item(); 42 | item2.setTitle("查看逐小时天气预报"); 43 | item2.setUrl(weather.getHoursUrl()); 44 | builder.addArticle(item2); 45 | // 3.明天 46 | Item item3 = new Item(); 47 | WeatherItem tomorrow = weather.getForecast().get(0); 48 | item3.setTitle("【明天】" + tomorrow.getType() + " " + tomorrow.getLowtemp() + "~" + tomorrow.getHightemp() 49 | + " " + tomorrow.getFengxiang() + " " + tomorrow.getFengli()); 50 | item3.setPicUrl(weatherService.getUrlByWeather(tomorrow.getType())); 51 | builder.addArticle(item3); 52 | // 4.后天 53 | Item item4 = new Item(); 54 | WeatherItem afterTomorrow = weather.getForecast().get(1); 55 | item4.setTitle("【后天】" + afterTomorrow.getType() + " " + afterTomorrow.getLowtemp() + "~" 56 | + afterTomorrow.getHightemp() + " " + afterTomorrow.getFengxiang() + " " 57 | + afterTomorrow.getFengli()); 58 | item4.setPicUrl(weatherService.getUrlByWeather(afterTomorrow.getType())); 59 | builder.addArticle(item4); 60 | // 5.未来15天 61 | Item item5 = new Item(); 62 | item5.setTitle("查看未来15天天气预报"); 63 | item5.setUrl(weather.getDaysUrl()); 64 | builder.addArticle(item5); 65 | // 6.昨天 66 | Item item6 = new Item(); 67 | WeatherItem yesterday = weather.getHistory().get(weather.getHistory().size() - 1); 68 | item6.setTitle("【昨天】" + yesterday.getType() + " " + yesterday.getLowtemp() + "~" + yesterday.getHightemp() 69 | + " " + yesterday.getFengxiang() + " " + yesterday.getFengli() + " PM" + today.getAqi()); 70 | item6.setPicUrl(weatherService.getUrlByWeather(yesterday.getType())); 71 | builder.addArticle(item6); 72 | return builder.toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build(); 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | String message = EmojiUtil.emoji(EmojiUtil.CROSS) + "查询不到\"" + cityName + "\"地区的天气信息!"; 76 | return WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 77 | .fromUser(wxMessage.getToUserName()).build(); 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/servlet/WxServlet.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.servlet; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.soecode.wxtools.api.WxConfigStorage; 13 | import com.soecode.wxtools.api.WxConsts; 14 | import com.soecode.wxtools.api.WxInMemoryConfigStorage; 15 | import com.soecode.wxtools.api.WxMessageRouter; 16 | import com.soecode.wxtools.api.WxService; 17 | import com.soecode.wxtools.api.WxServiceImpl; 18 | import com.soecode.wxtools.bean.WxXmlMessage; 19 | import com.soecode.wxtools.bean.WxXmlOutMessage; 20 | import com.soecode.wxtools.util.xml.XStreamTransformer; 21 | import com.soecode.xfshxzs.handler.ExpressMessageHandler; 22 | import com.soecode.xfshxzs.handler.MovieMessageHandler; 23 | import com.soecode.xfshxzs.handler.OneMessageHandler; 24 | import com.soecode.xfshxzs.handler.SubscribeEventHandler; 25 | import com.soecode.xfshxzs.handler.TextMessageHandler; 26 | import com.soecode.xfshxzs.handler.WeatherMessageHandler; 27 | import com.soecode.xfshxzs.matcher.ExpressMatcher; 28 | 29 | /** 30 | * 接收微信服务器请求 31 | */ 32 | @WebServlet("/wx") 33 | public class WxServlet extends HttpServlet { 34 | 35 | private static final long serialVersionUID = 1L; 36 | private WxConfigStorage config; 37 | private WxService service; 38 | private WxMessageRouter router; 39 | 40 | public WxServlet() { 41 | config = WxInMemoryConfigStorage.getInstance(); 42 | service = WxServiceImpl.getInstance(); 43 | service.setWxConfigStorage(config); 44 | router = new WxMessageRouter(WxServiceImpl.getInstance()); 45 | } 46 | 47 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 48 | throws ServletException, IOException { 49 | // 验证服务器的有效性 50 | PrintWriter out = response.getWriter(); 51 | String signature = request.getParameter("signature"); 52 | String timestamp = request.getParameter("timestamp"); 53 | String nonce = request.getParameter("nonce"); 54 | String echostr = request.getParameter("echostr"); 55 | if (WxServiceImpl.getInstance().checkSignature(signature, timestamp, nonce, echostr)) { 56 | out.print(echostr); 57 | } 58 | } 59 | 60 | protected void doPost(HttpServletRequest request, HttpServletResponse response) 61 | throws ServletException, IOException { 62 | // 设置编码格式为utf-8,防止中文乱码 63 | request.setCharacterEncoding("utf-8"); 64 | response.setCharacterEncoding("utf-8"); 65 | PrintWriter out = null; 66 | try { 67 | out = response.getWriter(); 68 | WxXmlMessage wx = XStreamTransformer.fromXml(WxXmlMessage.class, request.getInputStream()); 69 | wx.setContent(wx.getContent().trim());// 过滤两边空格 70 | System.out.println("消息:\n " + wx.toString()); 71 | // 订阅事件 72 | router.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_SUBSCRIBE) 73 | .handler(new SubscribeEventHandler()).end(); 74 | // 文本消息 75 | router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).handler(new TextMessageHandler()).next(); 76 | // 电影消息 77 | router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent("电影|更多") 78 | .handler(new MovieMessageHandler()).end(); 79 | // ONE消息 80 | router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent("来一发").handler(new OneMessageHandler()) 81 | .end(); 82 | // 天气消息 83 | router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent("(.+?天气)") 84 | .handler(new WeatherMessageHandler()).end(); 85 | // 快递消息 86 | router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).matcher(new ExpressMatcher()) 87 | .handler(new ExpressMessageHandler()).end(); 88 | WxXmlOutMessage xmlOutMsg = router.route(wx); 89 | if (xmlOutMsg != null) 90 | out.print(xmlOutMsg.toXml()); 91 | } catch (Exception e) { 92 | e.printStackTrace(); 93 | } finally { 94 | out.close(); 95 | } 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/service/MovieService.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.apache.http.client.ClientProtocolException; 8 | import org.codehaus.jackson.JsonNode; 9 | import org.codehaus.jackson.map.ObjectMapper; 10 | 11 | import com.soecode.xfshxzs.po.movie.Movie; 12 | import com.soecode.xfshxzs.po.movie.MovieCommentResult; 13 | import com.soecode.xfshxzs.po.movie.MovieDetail; 14 | import com.soecode.xfshxzs.po.movie.MovieStoryResult; 15 | import com.soecode.xfshxzs.util.HttpUitl; 16 | 17 | /** 18 | * 电影业务 19 | * 20 | * {@link http://m.wufazhuce.com/apps} 一个APP 21 | */ 22 | public class MovieService { 23 | 24 | // 电影列表URL 25 | private static final String MOVIE_LIST_URL = "http://v3.wufazhuce.com:8000/api/movie/list/0"; 26 | 27 | // 电影详情 28 | private static final String MOVIE_DETAIL_URL = "http://v3.wufazhuce.com:8000/api/movie/detail/ID"; 29 | 30 | // 电影故事(首个) 31 | private static final String MOVIE_FIRST_STORY_URL = "http://v3.wufazhuce.com:8000/api/movie/ID/story/1/0"; 32 | 33 | // 全部剧情 34 | private static final String MOVIE_ALL_STORY_URL = "http://v3.wufazhuce.com:8000/api/movie/ID/story/0/0"; 35 | 36 | // 评论列表(热门 点赞) 37 | private static final String MOVIE_PRAISE_COMMENT_URL = "http://v3.wufazhuce.com:8000/api/comment/praise/movie/ID/0"; 38 | 39 | // 全部评论(最新) 40 | private static final String MOVIE_TIME_COMMENT_URL = "http://v3.wufazhuce.com:8000/api/comment/time/movie/ID/0"; 41 | 42 | /** 43 | * 获取电影列表 44 | * 45 | * @return 46 | */ 47 | public List getMovieList() { 48 | List list = new ArrayList(); 49 | try { 50 | String json = HttpUitl.doGet(MOVIE_LIST_URL); 51 | ObjectMapper mapper = new ObjectMapper(); 52 | JsonNode root = mapper.readTree(json); 53 | JsonNode data = root.path("data"); 54 | if (data.isArray()) { 55 | for (JsonNode node : data) { 56 | Movie movie = mapper.readValue(node, Movie.class); 57 | list.add(movie); 58 | } 59 | } 60 | } catch (ClientProtocolException e) { 61 | e.printStackTrace(); 62 | } catch (IOException e) { 63 | e.printStackTrace(); 64 | } 65 | return list; 66 | } 67 | 68 | /** 69 | * 获取电影详细 70 | * 71 | * @param id 72 | * @return 73 | */ 74 | public MovieDetail getMovieDetailById(String id) { 75 | MovieDetail movieDetail = null; 76 | try { 77 | String json = HttpUitl.doGet(MOVIE_DETAIL_URL.replace("ID", id)); 78 | ObjectMapper mapper = new ObjectMapper(); 79 | JsonNode root = mapper.readTree(json); 80 | JsonNode data = root.path("data"); 81 | movieDetail = mapper.readValue(data, MovieDetail.class); 82 | } catch (ClientProtocolException e) { 83 | e.printStackTrace(); 84 | } catch (IOException e) { 85 | e.printStackTrace(); 86 | } 87 | return movieDetail; 88 | } 89 | 90 | /** 91 | * 获取电影URL 92 | * 93 | * @param id 94 | * @return 95 | */ 96 | public String getMovieURLById(String id) { 97 | return getMovieDetailById(id).getWeb_url(); 98 | } 99 | 100 | /** 101 | * 获取电影故事 102 | * 103 | * @param type 104 | * @param id 105 | * @return 106 | */ 107 | public MovieStoryResult getMovieStoryById(String type, String id) { 108 | String url = null; 109 | if ("all".equals(type)) {// 全部 110 | url = MOVIE_ALL_STORY_URL; 111 | } else {// 首个 112 | url = MOVIE_FIRST_STORY_URL; 113 | } 114 | MovieStoryResult movieStoryResult = null; 115 | try { 116 | String json = HttpUitl.doGet(url.replace("ID", id)); 117 | ObjectMapper mapper = new ObjectMapper(); 118 | JsonNode root = mapper.readTree(json); 119 | JsonNode data = root.path("data"); 120 | movieStoryResult = mapper.readValue(data, MovieStoryResult.class); 121 | } catch (ClientProtocolException e) { 122 | e.printStackTrace(); 123 | } catch (IOException e) { 124 | e.printStackTrace(); 125 | } 126 | return movieStoryResult; 127 | } 128 | 129 | /** 130 | * 获取电影评论 131 | * 132 | * @param type 133 | * @param id 134 | * @return 135 | */ 136 | public MovieCommentResult getMovieCommentById(String type, String id) { 137 | String url = null; 138 | if ("time".equals(type)) {// 最新 139 | url = MOVIE_TIME_COMMENT_URL; 140 | } else {// 热门 141 | url = MOVIE_PRAISE_COMMENT_URL; 142 | } 143 | MovieCommentResult movieCommentResult = null; 144 | try { 145 | String json = HttpUitl.doGet(url.replace("ID", id)); 146 | ObjectMapper mapper = new ObjectMapper(); 147 | JsonNode root = mapper.readTree(json); 148 | JsonNode data = root.path("data"); 149 | movieCommentResult = mapper.readValue(data, MovieCommentResult.class); 150 | } catch (ClientProtocolException e) { 151 | e.printStackTrace(); 152 | } catch (IOException e) { 153 | e.printStackTrace(); 154 | } 155 | return movieCommentResult; 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/util/HttpUitl.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.util; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.apache.http.Header; 9 | import org.apache.http.HttpEntity; 10 | import org.apache.http.NameValuePair; 11 | import org.apache.http.client.ClientProtocolException; 12 | import org.apache.http.client.entity.UrlEncodedFormEntity; 13 | import org.apache.http.client.methods.CloseableHttpResponse; 14 | import org.apache.http.client.methods.HttpGet; 15 | import org.apache.http.client.methods.HttpPost; 16 | import org.apache.http.impl.client.CloseableHttpClient; 17 | import org.apache.http.impl.client.HttpClients; 18 | import org.apache.http.message.BasicNameValuePair; 19 | import org.apache.http.util.EntityUtils; 20 | 21 | import com.soecode.wxtools.exception.WxErrorException; 22 | import com.soecode.wxtools.util.http.SimpleGetRequestExecutor; 23 | import com.soecode.wxtools.util.http.SimplePostRequestExecutor; 24 | 25 | /** 26 | * HTTP工具类 27 | */ 28 | public class HttpUitl { 29 | 30 | /** 31 | * 普通GET请求 32 | * 33 | * @param uri 34 | * @return 35 | * @throws IOException 36 | * @throws ClientProtocolException 37 | */ 38 | public static String doGet(String uri) throws ClientProtocolException, IOException { 39 | String html = null; 40 | CloseableHttpClient httpClient = HttpClients.createDefault(); 41 | HttpGet httpGet = new HttpGet(uri); 42 | CloseableHttpResponse response = httpClient.execute(httpGet); 43 | HttpEntity entity = response.getEntity(); 44 | if (entity != null) { 45 | html = EntityUtils.toString(entity); 46 | EntityUtils.consume(entity); 47 | } 48 | httpGet.releaseConnection(); 49 | response.close(); 50 | return html; 51 | } 52 | 53 | /** 54 | * 带参数的GET请求 55 | * 56 | * @param uri 57 | * @param params 58 | * @return 59 | * @throws IOException 60 | * @throws ClientProtocolException 61 | */ 62 | public static String doGet(String uri, Map params) throws ClientProtocolException, IOException { 63 | if (params != null) { 64 | uri += '?'; 65 | for (String key : params.keySet()) { 66 | uri += key + "=" + params.get(key) + "&"; 67 | } 68 | uri = uri.substring(0, uri.length() - 1); 69 | } 70 | String html = null; 71 | CloseableHttpClient httpClient = HttpClients.createDefault(); 72 | HttpGet httpGet = new HttpGet(uri); 73 | CloseableHttpResponse response = httpClient.execute(httpGet); 74 | HttpEntity entity = response.getEntity(); 75 | if (entity != null) { 76 | html = EntityUtils.toString(entity); 77 | EntityUtils.consume(entity); 78 | } 79 | httpGet.releaseConnection(); 80 | response.close(); 81 | return html; 82 | } 83 | 84 | /** 85 | * 带请求头和参数的GET请求 86 | * 87 | * @param uri 88 | * @param headers 89 | * @param params 90 | * @return 91 | * @throws IOException 92 | * @throws ClientProtocolException 93 | */ 94 | public static String doGet(String uri, Map headers, Map params) 95 | throws ClientProtocolException, IOException { 96 | if (params != null) { 97 | uri += '?'; 98 | for (String key : params.keySet()) { 99 | uri += key + "=" + params.get(key) + "&"; 100 | } 101 | uri = uri.substring(0, uri.length() - 1); 102 | } 103 | String html = null; 104 | CloseableHttpClient httpClient = HttpClients.createDefault(); 105 | HttpGet httpGet = new HttpGet(uri); 106 | if (headers != null) { 107 | for (String key : headers.keySet()) { 108 | httpGet.setHeader(key, headers.get(key)); 109 | } 110 | } 111 | CloseableHttpResponse response = httpClient.execute(httpGet); 112 | HttpEntity entity = response.getEntity(); 113 | if (entity != null) { 114 | html = EntityUtils.toString(entity); 115 | EntityUtils.consume(entity); 116 | } 117 | httpGet.releaseConnection(); 118 | response.close(); 119 | return html; 120 | } 121 | 122 | /** 123 | * 普通POST请求 124 | * 125 | * @param uri 126 | * @param params 127 | * @return 128 | * @throws IOException 129 | * @throws ClientProtocolException 130 | */ 131 | public static String doPost(String uri, Map params) throws ClientProtocolException, IOException { 132 | String html = null; 133 | CloseableHttpClient httpClient = HttpClients.createDefault(); 134 | HttpPost httpPost = new HttpPost(uri); 135 | List nvps = new ArrayList(); 136 | for (Map.Entry entry : params.entrySet()) { 137 | nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); 138 | } 139 | httpPost.setEntity(new UrlEncodedFormEntity(nvps)); 140 | CloseableHttpResponse response = httpClient.execute(httpPost); 141 | HttpEntity entity = response.getEntity(); 142 | if (entity != null) { 143 | html = EntityUtils.toString(entity); 144 | EntityUtils.consume(entity); 145 | } 146 | httpPost.releaseConnection(); 147 | response.close(); 148 | return html; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/handler/TextMessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.handler; 2 | 3 | import java.util.Map; 4 | 5 | import com.soecode.wxtools.api.WxMessageHandler; 6 | import com.soecode.wxtools.api.WxService; 7 | import com.soecode.wxtools.bean.WxXmlMessage; 8 | import com.soecode.wxtools.bean.WxXmlOutMessage; 9 | import com.soecode.wxtools.bean.WxXmlOutNewsMessage.Item; 10 | import com.soecode.wxtools.bean.outxmlbuilder.NewsBuilder; 11 | import com.soecode.wxtools.exception.WxErrorException; 12 | import com.soecode.xfshxzs.util.EmojiUtil; 13 | 14 | /** 15 | * 文本消息处理器 16 | */ 17 | public class TextMessageHandler implements WxMessageHandler { 18 | 19 | public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map context, WxService wxService) 20 | throws WxErrorException { 21 | String message = null; 22 | String content = wxMessage.getContent(); 23 | WxXmlOutMessage xmlOutMsg = null; 24 | if ("?".equals(content) || "?".equals(content) || "帮助".equals(content) || "菜单".equals(content)) { 25 | StringBuffer sb = new StringBuffer(); 26 | sb.append("感谢您使用,回复关键字:\n\n"); 27 | sb.append(EmojiUtil.emoji(EmojiUtil.MOVIE) + "【电影】查看近期电影评分\n"); 28 | sb.append(EmojiUtil.emoji(EmojiUtil.MONKEY) + "【来一发】每天都有福利\n"); 29 | sb.append(EmojiUtil.emoji(EmojiUtil.PENCEIL) + "【测试】查看所有测试\n"); 30 | sb.append(EmojiUtil.emoji(EmojiUtil.GAME) + "【游戏】查看所有游戏\n"); 31 | sb.append(EmojiUtil.emoji(EmojiUtil.BUS) + "【公交】查实时公交地铁图\n"); 32 | sb.append(EmojiUtil.emoji(EmojiUtil.WEATHER) + "【XX天气】查询天气预报\n"); 33 | sb.append(EmojiUtil.emoji(EmojiUtil.TRUCK) + "【快递单号】查询快递信息\n\n"); 34 | sb.append("回复【?】查看主菜单"); 35 | message = sb.toString(); 36 | xmlOutMsg = WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 37 | .fromUser(wxMessage.getToUserName()).build(); 38 | } else if ("天气".equals(content)) { 39 | message = "请直接回复【XX天气】,例如:查询珠海天气回复\"珠海天气\""; 40 | xmlOutMsg = WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 41 | .fromUser(wxMessage.getToUserName()).build(); 42 | } else if ("快递".equals(content)) { 43 | message = "请直接回复【快递单号】,例如:查询京东快递回复订单号\"20146073240\",无需输入物流公司"; 44 | xmlOutMsg = WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 45 | .fromUser(wxMessage.getToUserName()).build(); 46 | } 47 | 48 | else if ("测试".equals(content)) { 49 | Item item = new Item(); 50 | item.setTitle("点击进入查看所有测试"); 51 | item.setDescription("来源:小数据"); 52 | item.setPicUrl("http://www.arealme.com/newimg/tn_@2x_health.png"); 53 | item.setUrl("http://cn.arealme.com/?lang=cn"); 54 | xmlOutMsg = WxXmlOutMessage.NEWS().addArticle(item).toUser(wxMessage.getFromUserName()) 55 | .fromUser(wxMessage.getToUserName()).build(); 56 | } else if ("游戏".equals(content)) { 57 | Item item = new Item(); 58 | item.setTitle("点击进入查看所有游戏"); 59 | item.setDescription("来源:二店长的小游戏"); 60 | item.setPicUrl("http://img2.imgtn.bdimg.com/it/u=4036230424,3195861116&fm=21&gp=0.jpg"); 61 | item.setUrl("http://s2.erdianzhang.com/gameList"); 62 | xmlOutMsg = WxXmlOutMessage.NEWS().addArticle(item).toUser(wxMessage.getFromUserName()) 63 | .fromUser(wxMessage.getToUserName()).build(); 64 | } else if ("公交".equals(content)) { 65 | NewsBuilder builder = WxXmlOutMessage.NEWS(); 66 | // 1.珠海公交 67 | Item item1 = new Item(); 68 | item1.setTitle("珠海实时公交查询"); 69 | item1.setPicUrl( 70 | "https://ss1.baidu.com/70cFfyinKgQFm2e88IuM_a/forum/pic/item/4b90f603738da977250355a4b551f8198618e315.jpg"); 71 | item1.setUrl("http://www.zhbuswx.com/busline/BusQuery.html"); 72 | builder.addArticle(item1); 73 | // 2.全国公交 74 | Item item2 = new Item(); 75 | item2.setTitle("全国城市实时公交查询"); 76 | item2.setPicUrl("http://img5.imgtn.bdimg.com/it/u=2035560368,2960572219&fm=21&gp=0.jpg"); 77 | item2.setUrl("http://www.chedaona.cn/route/wap/index"); 78 | builder.addArticle(item2); 79 | // 3.附近公交站点 80 | Item item3 = new Item(); 81 | item3.setTitle("附近公交站查询"); 82 | item3.setPicUrl("http://img5.imgtn.bdimg.com/it/u=2035560368,2960572219&fm=21&gp=0.jpg"); 83 | item3.setUrl("http://www.nwei.com.cn/near.htm"); 84 | builder.addArticle(item3); 85 | // 4.地铁图 86 | Item item4 = new Item(); 87 | item4.setTitle("全国城市地铁图"); 88 | item4.setPicUrl("http://img4.imgtn.bdimg.com/it/u=555051301,1466834025&fm=21&gp=0.jpg"); 89 | item4.setUrl("http://map.baidu.com/mobile/webapp/index/setsubwaycity/force=simple"); 90 | builder.addArticle(item4); 91 | // 5.广州地铁 92 | Item item5 = new Item(); 93 | item5.setTitle("回复【广州地铁】可查看线网图、客流实况、在线购买单程票"); 94 | item5.setPicUrl("https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2214113435,2045471970&fm=58"); 95 | item5.setUrl("http://map.baidu.com/mobile/webapp/subway/show/foo=bar&city=guangzhou/"); 96 | builder.addArticle(item5); 97 | xmlOutMsg = builder.toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build(); 98 | } else if ("广州地铁".equals(content)) { 99 | NewsBuilder builder = WxXmlOutMessage.NEWS(); 100 | // 1.线网图 101 | Item item2 = new Item(); 102 | item2.setTitle("查询广州地铁线网图"); 103 | item2.setPicUrl("http://58.63.71.40/gzmetroWeifuwu/images/newmap.jpg"); 104 | item2.setUrl("http://58.63.71.40/gzmetroWeifuwu/images/newmap.jpg"); 105 | builder.addArticle(item2); 106 | // 2.客流实况 107 | Item item1 = new Item(); 108 | item1.setTitle("查询地铁客流实况"); 109 | item1.setUrl("http://ydyc.gzmtr.cn:13050/?s=wechat"); 110 | builder.addArticle(item1); 111 | // 3.普通单程票 112 | Item item3 = new Item(); 113 | item3.setTitle("购买普通单程票"); 114 | item3.setUrl("http://dzs.gzmtr.cn/wxpay/modules/index.php"); 115 | builder.addArticle(item3); 116 | // 4.APM单程票 117 | Item item4 = new Item(); 118 | item4.setTitle("购买APM单程票"); 119 | item4.setUrl("http://dzs.gzmtr.cn/wxpay/modules/indexapm.php"); 120 | builder.addArticle(item4); 121 | xmlOutMsg = builder.toUser(wxMessage.getFromUserName()).fromUser(wxMessage.getToUserName()).build(); 122 | } else { 123 | message = "\"" + content + "\"是什么鬼,我不懂!\n回复【?】查看帮助菜单"; 124 | xmlOutMsg = WxXmlOutMessage.TEXT().content(message).toUser(wxMessage.getFromUserName()) 125 | .fromUser(wxMessage.getToUserName()).build(); 126 | } 127 | return xmlOutMsg; 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/po/movie/MovieDetail.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.po.movie; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 电影详细结果实体 7 | */ 8 | public class MovieDetail { 9 | 10 | // 电影ID 11 | private String id; 12 | 13 | // 电影名 14 | private String title; 15 | 16 | // 首页封面URL 17 | private String indexcover; 18 | 19 | // 主题封面URL 20 | private String detailcover; 21 | 22 | // 视频URL 23 | private String video; 24 | 25 | private String verse; 26 | 27 | private String verse_en; 28 | 29 | // 评分 30 | private int score; 31 | 32 | private int revisedscore; 33 | 34 | // 用户评分数据 35 | private String review; 36 | 37 | // 关键字;分割 38 | private String keywords; 39 | 40 | private String movie_id; 41 | 42 | // 影片信息(导演、编剧、主演、类型、制片国家/地区) 43 | private String info; 44 | 45 | // 官方情节 46 | private String officialstory; 47 | 48 | // 责任编辑 49 | private String charge_edt; 50 | 51 | // WEB主页URL 52 | private String web_url; 53 | 54 | // 点赞数 55 | private int praisenum; 56 | 57 | private String sort; 58 | 59 | private String releasetime; 60 | 61 | private String scoretime; 62 | 63 | private String maketime; 64 | 65 | // 最后更新时间 66 | private String last_update_date; 67 | 68 | // 阅读数 69 | private String read_num; 70 | 71 | // 官方剧照 72 | private List photo; 73 | 74 | // 分享数 75 | private String sharenum; 76 | 77 | // 评论数 78 | private String commentnum; 79 | 80 | private String servertime; 81 | 82 | public String getId() { 83 | return id; 84 | } 85 | 86 | public void setId(String id) { 87 | this.id = id; 88 | } 89 | 90 | public String getTitle() { 91 | return title; 92 | } 93 | 94 | public void setTitle(String title) { 95 | this.title = title; 96 | } 97 | 98 | public String getIndexcover() { 99 | return indexcover; 100 | } 101 | 102 | public void setIndexcover(String indexcover) { 103 | this.indexcover = indexcover; 104 | } 105 | 106 | public String getDetailcover() { 107 | return detailcover; 108 | } 109 | 110 | public void setDetailcover(String detailcover) { 111 | this.detailcover = detailcover; 112 | } 113 | 114 | public String getVideo() { 115 | return video; 116 | } 117 | 118 | public void setVideo(String video) { 119 | this.video = video; 120 | } 121 | 122 | public String getVerse() { 123 | return verse; 124 | } 125 | 126 | public void setVerse(String verse) { 127 | this.verse = verse; 128 | } 129 | 130 | public String getVerse_en() { 131 | return verse_en; 132 | } 133 | 134 | public void setVerse_en(String verse_en) { 135 | this.verse_en = verse_en; 136 | } 137 | 138 | public int getScore() { 139 | return score; 140 | } 141 | 142 | public void setScore(int score) { 143 | this.score = score; 144 | } 145 | 146 | public int getRevisedscore() { 147 | return revisedscore; 148 | } 149 | 150 | public void setRevisedscore(int revisedscore) { 151 | this.revisedscore = revisedscore; 152 | } 153 | 154 | public String getReview() { 155 | return review; 156 | } 157 | 158 | public void setReview(String review) { 159 | this.review = review; 160 | } 161 | 162 | public String getKeywords() { 163 | return keywords; 164 | } 165 | 166 | public void setKeywords(String keywords) { 167 | this.keywords = keywords; 168 | } 169 | 170 | public String getMovie_id() { 171 | return movie_id; 172 | } 173 | 174 | public void setMovie_id(String movie_id) { 175 | this.movie_id = movie_id; 176 | } 177 | 178 | public String getInfo() { 179 | return info; 180 | } 181 | 182 | public void setInfo(String info) { 183 | this.info = info; 184 | } 185 | 186 | public String getOfficialstory() { 187 | return officialstory; 188 | } 189 | 190 | public void setOfficialstory(String officialstory) { 191 | this.officialstory = officialstory; 192 | } 193 | 194 | public String getCharge_edt() { 195 | return charge_edt; 196 | } 197 | 198 | public void setCharge_edt(String charge_edt) { 199 | this.charge_edt = charge_edt; 200 | } 201 | 202 | public String getWeb_url() { 203 | return web_url; 204 | } 205 | 206 | public void setWeb_url(String web_url) { 207 | this.web_url = web_url; 208 | } 209 | 210 | public int getPraisenum() { 211 | return praisenum; 212 | } 213 | 214 | public void setPraisenum(int praisenum) { 215 | this.praisenum = praisenum; 216 | } 217 | 218 | public String getSort() { 219 | return sort; 220 | } 221 | 222 | public void setSort(String sort) { 223 | this.sort = sort; 224 | } 225 | 226 | public String getReleasetime() { 227 | return releasetime; 228 | } 229 | 230 | public void setReleasetime(String releasetime) { 231 | this.releasetime = releasetime; 232 | } 233 | 234 | public String getScoretime() { 235 | return scoretime; 236 | } 237 | 238 | public void setScoretime(String scoretime) { 239 | this.scoretime = scoretime; 240 | } 241 | 242 | public String getMaketime() { 243 | return maketime; 244 | } 245 | 246 | public void setMaketime(String maketime) { 247 | this.maketime = maketime; 248 | } 249 | 250 | public String getLast_update_date() { 251 | return last_update_date; 252 | } 253 | 254 | public void setLast_update_date(String last_update_date) { 255 | this.last_update_date = last_update_date; 256 | } 257 | 258 | public String getRead_num() { 259 | return read_num; 260 | } 261 | 262 | public void setRead_num(String read_num) { 263 | this.read_num = read_num; 264 | } 265 | 266 | public List getPhoto() { 267 | return photo; 268 | } 269 | 270 | public void setPhoto(List photo) { 271 | this.photo = photo; 272 | } 273 | 274 | public String getSharenum() { 275 | return sharenum; 276 | } 277 | 278 | public void setSharenum(String sharenum) { 279 | this.sharenum = sharenum; 280 | } 281 | 282 | public String getCommentnum() { 283 | return commentnum; 284 | } 285 | 286 | public void setCommentnum(String commentnum) { 287 | this.commentnum = commentnum; 288 | } 289 | 290 | public String getServertime() { 291 | return servertime; 292 | } 293 | 294 | public void setServertime(String servertime) { 295 | this.servertime = servertime; 296 | } 297 | 298 | @Override 299 | public String toString() { 300 | return "MovieDetail [id=" + id + ", title=" + title + ", indexcover=" + indexcover + ", detailcover=" 301 | + detailcover + ", video=" + video + ", verse=" + verse + ", verse_en=" + verse_en + ", score=" + score 302 | + ", revisedscore=" + revisedscore + ", review=" + review + ", keywords=" + keywords + ", movie_id=" 303 | + movie_id + ", info=" + info + ", officialstory=" + officialstory + ", charge_edt=" + charge_edt 304 | + ", web_url=" + web_url + ", praisenum=" + praisenum + ", sort=" + sort + ", releasetime=" 305 | + releasetime + ", scoretime=" + scoretime + ", maketime=" + maketime + ", last_update_date=" 306 | + last_update_date + ", read_num=" + read_num + ", photo=" + photo + ", sharenum=" + sharenum 307 | + ", commentnum=" + commentnum + ", servertime=" + servertime + "]"; 308 | } 309 | 310 | } 311 | -------------------------------------------------------------------------------- /src/main/java/com/soecode/xfshxzs/service/WeatherService.java: -------------------------------------------------------------------------------- 1 | package com.soecode.xfshxzs.service; 2 | 3 | import java.io.IOException; 4 | import java.util.Date; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.apache.http.client.ClientProtocolException; 9 | import org.codehaus.jackson.JsonNode; 10 | import org.codehaus.jackson.map.DeserializationConfig.Feature; 11 | import org.codehaus.jackson.map.JsonMappingException; 12 | import org.codehaus.jackson.map.ObjectMapper; 13 | 14 | import com.soecode.xfshxzs.po.weather.Weather; 15 | import com.soecode.xfshxzs.util.HttpUitl; 16 | 17 | /** 18 | * 天气业务 19 | * 20 | * {@link http://apistore.baidu.com/apiworks/servicedetail/112.html} 21 | */ 22 | public class WeatherService { 23 | 24 | // 项目根目录 25 | private static final String BASEPATH = "http://lyf.soecode.com/xfshxzs"; 26 | 27 | // 百度API钥匙 28 | private static final String APIKEY = "***"; 29 | 30 | // 城市代码查询 31 | private static final String CITY_CODE_URL = "http://apis.baidu.com/apistore/weatherservice/cityinfo"; 32 | 33 | // 天气查询 34 | private static final String WEATHER_URL = "http://apis.baidu.com/apistore/weatherservice/recentweathers"; 35 | 36 | // 中国天气网 37 | private static final String WEATHER_WEB_URL = "http://www.weather.com.cn/weather/CITYCODE.shtml"; 38 | 39 | // 逐小时天气预报 40 | private static final String WEATHER_HOURS_URL = "http://baidu.weather.com.cn/mhours/CITYCODE.shtml"; 41 | 42 | // 未来15天天气预报 43 | private static final String WEATHER_15DAYS_URL = "http://baidu.weather.com.cn/mweather15d/CITYCODE.shtml"; 44 | 45 | /** 46 | * 根据城市名称查询城市代码 47 | * 48 | * @param cityName 49 | * @return 50 | */ 51 | public String getCityCodeByCityName(String cityName) { 52 | String cityCode = null; 53 | try { 54 | Map headers = new HashMap(); 55 | headers.put("apikey", APIKEY); 56 | Map params = new HashMap(); 57 | params.put("cityname", cityName); 58 | String json = HttpUitl.doGet(CITY_CODE_URL, headers, params); 59 | ObjectMapper mapper = new ObjectMapper(); 60 | JsonNode root = mapper.readTree(json); 61 | JsonNode data = root.path("retData"); 62 | cityCode = data.path("cityCode").asText(); 63 | } catch (ClientProtocolException e) { 64 | e.printStackTrace(); 65 | } catch (IOException e) { 66 | e.printStackTrace(); 67 | } 68 | return cityCode; 69 | } 70 | 71 | /** 72 | * 根据城市代码查询天气 73 | * 74 | * @param cityCode 75 | * @return 76 | * @throws JsonMappingException 77 | */ 78 | public Weather getWeatherByCityCode(String cityCode) throws JsonMappingException { 79 | Weather weather = null; 80 | try { 81 | Map headers = new HashMap(); 82 | headers.put("apikey", APIKEY); 83 | Map params = new HashMap(); 84 | params.put("cityid", cityCode); 85 | String json = HttpUitl.doGet(WEATHER_URL, headers, params); 86 | ObjectMapper mapper = new ObjectMapper(); 87 | mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);// 忽略未知属性 88 | JsonNode root = mapper.readTree(json); 89 | JsonNode data = root.path("retData"); 90 | weather = mapper.readValue(data, Weather.class); 91 | weather.setWebUrl(WEATHER_WEB_URL.replace("CITYCODE", cityCode)); 92 | weather.setHoursUrl(WEATHER_HOURS_URL.replace("CITYCODE", cityCode)); 93 | weather.setDaysUrl(WEATHER_15DAYS_URL.replace("CITYCODE", cityCode)); 94 | } catch (ClientProtocolException e) { 95 | e.printStackTrace(); 96 | } catch (IOException e) { 97 | e.printStackTrace(); 98 | } 99 | return weather; 100 | } 101 | 102 | /** 103 | * 根据天气返回图片代码 104 | * 105 | * @param weather 106 | * @return 107 | */ 108 | public static String getImgByWeather(String weather) { 109 | String imgName = "00"; 110 | if ("晴".equals(weather)) { 111 | imgName = "00"; 112 | } else if ("多云".equals(weather)) { 113 | imgName = "01"; 114 | } else if ("阴".equals(weather)) { 115 | imgName = "02"; 116 | } else if ("阵雨".equals(weather)) { 117 | imgName = "03"; 118 | } else if ("雷阵雨".equals(weather)) { 119 | imgName = "04"; 120 | } else if ("雷阵雨伴有冰雹".equals(weather)) { 121 | imgName = "05"; 122 | } else if ("雨夹雪".equals(weather)) { 123 | imgName = "06"; 124 | } else if ("小雨".equals(weather)) { 125 | imgName = "07"; 126 | } else if ("中雨".equals(weather)) { 127 | imgName = "08"; 128 | } else if ("大雨".equals(weather)) { 129 | imgName = "09"; 130 | } else if ("暴雨".equals(weather)) { 131 | imgName = "10"; 132 | } else if ("大暴雨".equals(weather)) { 133 | imgName = "11"; 134 | } else if ("特大暴雨".equals(weather)) { 135 | imgName = "12"; 136 | } else if ("阵雪".equals(weather)) { 137 | imgName = "13"; 138 | } else if ("小雪".equals(weather)) { 139 | imgName = "14"; 140 | } else if ("中雪".equals(weather)) { 141 | imgName = "15"; 142 | } else if ("大雪".equals(weather)) { 143 | imgName = "16"; 144 | } else if ("暴雪".equals(weather)) { 145 | imgName = "17"; 146 | } else if ("雾".equals(weather)) { 147 | imgName = "18"; 148 | } else if ("冻雨".equals(weather)) { 149 | imgName = "19"; 150 | } else if ("沙尘暴".equals(weather)) { 151 | imgName = "20"; 152 | } else if ("小到中雨".equals(weather)) { 153 | imgName = "21"; 154 | } else if ("中到大雨".equals(weather)) { 155 | imgName = "22"; 156 | } else if ("大到暴雨".equals(weather)) { 157 | imgName = "23"; 158 | } else if ("暴雨到大暴雨".equals(weather)) { 159 | imgName = "24"; 160 | } else if ("大暴雨到特大暴雨".equals(weather)) { 161 | imgName = "25"; 162 | } else if ("小到中雪".equals(weather)) { 163 | imgName = "26"; 164 | } else if ("中到大雪".equals(weather)) { 165 | imgName = "27"; 166 | } else if ("大到暴雪".equals(weather)) { 167 | imgName = "28"; 168 | } else if ("浮尘".equals(weather)) { 169 | imgName = "29"; 170 | } else if ("扬沙".equals(weather)) { 171 | imgName = "30"; 172 | } else if ("强沙尘暴".equals(weather)) { 173 | imgName = "31"; 174 | } else if ("霾".equals(weather)) { 175 | imgName = "53"; 176 | } 177 | return imgName + ".png"; 178 | } 179 | 180 | /** 181 | * 根据天气返回图片URL 182 | * 183 | * @param weather 184 | * @return 185 | */ 186 | public String getUrlByWeather(String weather) { 187 | String url = BASEPATH + "/resources/weather_ico"; 188 | Date date = new Date(); 189 | int hours = date.getHours();// 获取当前小时 190 | // 超过6点就算夜晚 191 | if (hours >= 18) {// 夜晚 192 | url += "/night"; 193 | } else {// 白天 194 | url += "/day"; 195 | } 196 | url += "/" + getImgByWeather(weather); 197 | return url; 198 | } 199 | 200 | } 201 | --------------------------------------------------------------------------------