|
|
@ -2,6 +2,7 @@ package com.wmeimob.bjyy.controller; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import org.apache.log4j.Logger; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
@ -26,11 +27,13 @@ public class HomeController extends BaseController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserService userService; |
|
|
|
private Logger log = Logger.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@RequestMapping("/start") |
|
|
|
public ModelAndView start(HttpServletRequest request) { |
|
|
|
String code = request.getParameter("code"); |
|
|
|
String backUrl = request.getParameter("backUrl"); |
|
|
|
log.info("start: " + code + "," + backUrl); |
|
|
|
if (!Strings.isNullOrEmpty(code)) { |
|
|
|
if (Strings.isNullOrEmpty(backUrl)) { |
|
|
|
backUrl = request.getContextPath() + "/wx/core/index"; |
|
|
@ -50,12 +53,19 @@ public class HomeController extends BaseController { |
|
|
|
WxAuthAccessToken authToken = WECHAT.basic().authAccessToken(code); |
|
|
|
String openId = authToken.getOpenId(); |
|
|
|
if (!Strings.isNullOrEmpty(openId)) { |
|
|
|
log.info("start,openId is not null: " + openId); |
|
|
|
SessionUtil.setSession(SessionUtil.SESSION_WX_OPENID, openId); |
|
|
|
User user = RedisUtil.getObject(RedisUtil.PREFIX_USER_INFO + openId); |
|
|
|
if (user == null) { |
|
|
|
// 用户不存在才获取用户信息
|
|
|
|
log.info("start,user = " + user); |
|
|
|
user = userService.getUserByOpenId(openId); |
|
|
|
if (user == null || HttpUtil.isNetFileAvailable(user.getHeadImgurl())) { |
|
|
|
log.info("start,user,user = " + user); |
|
|
|
|
|
|
|
//因为修改了服务器,没有配置公众号白名单,这里会报错、
|
|
|
|
//invalid ip 116.204.40.58 ipv6 ::ffff:116.204.40.58, not in whitelist rid: 661
|
|
|
|
//程序走到这里会抛出异常,所以下面的saveWechatUser和RedisUtil.setValue都无法执行。
|
|
|
|
WxUserInfoBase userInfo = WECHAT.user().userInfoBase(openId); |
|
|
|
// if (userInfo.getSubscribe() != 0 || userInfo.getSubscribeTime() != null) {
|
|
|
|
// 用户已关注
|
|
|
@ -67,6 +77,7 @@ public class HomeController extends BaseController { |
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
log.info("start,return,user = " + user); |
|
|
|
RedisUtil.setValue(RedisUtil.PREFIX_USER_INFO + openId, user); |
|
|
|
} |
|
|
|
return mv; |
|
|
|