发表于: 2018-01-13 21:52:29
1 691
今天完成的事情
修改微信授权的代码,避免500错误
微信会发三次请求,都是同样的code,第一次能成功获取用户信息,之后两次因为code失效,会导致获取信息为空,考虑将第一次的信息存入session,之后两次的获取的信息先判断是否为空,在做相应的处理
@RequestMapping(value = "/a/code")
public synchronized String first(HttpServletRequest request, ModelMap model)
{
WeixinUtil weixinUtil = new WeixinUtil();
String code = request.getParameter("code");
//替换参数
String url = access_token_api.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);
//调用接口,获取access_token,openId
JSONObject jsonObject = httpRequest(url, "GET", null);
String access_token = (String) jsonObject.get("access_token");
String refresh_token = (String) jsonObject.get("refresh_token");
String openid = (String) jsonObject.get("openid");
String scope = (String) jsonObject.get("scope");
/**
* 获取data
* 用户数据
* [0]:sex,[1]:city,[2]:province
*/
String O_url = O_url_1.replace("ACCESS_TOKEN",access_token).replace("OPENID",openid);
//调用接口,获取用户信息
JSONObject userData = httpRequest(O_url, "GET", null);
userData.put("openid",openid);
将所有调用微信的流程都写在controller中,不然会出现各种500,
判断是否为空,进行添加
if (session.getAttribute("userId")==null){
session.setAttribute("userId", uid); //id类型???
}
明天的计划
修改微信图片上传的bug
遇到的问题
图片上传,签名失效
收获
session使用
评论