package jp.co.dreamarts;

import jp.co.dreamarts.platform.wx.WeixinMessage;
import jp.co.dreamarts.platform.wx.WeixinUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
@RequestMapping("/restful/weixin.do")
public class HelloController {
    @RequestMapping(method = RequestMethod.GET)
    public String doGet(HttpServletRequest request) {
        String echostr = request.getParameter("echostr");
        request.setAttribute("echostr", echostr);
        return "hello";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String doPost(HttpServletRequest request) throws IOException {
        WeixinMessage wxMsg = null;
        try {
            wxMsg = WeixinUtils.parseXML(request.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(wxMsg.getContent());
        System.out.println("wxMsg.getReceiver()" + wxMsg.getReceiver());
        System.out.println("wxMsg.getSender()" + wxMsg.getSender());

        request.setAttribute("wxMsg", wxMsg.getReply());
        request.setAttribute("content", wxMsg.getReply());

        return "weixin";
    }


}
@@ -406,16 +406,115 @@
 ception;
+%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;
 %0A%0A@Contr
@@ -1339,122 +1339,771 @@
 ));%0A
-%0A        request.setAttribute(%22wxMsg%22, wxMsg.getReply());%0A        request.setAttribute(%22content%22, wxMsg.getReply()
+        List list = new ArrayList();%0A        Map a1 = new HashMap();%0A        a1.put(%22name%22,%22%E6%9D%8E%E6%B5%A9%22);%0A        a1.put(%22phone%22,%2218642698912%22);%0A        Map a2 = new HashMap();%0A        a2.put(%22name%22,%22%E6%9D%8E%E5%9B%9B%22);%0A        a2.put(%22phone%22,%22123123123%22);%0A        list.add(a1);%0A        list.add(a2);%0A        request.setAttribute(%22wxMsg%22, wxMsg.getReply());%0A        String phone = %22%22;%0A        for(int i = 0 ; i%3Clist.size();i++)%7B%0A            Map result = (Map)list.get(i);%0A            String s = (String)result.get(%22name%22);%0A            String p = (String)result.get(%22phone%22);%0A            if(s == wxMsg.getContent()) %7B%0A                phone = p;%0A            %7D%0A        %7D%0A        if(phone.length() == 0 )%7B%0A            phone = %22%E6%9F%A5%E6%97%A0%E6%AD%A4%E4%BA%BA%22;%0A        %7D%0A        request.setAttribute(%22content%22, phone
 );%0A%0A

test 微信