use of com.guhanjie.service.UserService 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.service.UserService in project weixin-boot by guhanjie.
the class MessageKit method handleLocationEvent.
private static String handleLocationEvent(Map<String, String> msgMap) throws IOException {
LOGGER.info("starting to handle location event....");
String openId = msgMap.get("FromUserName");
String lat = msgMap.get("Latitude");
String lng = msgMap.get("Longitude");
// 获取用户上报的地址微信,并绑定到内存中
User user = new User();
user.setOpenId(openId);
Position p = new Position();
p.setGeoLat(lat);
p.setGeoLng(lng);
user.setPosition(p);
UserService userService = SpringContextUtil.getBean(UserService.class);
userService.updateToCache(user);
return "";
}
Aggregations