|
|
@@ -10,7 +10,6 @@ import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.ui.Model;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
@@ -18,10 +17,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.PrintWriter;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -52,32 +47,20 @@ public class WeChatController {
|
|
|
/**
|
|
|
* 与微信服务器接口配置
|
|
|
*
|
|
|
- * @param model
|
|
|
- * @param request
|
|
|
- * @param response
|
|
|
+ * @param signature 与微信服务器接口配置
|
|
|
+ * @param timestamp 时间戳
|
|
|
+ * @param nonce 随机数
|
|
|
+ * @param echostr 随机字符串
|
|
|
*/
|
|
|
@RequestMapping(value = "/check", method = RequestMethod.GET)
|
|
|
- public void wenxinCheck(Model model, HttpServletRequest request, HttpServletResponse response) {
|
|
|
- // 微信加密签名
|
|
|
- String signature = request.getParameter("signature");
|
|
|
- // 时间戳
|
|
|
- String timestamp = request.getParameter("timestamp");
|
|
|
- // 随机数
|
|
|
- String nonce = request.getParameter("nonce");
|
|
|
- // 随机字符串
|
|
|
- String echostr = request.getParameter("echostr");
|
|
|
+ public String wenxinCheck(String signature, String timestamp, String nonce, String echostr) {
|
|
|
logger.info("与微信服务器接口配置 with signature: {} and timestamp: {} and nonce: {} and echostr: {}", signature, timestamp, nonce, echostr);
|
|
|
- PrintWriter print;
|
|
|
+
|
|
|
// 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败
|
|
|
if (signature != null && CheckoutUtil.checkSignature(signature, timestamp, nonce)) {
|
|
|
- try {
|
|
|
- print = response.getWriter();
|
|
|
- print.write(echostr);
|
|
|
- print.flush();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ return echostr;
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -96,7 +79,8 @@ public class WeChatController {
|
|
|
/**
|
|
|
* 发送模板消息
|
|
|
*
|
|
|
- * @return
|
|
|
+ * @param messages 需要发送模板的实体,包括uu号
|
|
|
+ * @return 提示信息
|
|
|
*/
|
|
|
@RequestMapping(value = "/sendTemplateMessage", method = RequestMethod.POST)
|
|
|
public ModelMap sendTemplateMessage(@RequestBody List<MessageModel> messages) {
|
|
|
@@ -107,8 +91,8 @@ public class WeChatController {
|
|
|
/**
|
|
|
* 绑定用户
|
|
|
*
|
|
|
- * @param user
|
|
|
- * @return
|
|
|
+ * @param user 用户包装类型。传入 code 或密码
|
|
|
+ * @return 正确信息或者错误信息,前端使用
|
|
|
*/
|
|
|
@RequestMapping(value = "/bindUser", method = RequestMethod.POST)
|
|
|
public ModelMap bindUser(@RequestBody UserVo user) {
|
|
|
@@ -119,7 +103,7 @@ public class WeChatController {
|
|
|
/**
|
|
|
* 发送手机验证码
|
|
|
* @param mobile 手机号
|
|
|
- * @return
|
|
|
+ * @return 前端使用的提示信息
|
|
|
*/
|
|
|
@RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET)
|
|
|
public ModelMap sendSmsCode(String mobile) {
|