| | |
| | | */ |
| | | public static String queryToken(Operator operator){ |
| | | HttpRequest post = HttpUtil.createPost(operator.getTestUrl() + InterfaceUrlEnum.QUERY_TOKEN.getUrl()); |
| | | JSONObject info = new JSONObject(); |
| | | info.put("OperatorID", operator.getOurOperatorId()); |
| | | info.put("OperatorSecret", operator.getOperatorSecret()); |
| | | Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); |
| | | post.contentType("application/json;charset=utf-8"); |
| | | JSONObject body = new JSONObject(); |
| | | body.put("OperatorID", operator.getOurOperatorId()); |
| | | body.put("OperatorSecret", operator.getOurOperatorSecret()); |
| | | post.body(body.toJSONString()); |
| | | BaseRequest baseRequest = new BaseRequest(); |
| | | baseRequest.setOperatorID(operator.getOurOperatorId()); |
| | | baseRequest.setTimeStamp(timeStamp); |
| | | baseRequest.setSeq("0001"); |
| | | String jsonString = JacksonUtils.toJson(info); |
| | | String encrypt = AESUtil.encrypt(jsonString, operator.getDataSecret(), operator.getDataSecretIv()); |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setOperator(operator); |
| | | baseRequest.setSig(buildSign(baseRequest)); |
| | | String request_json = JacksonUtils.toJson(baseRequest); |
| | | log.info("获取授权token请求:" + request_json); |
| | | log.info("获取授权token请求Data:" + jsonString); |
| | | post.body(request_json); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("获取三方token失败:" + execute.body()); |
| | | return null; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body()); |
| | | Integer succStat = jsonObject.getInteger("SuccStat"); |
| | | if(0 != succStat){ |
| | | log.error("获取三方token失败:" + jsonObject.getString("FailReason")); |
| | | log.info("获取授权token响应:" + execute.body()); |
| | | BaseResult baseResult = JSON.parseObject(execute.body(), BaseResult.class); |
| | | Integer Ret = baseResult.getRet(); |
| | | if(0 != Ret){ |
| | | log.error("获取三方token失败:" + baseResult.getMsg()); |
| | | return null; |
| | | } |
| | | String token = jsonObject.getString("AccessToken"); |
| | | Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + jsonObject.getLong("TokenAvailableTime"); |
| | | //解密参数 |
| | | String decrypt = AESUtil.decrypt(baseResult.getData(), operator.getDataSecret(), operator.getDataSecretIv()); |
| | | log.info("获取授权token请求Data:" + decrypt); |
| | | QueryTokenResult queryTokenResult = JSON.parseObject(decrypt, QueryTokenResult.class); |
| | | String token = queryTokenResult.getAccessToken(); |
| | | Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + queryTokenResult.getTokenAvailableTime(); |
| | | LocalDateTime localDateTime = Instant.ofEpochSecond(tokenAvailableTime).atOffset(ZoneOffset.UTC).toLocalDateTime(); |
| | | operator.setAccessToken(token); |
| | | operator.setTokenAvailableTime(localDateTime); |
| | |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setOperator(operator); |
| | | baseRequest.setSig(buildSign(baseRequest)); |
| | | post.body(JSON.toJSONString(baseRequest)); |
| | | post.body(JacksonUtils.toJson(baseRequest)); |
| | | } |
| | | |
| | | |