Commit 8f30575b5565f1bf015ae89169fff8dbe59a06ad
1 parent
19e11867d9
Exists in
master
修改反馈接口
Showing 2 changed files with 62 additions and 0 deletions
mainData/src/main/java/com/lymsh/yimiao/main/data/util/FeedBackUtil.java
View file @
8f30575
1 | +package com.lymsh.yimiao.main.data.util; | |
2 | + | |
3 | +import org.apache.commons.httpclient.HttpClient; | |
4 | +import org.apache.commons.httpclient.NameValuePair; | |
5 | +import org.apache.commons.httpclient.methods.PostMethod; | |
6 | + | |
7 | +/** | |
8 | + * Created by Administrator on 2016/5/18 0018. | |
9 | + */ | |
10 | +public class FeedBackUtil { | |
11 | + | |
12 | + public static boolean sendFeedBack(String content,String name) { | |
13 | + HttpClient client = new HttpClient(); | |
14 | + PostMethod post = new MessageUtil.UTF8PostMethod("http://ams.api.stage.healthbaby.com.cn/v1/yimiao/feedbacks.action"); | |
15 | + NameValuePair[] data = { | |
16 | + new NameValuePair("content", content), | |
17 | + new NameValuePair("name", name) | |
18 | + }; | |
19 | + | |
20 | + post.setRequestBody(data); | |
21 | + try { | |
22 | + client.executeMethod(post); | |
23 | + String result = new String(post.getResponseBodyAsString()); | |
24 | +// int statusCode = post.getStatusCode(); | |
25 | + if (result != null && result.indexOf("成功") > 0){ | |
26 | + return true; | |
27 | + } | |
28 | + post.releaseConnection(); | |
29 | + }catch (Exception e){ | |
30 | + e.printStackTrace(); | |
31 | + } | |
32 | + return false; | |
33 | + } | |
34 | + | |
35 | +} |
webApi/src/main/java/com/lyms/yimiao/web/controller/v1/FeedbackController.java
View file @
8f30575
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | import com.lymsh.yimiao.main.data.model.YmUsers; |
12 | 12 | import com.lymsh.yimiao.main.data.service.YmFeedBacksService; |
13 | 13 | import com.lymsh.yimiao.main.data.service.YmUsersService; |
14 | +import com.lymsh.yimiao.main.data.util.FeedBackUtil; | |
14 | 15 | import com.lymsh.yimiao.main.data.util.JsonUtil; |
15 | 16 | import com.lymsh.yimiao.main.data.util.LoginContext; |
16 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -78,6 +79,32 @@ |
78 | 79 | result.put("errorcode", ConstantInterface.SYSTEM_ERROR); |
79 | 80 | result.put("errormsg", "userId为空."); |
80 | 81 | writeJson(httpServletResponse, JsonUtil.obj2JsonString(result)); |
82 | + } | |
83 | + } | |
84 | + | |
85 | + //反馈 | |
86 | + @RequestMapping(value = "/ams/feedbacks", method = RequestMethod.POST) | |
87 | + @TokenRequired | |
88 | + public void sendFeedBack(HttpServletResponse response, | |
89 | + HttpServletRequest request, | |
90 | + @RequestParam("content") String content) { | |
91 | + if (StringUtils.isEmpty(content)) { | |
92 | + ResultUtils.buildParameterErrorResultAndWrite(response); | |
93 | + return; | |
94 | + } | |
95 | + | |
96 | + LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); | |
97 | + Integer userId = loginContext.getId(); | |
98 | + if (null != userId) { | |
99 | + YmUsers users = usersService.getYmUsers(userId); | |
100 | + boolean result = FeedBackUtil.sendFeedBack(content,users.getNickname()==null ? users.getPhone() : users.getNickname()); | |
101 | + if (result){ | |
102 | + ResultUtils.buildSuccessResultAndWrite(response); | |
103 | + }else { | |
104 | + ResultUtils.buildParameterErrorResultAndWrite(response,"发送反馈信息失败"); | |
105 | + } | |
106 | + }else { | |
107 | + ResultUtils.buildParameterErrorResultAndWrite(response,"登录异常"); | |
81 | 108 | } |
82 | 109 | } |
83 | 110 |