Commit 5b67c4312e676419323d6a24fa0ce54315054429

Authored by landong2015
1 parent 23a3241f1a
Exists in master

新增获取幻灯片和育儿课堂接口

Showing 2 changed files with 81 additions and 0 deletions

mainData/src/main/java/com/lymsh/yimiao/main/data/util/ArticleUtil.java View file @ 5b67c43
  1 +package com.lymsh.yimiao.main.data.util;
  2 +
  3 +import org.apache.commons.httpclient.HttpClient;
  4 +import org.apache.commons.httpclient.methods.GetMethod;
  5 +
  6 +/**
  7 + * Created by Administrator on 2016/5/12 0012.
  8 + */
  9 +public class ArticleUtil {
  10 +
  11 + public static String getArticlesImages() {
  12 + HttpClient client = new HttpClient();
  13 + GetMethod get = new MessageUtil.UTF8GetMethod("http://ams.api.stage.healthbaby.com.cn/v1/imageArticles.action");
  14 + try {
  15 + client.executeMethod(get);
  16 + String result = new String(get.getResponseBodyAsString());
  17 + int statusCode = get.getStatusCode();
  18 + if (statusCode==200){
  19 + return result;
  20 + }
  21 + get.releaseConnection();
  22 + }catch (Exception e){
  23 + e.printStackTrace();
  24 + }
  25 + return null;
  26 + }
  27 +
  28 + public static String getCategoryArticle(){
  29 + HttpClient client = new HttpClient();
  30 + GetMethod get = new MessageUtil.UTF8GetMethod("http://ams.api.stage.healthbaby.com.cn/v1/yiMiaoArticles.action");
  31 + try {
  32 + client.executeMethod(get);
  33 + String result = new String(get.getResponseBodyAsString());
  34 + int statusCode = get.getStatusCode();
  35 + if (statusCode==200){
  36 + return result;
  37 + }
  38 + get.releaseConnection();
  39 + }catch (Exception e){
  40 + e.printStackTrace();
  41 + }
  42 + return null;
  43 + }
  44 +
  45 +
  46 +}
webApi/src/main/java/com/lyms/yimiao/web/controller/v1/ArticleController.java View file @ 5b67c43
  1 +package com.lyms.yimiao.web.controller.v1;
  2 +
  3 +import com.lymsh.mommybaby.basecommon.base.BaseController;
  4 +import com.lymsh.mommybaby.basecommon.base.TokenRequired;
  5 +import com.lymsh.mommybaby.basecommon.util.JsonUtil;
  6 +import com.lymsh.yimiao.main.data.util.ArticleUtil;
  7 +import org.springframework.stereotype.Controller;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestMethod;
  10 +
  11 +import javax.servlet.http.HttpServletResponse;
  12 +
  13 +/**
  14 + * Created by Administrator on 2016/5/12 0012.
  15 + */
  16 +
  17 +@Controller
  18 +@RequestMapping("/v1")
  19 +public class ArticleController extends BaseController{
  20 +
  21 + //幻灯片
  22 + @RequestMapping(value = "/image/slide", method = RequestMethod.GET)
  23 + @TokenRequired
  24 + public void getSlide(HttpServletResponse response){
  25 + writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getArticlesImages()));
  26 + }
  27 +
  28 + //获取育儿课堂
  29 + @RequestMapping(value = "/category/article", method = RequestMethod.GET)
  30 + @TokenRequired
  31 + public void getColumn(HttpServletResponse response){
  32 + writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getCategoryArticle()));
  33 + }
  34 +
  35 +}