@RequestMapping(value = "/home", method = RequestMethod.GET)//需要设置的IDP的回调地址redirect_uripublic Object get(@RequestParam("code")String code) throws IOException {if(StringUtils.isNotBlank(code)){String accessKeyId = "xxxx";String secretAccessId = "xxxx";HttpClient httpClient = NdHttpClientBuilder.getHttpClient(accessKeyId, secretAccessId);//此类由sdk提供JSONObject obj = new JSONObject();obj.put("access_key_id", accessKeyId);obj.put("secret_access_key", secretAccessId);obj.put("code", code);obj.put("grant_type", "authorization_code");HttpPost request = new HttpPost(API_GATEWAY_HOST+"/oauth/access_token");request.setHeader("Content-Type","application/json");StringEntity entity = new StringEntity(obj.toString());request.setHeader("sdp-app-id",SDP_APP_ID);request.setEntity(entity);HttpHost httpHost = HttpHost.create(API_GATEWAY_HOST);HttpResponse httpResponse = httpClient.execute(httpHost,request);if(httpResponse.getStatusLine().getStatusCode()==200){String result = EntityUtils.toString(httpResponse.getEntity());JSONObject token = JSONObject.parseObject(result,JSONObject.class);return token;}return EntityUtils.toString(httpResponse.getEntity());}return "code is null";}
作者:wangtc 创建时间:2023-10-08 10:41
更新时间:2023-11-14 11:11
更新时间:2023-11-14 11:11