WxFeedbackService.java
5.44 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package com.thinkgem.jeesite.modules.wechat.service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.service.ServiceException;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.modules.wechat.entity.WxFeedback;
import com.thinkgem.jeesite.modules.wechat.entity.WxOrder;
import net.sf.json.JSONObject;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.wechat.dao.WxFeedbackDao;
/**
* 反馈意见Service
* @author lzj
* @version 2020-03-19
*/
@Service
@Transactional(readOnly = true)
public class WxFeedbackService extends CrudService<WxFeedbackDao, WxFeedback> {
public WxFeedback get(String id) {
return super.get(id);
}
public List<WxFeedback> findList(WxFeedback wxFeedback) {
return super.findList(wxFeedback);
}
public Page<WxFeedback> findPage(Page<WxFeedback> page, WxFeedback wxFeedback) {
return super.findPage(page, wxFeedback);
}
@Transactional(readOnly = false)
public void save(WxFeedback wxFeedback) {
super.save(wxFeedback);
}
@Transactional(readOnly = false)
public void delete(WxFeedback wxFeedback) {
super.delete(wxFeedback);
}
public Map rece_feedback(HttpServletRequest request) {
Map map = new HashMap();
String userid = request.getParameter("userid");
String fdid = request.getParameter("fdid");
String kes = request.getParameter("kes");
String question = request.getParameter("question");
WxFeedback feedback = getFdid(fdid);//反馈id查询是否存在,存在的话不再保存
if(feedback == null) {
WxFeedback order = new WxFeedback();
order.setUserid(userid);
order.setFdid(fdid);
order.setKes(kes);
order.setQuestion(question);
super.save(order);
map.put("resultMsg", "反馈信息成功保存");
}else {
map.put("resultMsg", "已存在反馈信息");
}
return map;
}
private WxFeedback getFdid(String fdid) {
// TODO Auto-generated method stub
return dao.getFdid(fdid);
}
public Map answer(WxFeedback wxFeedback) {
String url = Global.getWxUrl() + "/end/feedback";
Map params = new HashMap();
params.put("fdid", wxFeedback.getFdid());
params.put("answer", wxFeedback.getAnswer());
params.put("isopen", wxFeedback.getIsopen());
String content = "";
try {
content = posturl(params, url);
} catch (IOException e) {
e.printStackTrace();
}
Map map = JsonUtil.jsonToMap(content);
return map;
}
// post方式向微信端传递数据
private String posturl(Map params, String url) throws IOException {
Integer URLOUTTIME = 1000 * 60;
String res = "";
HttpPost httppost = null;
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
Exception exception = null;
try {
client = HttpClientBuilder.create().build();
httppost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(URLOUTTIME)
.setConnectTimeout(URLOUTTIME).setSocketTimeout(URLOUTTIME).build();
httppost.setConfig(requestConfig);
List<NameValuePair> urlParameters = Lists.newArrayList();
if(params != null && params.size()>0) {
Iterator<String> it = params.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
urlParameters.add(new BasicNameValuePair(key,(String) params.get(key)));
}
httppost.setEntity(new UrlEncodedFormEntity(urlParameters, "utf-8"));
}
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
response = client.execute(httppost);
res = EntityUtils.toString(response.getEntity(), "utf-8");
logger.info("返回信息:" + res);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httppost != null) {
httppost.releaseConnection();
}
if (response != null) {
response.close();
}
if (client != null) {
client.close();
}
}
return res;
}
public Map open(WxFeedback wxFeedback) {
String url = Global.getWxUrl() + "/open/feedback";
Map params = new HashMap();
params.put("fdid", wxFeedback.getFdid());
params.put("isopen", wxFeedback.getIsopen());
String content = "";
try {
content = posturl(params, url);
} catch (IOException e) {
e.printStackTrace();
}
Map map = JsonUtil.jsonToMap(content);
return map;
}
}