Commit 5f4a0acd authored by hezhen's avatar hezhen

123

parent b8a9c2ba
...@@ -31,7 +31,6 @@ import javax.servlet.http.HttpSession; ...@@ -31,7 +31,6 @@ import javax.servlet.http.HttpSession;
public class WeixinController { public class WeixinController {
public static final String WECHAT_AUTOLOGIN_CALLBACKURL_KEY = "callback"; public static final String WECHAT_AUTOLOGIN_CALLBACKURL_KEY = "callback";
public static final String WECHAT_REDIS_KEY = "key";
@Autowired @Autowired
WeixinService weixinService; WeixinService weixinService;
...@@ -53,15 +52,16 @@ public class WeixinController { ...@@ -53,15 +52,16 @@ public class WeixinController {
@RequestMapping(value ="/app/unauth/wxLogin",method = RequestMethod.GET) @RequestMapping(value ="/app/unauth/wxLogin",method = RequestMethod.GET)
@IgnoreUserToken @IgnoreUserToken
public String index(@RequestParam(value = "redirec_url")String redirec_url, public String index(@RequestParam(value = "redirec_url",defaultValue = "")String redirec_url,
@RequestParam(value = "key")String key){ @RequestParam(value = "key",defaultValue = "")String key){
log.info("-----微信wxLogin---redirec_url=="+redirec_url); log.info("-----微信wxLogin---redirec_url=="+redirec_url+"-----key===="+key);
if (StringUtils.isBlank(redirec_url)){ if (StringUtils.isBlank(redirec_url)||StringUtils.isBlank(key)){
redirec_url=""; redirec_url="";
} }
try { try {
String encrypt_curr_url = Base64.encode(redirec_url.getBytes("utf-8")); String encrypt_curr_url = Base64.encode(redirec_url.getBytes("utf-8"));
redirec_url=url+"?" + WECHAT_AUTOLOGIN_CALLBACKURL_KEY+ "=" + encrypt_curr_url+"&"+WECHAT_REDIS_KEY+"="+key; encrypt_curr_url+=","+key;
redirec_url=url+"?" + WECHAT_AUTOLOGIN_CALLBACKURL_KEY+ "=" + encrypt_curr_url;
String oauth_api=weixinService.getAuthorize(redirec_url); String oauth_api=weixinService.getAuthorize(redirec_url);
return String.format("redirect:"+oauth_api); return String.format("redirect:"+oauth_api);
}catch (Exception e){ }catch (Exception e){
...@@ -78,17 +78,22 @@ public class WeixinController { ...@@ -78,17 +78,22 @@ public class WeixinController {
* @return * @return
*/ */
@GetMapping(value = "/app/unauth/userInfo") @GetMapping(value = "/app/unauth/userInfo")
public String getUserInformation(String code, String callback,String key, HttpServletRequest request) { public String getUserInformation(String code, String callback, HttpServletRequest request) {
log.info("-----微信回调userInfo---code=="+code+"----redirec_url==="+callback+"---key==="+key); log.info("-----微信回调userInfo---code=="+code+"----redirec_url==="+callback);
try { try {
String [] params=callback.split(",");
String key=params[1];
callback=params[0];
userBiz.authUser(code,key,request); userBiz.authUser(code,key,request);
callback =new String(Base64.decode(callback), "utf-8"); callback =new String(Base64.decode(callback), "utf-8");
log.info("callback===" + callback); log.info("callback===" + callback);
return String.format("redirect:"+callback);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
log.info("网络异常===" + e.getMessage()); log.info("网络异常===" + e.getMessage());
return String.format("网络异常");
} }
return String.format("redirect:"+callback);
} }
/** /**
......
...@@ -89,16 +89,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -89,16 +89,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter {
{ {
e.printStackTrace(); e.printStackTrace();
} }
String redisLockKey=null; String key=null;
if (StringUtils.isNotBlank(jb)){ if (StringUtils.isNotBlank(jb)){
redisLockKey= RedisKey.CONSTANT_CODE_PREFIX + UUID.randomUUID(); key= UUID.randomUUID()+"";
String redisLockKey= RedisKey.CONSTANT_CODE_PREFIX +key;
log.info("-----jb====="+jb.toString()); log.info("-----jb====="+jb.toString());
Boolean suc = summbitRedisTemplate.opsForValue().setIfAbsent(redisLockKey, jb.toString()); Boolean suc = summbitRedisTemplate.opsForValue().setIfAbsent(redisLockKey, jb.toString());
if (suc) { if (suc) {
summbitRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期 summbitRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期
} }
} }
return redisLockKey; return key;
} }
......
...@@ -76,7 +76,7 @@ public class JsTicketService { ...@@ -76,7 +76,7 @@ public class JsTicketService {
{ {
JSONObject objTemp = new JSONObject(); JSONObject objTemp = new JSONObject();
objTemp = JSONObject.parseObject(jsTicketRedis).getJSONObject(key); objTemp = JSONObject.parseObject(jsTicketRedis).getJSONObject(key);
jsTicket.setExpiredTime(objTemp.getLong("expiresIn")); jsTicket.setExpiredTime(objTemp.getLong("expiredTime"));
jsTicket.setTicket(objTemp.getString("ticket")); jsTicket.setTicket(objTemp.getString("ticket"));
jsTicket.setExpires_in(objTemp.getInteger("expiresIn")); jsTicket.setExpires_in(objTemp.getInteger("expiresIn"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment