private String getOpenId(String code){ String url = "https://api.weixin.qq.com/sns/jscode2session"; HashMap map = new HashMap(); map.put("appid", appId); map.put("secret", appSecret); map.put("js_code", code); map.put("grant_type", "authorization_code"); // http请求 String response = HttpUtil.post(url, map); // 返回响应转json,通过key获取value JSONObject jsonObject = JSONUtil.parseObj(response); String openid = jsonObject.getStr("openid"); if(ValidateUtil.isEmpty(openid)){ throw new RuntimeException("临时登陆凭证错误"); } return openid; }
if (!bool) { //把当前用户绑定到ROOT帐户 String openId = getOpenId(code); HashMap param = new HashMap(); param.put("openId", openId); param.put("nickname", nickname); param.put("photo", photo); param.put("role", "[0]"); param.put("status", 1); param.put("createTime", new Date()); param.put("root", true); userDao.insert(param); int id = userDao.searchIdByOpenId(openId); return id; }
map作为参数非常灵活,value可以是多种类型
标签:map,code,String,openid,微信,param,接口,put From: https://www.cnblogs.com/sgj191024/p/17758484.html