一个读取properties的小工具

一个读取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;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值