一个读取properties的小工具
ResourceBundle.getBundle(“weixin”);
通过ResourceBundle,我们需要访问位于/WEB-INF/classes目录下的一个后缀名为properties的文本类型文件,从里面读取我们需要的值。
springboot我们可以直接放默认properties那边
public static com.alibaba.fastjson.JSONObject getSessionKeyOropenid(String code){
//微信端登录code值
String wxCode = code;
ResourceBundle resource = ResourceBundle.getBundle("weixin"); //读取属性文件
String requestUrl = resource.getString("url"); //请求地址 https://api.weixin.qq.com/sns/jscode2session
Map<String,String> requestUrlParam = new HashMap<String,String>();
requestUrlParam.put("appid", resource.getString("appId")); //开发者设置中的appId
requestUrlParam.put("secret", resource.getString("appSecret")); //开发者设置中的appSecret
requestUrlParam.put("js_code", wxCode); //小程序调用wx.login返回的code
requestUrlParam.put("grant_type", "authorization_code"); //默认参数
//发送post请求读取调用微信 https://api.weixin.qq.com/sns/jscode2session 接口获取openid用户唯一标识
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(com.fishonline.easyreport.utils.UrlUtil.sendPost(requestUrl,requestUrlParam));
return jsonObject;
}