Commit 4daac078 authored by hezhen's avatar hezhen

123

parent ad63ee67
...@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
...@@ -45,10 +44,16 @@ public class WeixinController { ...@@ -45,10 +44,16 @@ public class WeixinController {
if (StringUtils.isBlank(redirec_url)){ if (StringUtils.isBlank(redirec_url)){
redirec_url=""; redirec_url="";
} }
String encrypt_curr_url = Base64.encode(redirec_url); try {
String encrypt_curr_url = Base64.encode(redirec_url.getBytes("utf-8"));
redirec_url=url+"?" + WECHAT_AUTOLOGIN_CALLBACKURL_KEY+ "=" + encrypt_curr_url; 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){
e.printStackTrace();
log.info("网络异常===" + e.getMessage());
return String.format("网络异常");
}
} }
/** /**
...@@ -64,6 +69,7 @@ public class WeixinController { ...@@ -64,6 +69,7 @@ public class WeixinController {
log.info("----code为空---"); log.info("----code为空---");
return String.format("code为空"); return String.format("code为空");
} }
try {
JSONObject jsonData = weixinService.getAccessToken(code); JSONObject jsonData = weixinService.getAccessToken(code);
String openid = jsonData.getString("openid"); String openid = jsonData.getString("openid");
String access_token = jsonData.getString("access_token"); String access_token = jsonData.getString("access_token");
...@@ -79,15 +85,19 @@ public class WeixinController { ...@@ -79,15 +85,19 @@ public class WeixinController {
} }
UserInfo userInfo=new UserInfo(); UserInfo userInfo=new UserInfo();
userInfo.setOpenId(openid); userInfo.setOpenId(openid);
log.error("UserInfo===" + JSONObject.toJSONString(userInfo)); log.info("UserInfo===" + JSONObject.toJSONString(userInfo));
String encode = Base64.encode(JSONObject.toJSONString(userInfo)); String encode = Base64.encode(JSONObject.toJSONString(userInfo));
session.removeAttribute(frontSessionKey); session.removeAttribute(frontSessionKey);
session.setAttribute(frontSessionKey, encode); session.setAttribute(frontSessionKey, encode);
callback =Base64.encode(callback); callback =new String(Base64.decode(callback), "utf-8");
log.error("callback===" + callback); log.info("callback===" + callback);
return String.format("redirect:"+callback); return String.format("redirect:"+callback);
}catch (Exception e){
e.printStackTrace();
log.info("网络异常===" + e.getMessage());
return String.format("网络异常");
} }
}
} }
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