获取小程序accessToken

private static String getAccessToken(){
	        String url = "https://api.weixin.qq.com/cgi-bin/token?			                                grant_type=client_credential&appid="+"wx5d6fccb4d0b05cd8"+"&secret="+"5cba895998cad2b0d0b5895ee43891bd";
	        String wxJson = new RestTemplate().getForEntity(url, String.class).getBody();
	        System.out.println("access-token响应: {}"+wxJson);
	        com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(wxJson);
	        Object accessTokenObj = jsonObject.get("access_token");
	        if(accessTokenObj == null){
	            return null;
	        }
	        String a=accessTokenObj.toString().split(",")[0].split(":")[0];
	        return a;
	    }

  ,

posted @ 2019-12-11 11:16  黑魔法os  阅读(1466)  评论(0编辑  收藏  举报