| | |
| | | public static void main(String[] args) { |
| | | try { |
| | | // // 初始化数据 |
| | | init(); |
| | | |
| | | // // 请求token |
| | | if (token == null) { |
| | | token = getToken(); |
| | |
| | | } |
| | | // token转对象,获取api访问所用token和secret |
| | | NcResultMessage returnData = JSONObject.parseObject(token, NcResultMessage.class); |
| | | if (returnData.isSuccess()) { |
| | | if (token != null && returnData.isSuccess()) { |
| | | JSONObject data = JSONObject.parseObject(returnData.getData().toString()); |
| | | String access_token = (String) data.get("access_token"); |
| | | String security_key = (String) data.get("security_key"); |
| | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | data = JSONObject.parseObject(token.getBytes(), NcResultMessage.class); |
| | | returnData = JSONObject.parseObject(token, NcResultMessage.class); |
| | | data = JSONObject.parseObject(returnData.getData().toString()); |
| | | access_token = (String) data.get("access_token"); |
| | | security_key = (String) data.get("security_key"); |
| | | refresh_token = (String) data.get("refresh_token"); |
| | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | System.out.println("【url】:" + apiUrl); |
| | | System.out.println("【json】:" + json); |
| | | System.out.println("【RESULT】:" + result); |
| | | System.out.println("result解密:" + result2); |
| | | return JSONObject.parseObject(result2, NcResultMessage.class); |
| | |
| | | * @throws Exception |
| | | */ |
| | | private static String getToken() throws Exception { |
| | | if (grant_type == null) { |
| | | init(); |
| | | } |
| | | String token = null; |
| | | if ("password".equals(grant_type)) { |
| | | // 密码模式 |
| | |
| | | result = new String(temp.toString().getBytes("utf-8"), ecod); |
| | | System.out.println(result); |
| | | } catch (Exception e) { |
| | | System.out.println(e); |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } finally { |
| | | if (null != bufferedReader) { |