WeChatController.java
4.82 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
package com.phxl.modules.wechat.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.phxl.common.util.Global;
import com.phxl.common.utils.Encodes;
import com.phxl.modules.wechat.constants.WeChatConstants;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.taskdefs.Exec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.phxl.modules.wechat.service.WeChatService;
import com.phxl.modules.wechat.utils.WeChatUtils;
import org.springframework.web.servlet.ModelAndView;
/**
* 微信端
* @author 何
*
*/
@Controller
@RequestMapping(value = "/weChat")
public class WeChatController {
private Logger logger=LoggerFactory.getLogger(WeChatController.class);
@Autowired
@Qualifier("weChatServiceImpl")
private WeChatService weChatService;
/**
* 微信认证
* @param signature
* @param timestamp
* @param nonce
* @param echostr
* @param request
* @param response
*/
@RequestMapping(value = "/verificate", method = RequestMethod.GET)
public void weChatVerification(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr,
HttpServletRequest request, HttpServletResponse response) {
try {
PrintWriter printWriter = response.getWriter();
//String checkWx = WeChatUtils.checkWx(timestamp, nonce);
printWriter.print(echostr);
} catch (Exception e1) {
e1.printStackTrace();
}
}
/**
* 获得加密后得密码信息
* @param password
* @return
*/
@ResponseBody
@RequestMapping(value = "/entryptPassword", method = RequestMethod.POST)
public Map<String,Object> entryptPassword(@RequestParam String password) {
String pwd = WeChatUtils.encode(password);
Map<String,Object> map =new HashMap<String, Object>();
map.put("password", pwd);
return map;
}
/**
* 登录
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response) {
return weChatService.login(request,response);
}
/**
* 接受spd推送给微信端数据
* @param request
* @param params
* @return
*/
@RequestMapping("/pushData")
@ResponseBody
public String pushWeChatData(HttpServletRequest request, @RequestBody String params){
logger.info("推送微信端接口数据:{}"+params);
String url = getServiceIp(request);
return weChatService.pushData(params,url);
}
/**
* 查询数据
* @param jsonObject
* @return
*/
@ResponseBody
@RequestMapping(value = "/findDatas", method = RequestMethod.POST)
public JSONObject findDatas(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject jsonObject) throws IOException {
return weChatService.findDataList(jsonObject);
}
/**
* 通过商品名称查询商品信息
*/
@ResponseBody
@RequestMapping(value = "/queryParam", method = RequestMethod.POST)
public JSONObject queryParams(@RequestBody JSONObject jsonObject) {
return weChatService.queryDrugInfo(jsonObject);
}
/**
* 登录
* @param request
* @param response
* @return
*/
@ResponseBody
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(HttpServletRequest request, HttpServletResponse response) {
return weChatService.logout(request,response);
}
/**
* 通过商品名称查询商品信息
*/
@ResponseBody
@RequestMapping(value = "/createMenu", method = RequestMethod.GET)
public String createMenu() {
return weChatService.createMenu();
}
/**
* 通过商品名称查询商品信息
*/
@ResponseBody
@RequestMapping(value = "/deleteMenu", method = RequestMethod.GET)
public String deleteMenu() {
return weChatService.deleteMenu();
}
/**
* 返回当前服务ip地址和端口信息
*/
public String getServiceIp(HttpServletRequest request){
//得到请求协议
String scheme = request.getScheme();
//得到具体ip
String ip = request.getHeader("host");
return scheme+"://"+ip;
}
}