需求:前端请求授权并重定向到当前页面,前端传递参数当前页路由。
如:接口http://xxxxxx/weixin/getWxgzh?redirect=healtheducation
需返回重定向到:https://xxx.xxx.xxx/web/index.html#/healtheducation
问题来了,后端请求微信code,自定义的只有state,state携带https://xxx.xxx.xxx/web/index.html#/healtheducation返回后无法获取state#后边的值,只能获取https://xxx.xxx.xxx/web/index.html。
解决方法:携带之前Base64加密,这儿的参数是state
String redirec= Base64.getEncoder().encodeToString(state.getBytes("utf-8"));
返回之后解密
byte[] decode = Base64.getDecoder().decode(state);
String statet=new String(decode);