51e52c42c488fe1fb528bf8a7513df26efe4b539.svn-base
2.5 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
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.cms.web.front;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.utils.WiexinSignUtil;
/**
* 测试Controller
* @author ThinkGem
* @version 2014-02-28
*/
@Controller
@RequestMapping(value = "${frontPath}/weixin")
public class WeixinController extends BaseController {
/**
*
* @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
* @param timestamp 时间戳
* @param nonce 随机数
* @param echostr 随机数
* @return
*/
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public String get(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request) {
System.out.println("=============================================== get start");
for (Object o : request.getParameterMap().keySet()){
System.out.println(o + " = " + request.getParameter((String)o));
}
System.out.println("=============================================== get end");
// 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败
if (WiexinSignUtil.checkSignature(signature, timestamp, nonce)) {
return echostr;
}
return "";
}
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
public String post(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request) {
System.out.println("=============================================== post start");
for (Object o : request.getParameterMap().keySet()){
System.out.println(o + " = " + request.getParameter((String)o));
}
System.out.println("=============================================== post end");
StringBuilder result = new StringBuilder();
result.append("<xml>" +
"<ToUserName><![CDATA[toUser]]></ToUserName>" +
"<FromUserName><![CDATA[fromUser]]></FromUserName>" +
"<CreateTime>12345678</CreateTime>" +
"<MsgType><![CDATA[text]]></MsgType>" +
"<Content><![CDATA[你好]]></Content>" +
"</xml>");
return result.toString();
}
}