RestTemplate 请求

@Autowired
private RestTemplate httpRestTemplate;	   

	String code= request.getParameter("code");
    		URI url = new URI("http://10.20.60.107:8088/ssoserver/moc2/token");
	    	// 参数拼装
	    	LinkedMultiValueMap<String, String> postParam = new LinkedMultiValueMap<String, String>() ;
	    	postParam.add("grant_type", "authorization_code");
	    	postParam.add("client_id", "222");
	    	postParam.add("client_secret", "45B6E9F1D9A4F10873EB7B2B9BC2CB9AEC11E6AF4ED50980734E62ABFDE91210");
	    	postParam.add("redirect_uri", "http://10.20.60.107:8088/ssoserver/third/oauth/login/callback");
	    	postParam.add("code", code);
	    	ResponseEntity<JSONObject> forEntity = httpRestTemplate.postForEntity(url, postParam, JSONObject.class);
	    	JSONObject object = forEntity.getBody();
	    	String accessToken = object.getString("access_token"); 

  

posted @ 2022-11-09 16:15  JLCUI  阅读(8)  评论(0编辑  收藏  举报