Esempio n. 1
0
 @Override
 public User loginFromWechat(String code, String siteId) {
   AccessToken accessToken = wechatService.getAccessToken(code);
   if (accessToken.isInvalid()) {
     throw new ServiceException(accessToken.getErrmsg());
   }
   User user = userDao.getByProperty("wechatUserId", accessToken.getOpenid());
   if (null == user) {
     WechartUserInfo userInfo = wechatService.getUserInfo(accessToken);
     if (userInfo.isInvalid()) {
       throw new ServiceException(userInfo.getErrmsg());
     }
     user = new User();
     user.setWechatUserId(userInfo.getOpenid());
     user.setName(userInfo.getNickname());
     if (null != userInfo.getSex()) {
       if ("1".equals(userInfo.getSex())) {
         user.setSex(User.Sex.MALE);
       }
       if ("2".equals(userInfo.getSex())) {
         user.setSex(User.Sex.FEMALE);
       }
       user = addUser(user, siteId);
       user.setPoints(5);
       userDao.update(user);
     }
   }
   user = loginHandle(user);
   return user;
 }
Esempio n. 2
0
 @Override
 public User addUser(User user, String siteId) throws ServiceException {
   Site site = siteDao.get(siteId);
   user.setSite(site);
   user.setPoints(0);
   save(user);
   return user;
 }
Esempio n. 3
0
 @Override
 public int addSharePoints(String userId) {
   int points = (int) (Math.random() * 59) + 1;
   User user = userDao.load(userId);
   user.setPoints(user.getPoints() + points);
   userDao.update(user);
   return points;
 }
Esempio n. 4
0
 @Override
 public void psychologicalTest(String userId, int points) {
   User user = userDao.load(userId);
   if (user.getPoints() < points) {
     throw new ServiceException("当前积分不足,无法进行评测!");
   }
   user.setPoints(user.getPoints() - points);
   userDao.update(user);
 }