|
|
@@ -0,0 +1,55 @@
|
|
|
+package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.BytedanceRefreshTokenMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceRefreshTokenService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class BytedanceRefreshTokenServiceImpl implements IBytedanceRefreshTokenService {
|
|
|
+ @Autowired
|
|
|
+ private BytedanceRefreshTokenMapper bytedanceRefreshTokenMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bytedanceRefreshToken() {
|
|
|
+ List<JSONObject> tokenList = bytedanceRefreshTokenMapper.getTokenList();
|
|
|
+ if (!Check.isNull(tokenList)) {
|
|
|
+ for (int i = 0; i < tokenList.size(); i++) {
|
|
|
+ JSONObject tokenJson = tokenList.get(i);
|
|
|
+ Long adminAdvertiserId = tokenJson.getLong("adminAdvertiserId");
|
|
|
+ String refreshToken = tokenJson.getString("refreshToken");
|
|
|
+ Long appId = tokenJson.getLong("appId");
|
|
|
+ String secret = tokenJson.getString("secret");
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("app_id", appId);
|
|
|
+ param.put("secret", secret);
|
|
|
+ param.put("refresh_token", refreshToken);
|
|
|
+ String s = HttpUtils.httpPostRequest("https://api.oceanengine.com/open_api/oauth2/refresh_token/", param, null);
|
|
|
+ JSONObject refreshTokenInfo = JSONObject.parseObject(s);
|
|
|
+ if (!Check.isNull(refreshTokenInfo)) {
|
|
|
+ Integer code = refreshTokenInfo.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject data = refreshTokenInfo.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ String updateAccessToken = data.getString("access_token");
|
|
|
+ String updateRefreshToken = data.getString("refresh_token");
|
|
|
+ bytedanceRefreshTokenMapper.updateTokenByAdminAdvertiserId(adminAdvertiserId, updateAccessToken, updateRefreshToken);
|
|
|
+ log.info("{},刷新token成功", adminAdvertiserId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("刷新token失败,入参:{},返回信息:{}", param, refreshTokenInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|