瀏覽代碼

修改token刷新

yumeng 5 年之前
父節點
當前提交
e2a6279340

+ 2 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml

@@ -15,7 +15,7 @@
         <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
     </resultMap>
 
-    <sql id="Base_Column_List">
+    <sql id="Base_Column_List">selectAll
         id,media_id,advertiser_id,account_id,access_token,refresh_token,access_token_expires_in,refresh_token_expires_in,create_time,update_time
    </sql>
 
@@ -23,6 +23,7 @@
         select
         <include refid="Base_Column_List"/>
         from ctop_oauth_token
+        group by account_id
     </select>
 
 

+ 17 - 4
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java

@@ -70,9 +70,20 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
         }
         JSONObject data = resultObject.getJSONObject("data");
         CtopOauthToken refreshToken = new CtopOauthToken(token, data);
-        cTopOauthTokenMapper.deleteById(token.getId());
+       /* cTopOauthTokenMapper.deleteById(token.getId());
         cTopOauthTokenMapper.insert(refreshToken);
-        log.info("头条刷新token成功:accountId:{}", accountId);
+        CtopOauthToken topOauthToken = new CtopOauthToken();
+        topOauthToken.setAccessToken(refreshToken.getAccessToken());
+        topOauthToken.setRefreshToken(refreshToken.getRefreshToken());*/
+
+        QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("media_id", 1);
+
+        int i = cTopOauthTokenMapper.update(refreshToken, queryWrapper);
+        if (i > 0) {
+            log.info("头条刷新token成功:accountId:{}", accountId);
+        }
         resultMap.put("message", "token刷新成功");
         resultMap.put("code", 0);
         return resultMap;
@@ -104,7 +115,6 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
                     if (!Check.isNull(oauthToken)) {
                         JSONObject dataJson = resultJson.getJSONObject("data");
                         if (!Check.isNull(dataJson)) {
-                            oauthToken.setAccountId(accountId);
                             oauthToken.setAccessToken(dataJson.getString("access_token"));
                             long accessTokenExpireIn = dataJson.getLong("access_token_expires_in") * 1000L;
                             long now = System.currentTimeMillis();
@@ -115,7 +125,10 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
                             Date refreshTokenExpireInDate = new Date(now + refreshTokenExpireIn);
                             oauthToken.setRefreshTokenExpiresIn(refreshTokenExpireInDate);
                             oauthToken.setUpdateTime(new Date());
-                            int i = cTopOauthTokenMapper.updateByPrimaryKeySelective(oauthToken);
+                            QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+                            queryWrapper.eq("account_id", accountId);
+                            queryWrapper.eq("media_id", 2);
+                            int i = cTopOauthTokenMapper.update(oauthToken, queryWrapper);
                             if (i > 0) {
                                 log.info("快手刷新token成功,accountId:{}", accountId);
                             }