|
|
@ -17,6 +17,7 @@ import com.hai.common.exception.SysCode; |
|
|
|
import com.hai.common.security.SessionObject; |
|
|
|
import com.hai.common.security.SessionObject; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
import com.hai.common.security.UserCenter; |
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
|
|
|
|
import com.hai.common.utils.RedisUtil; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.entity.HighUser; |
|
|
|
import com.hai.entity.HighUser; |
|
|
|
import com.hai.model.HighUserModel; |
|
|
|
import com.hai.model.HighUserModel; |
|
|
@ -48,6 +49,8 @@ public class WechatController { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(WechatController.class); |
|
|
|
private static final Logger log = LoggerFactory.getLogger(WechatController.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String WX_OPENID_SESSION_REDIS = "WX_OPENID_SESSION_REDIS"; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private UserCenter userCenter; |
|
|
|
private UserCenter userCenter; |
|
|
|
|
|
|
|
|
|
|
@ -57,13 +60,15 @@ public class WechatController { |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private HighUserPayPasswordService highUserPayPasswordService; |
|
|
|
private HighUserPayPasswordService highUserPayPasswordService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private RedisUtil redisUtil; |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/handleCode", method = RequestMethod.GET) |
|
|
|
@RequestMapping(value = "/handleCode", method = RequestMethod.GET) |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
@ApiOperation(value = "小程序code解析") |
|
|
|
@ApiOperation(value = "小程序code解析") |
|
|
|
public ResponseData compairCode(@RequestParam(value = "code", required = true) String code, |
|
|
|
public ResponseData compairCode(@RequestParam(value = "code", required = true) String code, |
|
|
|
HttpServletRequest request, HttpServletResponse response) { |
|
|
|
HttpServletRequest request, HttpServletResponse response) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
//校验code,openId不能同时为空
|
|
|
|
//校验code,openId不能同时为空
|
|
|
|
if (StringUtils.isEmpty(code)) { |
|
|
|
if (StringUtils.isEmpty(code)) { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
@ -72,7 +77,7 @@ public class WechatController { |
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code); |
|
|
|
WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code); |
|
|
|
//保存小程序用户登录的openId及sessionKey信息
|
|
|
|
//保存小程序用户登录的openId及sessionKey信息
|
|
|
|
SessionKeyCache.setData(session.getOpenid(), session, -1); |
|
|
|
redisUtil.hset(WX_OPENID_SESSION_REDIS,session.getOpenid(),session); |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("openId", session.getOpenid()); |
|
|
|
jo.put("openId", session.getOpenid()); |
|
|
|
return ResponseMsgUtil.success(jo); |
|
|
|
return ResponseMsgUtil.success(jo); |
|
|
@ -87,7 +92,6 @@ public class WechatController { |
|
|
|
public ResponseData login(@RequestParam(value = "openId", required = true) String openId, |
|
|
|
public ResponseData login(@RequestParam(value = "openId", required = true) String openId, |
|
|
|
HttpServletRequest request, HttpServletResponse response) { |
|
|
|
HttpServletRequest request, HttpServletResponse response) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
//校验code,openId不能同时为空
|
|
|
|
//校验code,openId不能同时为空
|
|
|
|
if (StringUtils.isEmpty(openId)) { |
|
|
|
if (StringUtils.isEmpty(openId)) { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
@ -130,10 +134,13 @@ public class WechatController { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
//请求微信api,获取用户session_key以及openId
|
|
|
|
//请求微信api,获取用户session_key以及openId
|
|
|
|
WxMaJscode2SessionResult session = SessionKeyCache.getData(openId); |
|
|
|
Object skObject = redisUtil.hget(WX_OPENID_SESSION_REDIS,openId); |
|
|
|
|
|
|
|
if (skObject == null){ |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WxMaJscode2SessionResult session = (WxMaJscode2SessionResult)skObject; |
|
|
|
|
|
|
|
|
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
|
|
|
|
|
|
|
|
WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); |
|
|
|
WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); |
|
|
|
if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) { |
|
|
|
if (phoneNoInfo == null || StringUtils.isEmpty(phoneNoInfo.getPurePhoneNumber())) { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败"); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败"); |
|
|
@ -174,12 +181,14 @@ public class WechatController { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
//请求微信api,获取用户session_key以及openId
|
|
|
|
//请求微信api,获取用户session_key以及openId
|
|
|
|
WxMaJscode2SessionResult session = SessionKeyCache.getData(openId); |
|
|
|
Object skObject = redisUtil.hget(WX_OPENID_SESSION_REDIS,openId); |
|
|
|
System.out.println(JSONObject.toJSONString(session)); |
|
|
|
if (skObject == null){ |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WxMaJscode2SessionResult session = (WxMaJscode2SessionResult)skObject; |
|
|
|
|
|
|
|
|
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
final WxMaService wxService = WxMaConfiguration.getMaService(); |
|
|
|
WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(session.getSessionKey(), encryptedData, iv); |
|
|
|
WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(session.getSessionKey(), encryptedData, iv); |
|
|
|
|
|
|
|
|
|
|
|
if (userInfo == null) { |
|
|
|
if (userInfo == null) { |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败"); |
|
|
|
throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_DECRYPT_ERROR, "用户phoneNumber解析失败"); |
|
|
|
} |
|
|
|
} |
|
|
|