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);
}
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);
}
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;
}
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";
}
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";
}
Aggregations