Search in sources :

Example 1 with User

use of com.guhanjie.model.User in project weixin-boot by guhanjie.

the class MessageKit method handleSubscribeEvent.

private static String handleSubscribeEvent(Map<String, String> msgMap) throws IOException {
    LOGGER.info("starting to handle subscribe event....");
    String openId = msgMap.get("FromUserName");
    // 自动添加关注用户
    try {
        UserService userService = SpringContextUtil.getBean(UserService.class);
        User user = userService.getUserByOpenId(openId);
        if (user == null) {
            user = new User();
            user.setOpenId(openId);
            UserInfo userInfo = UserKit.getUserInfo(openId);
            user.setUnionid(userInfo.getUnionid());
            user.setName(userInfo.getNickname());
            user.setNickname(userInfo.getNickname());
            user.setSex(userInfo.getSex());
            user.setLanguage(userInfo.getLanguage());
            user.setCountry(userInfo.getCountry());
            user.setProvince(userInfo.getProvince());
            user.setCity(userInfo.getCity());
            if (StringUtils.isNumeric(userInfo.getSubscribe_time())) {
                user.setSubscribeTime(new Date(Long.parseLong(userInfo.getSubscribe_time())));
            }
            userService.addUser(user);
        }
    } catch (Exception e) {
        LOGGER.error("error happened in add user info, openId[{}].", openId, e);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("ToUserName", msgMap.get("FromUserName"));
    map.put("FromUserName", msgMap.get("ToUserName"));
    map.put("CreateTime", new Date().getTime() + "");
    map.put("MsgType", "text");
    map.put("Content", "您好,欢迎关注!");
    return XmlUtil.map2xmlstr(map);
}
Also used : User(com.guhanjie.model.User) UserService(com.guhanjie.service.UserService) HashMap(java.util.HashMap) UserInfo(com.guhanjie.weixin.model.UserInfo) Date(java.util.Date) IOException(java.io.IOException)

Example 2 with User

use of com.guhanjie.model.User in project weixin-boot by guhanjie.

the class TestUserMapper method testGeneratedKey.

@Test
public void testGeneratedKey() {
    logger.debug("Create one record to table[{}]...\n", tableName);
    User model = new User();
    model.setName("guhanjie");
    model.setSex("m");
    long insertCount = mapper.insertSelective(model);
    logger.debug(JSON.toJSONString(model));
    assertEquals(insertCount, 1L);
}
Also used : User(com.guhanjie.model.User) Test(org.junit.Test)

Example 3 with User

use of com.guhanjie.model.User in project weixin-boot by guhanjie.

the class BaseController method getSessionUser.

protected User getSessionUser() {
    HttpSession session = request.getSession();
    Object user = session.getAttribute(AppConstants.SESSION_KEY_USER);
    if (user != null && user instanceof User) {
        return (User) user;
    }
    return null;
}
Also used : User(com.guhanjie.model.User) HttpSession(javax.servlet.http.HttpSession)

Example 4 with User

use of com.guhanjie.model.User in project weixin-boot by guhanjie.

the class OrderController method order.

@RequestMapping(value = { "", "pre" }, method = RequestMethod.GET)
public String order(HttpServletRequest req, HttpServletResponse resp, Model model, @RequestParam(required = false) String phone, @RequestParam(required = false) String source) {
    resp.setHeader("Cache-Control", "no-cache");
    if (getSessionUser() == null && StringUtils.isNotBlank(phone)) {
        User user = userService.getUserByPhone(phone);
        if (user != null) {
            setSessionUser(user);
            req.getSession().setAttribute(AppConstants.SESSION_KEY_OPEN_ID, user.getOpenId());
        }
    }
    if (StringUtils.isNotBlank(source)) {
        model.addAttribute("source", source);
    }
    return "order";
}
Also used : User(com.guhanjie.model.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with User

use of com.guhanjie.model.User in project weixin-boot by guhanjie.

the class OrderController method searchOrder.

@RequestMapping(value = "search", method = RequestMethod.GET)
public String searchOrder(HttpServletRequest req, HttpServletResponse resp, Model model) {
    resp.setHeader("Cache-Control", "no-cache");
    User user = getSessionUser();
    List<Order> orders = orderService.getOrdersByUser(user);
    model.addAttribute("orders", orders);
    model.addAttribute("now", new Date());
    return "order_search";
}
Also used : Order(com.guhanjie.model.Order) User(com.guhanjie.model.User) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (com.guhanjie.model.User)12 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 HttpSession (javax.servlet.http.HttpSession)3 Position (com.guhanjie.model.Position)2 UserService (com.guhanjie.service.UserService)2 UserInfo (com.guhanjie.weixin.model.UserInfo)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Order (com.guhanjie.model.Order)1 WeixinHttpCallback (com.guhanjie.weixin.WeixinHttpUtil.WeixinHttpCallback)1 AccessToken (com.guhanjie.weixin.model.AccessToken)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1