Commit e339efaa authored by 钱坤's avatar 钱坤

早报推送的链接改为使用重定向地址

parent b2d9b8aa
package com.tanpu.feo.feojob.feign.shorter;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(value = "shorturl", url = "${tanpu.feo-shorter.svc:}", path = "/")
public interface ShorterFeign {
@PostMapping(value = "/shorter/get")
ShorterResp getShorter(@RequestParam("url") String url);
}
package com.tanpu.feo.feojob.feign.shorter;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class ShorterResp<T> {
private int code;
private String msg;
private T result;
public ShorterResp(int code, String msg) {
this.code = code;
this.msg = msg;
}
public boolean isSuccess() {
return code == 200;
}
public boolean isNotSuccess() {
return !isSuccess();
}
}
......@@ -4,8 +4,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -13,22 +11,17 @@ import com.tanpu.common.constant.BizStatus;
import com.tanpu.feo.feojob.config.MorningPaperProperties;
import com.tanpu.feo.feojob.dao.user.entity.*;
import com.tanpu.feo.feojob.dao.user.mapper.*;
import com.tanpu.feo.feojob.feign.shorter.ShorterFeign;
import com.tanpu.feo.feojob.feign.shorter.ShorterResp;
import com.tanpu.feo.feojob.feign.wxcp.FeignClientForWxCp;
import com.tanpu.feo.feojob.feign.wxmp.FeignClientForWxMp;
import com.tanpu.feo.feojob.service.RedirectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -63,7 +56,7 @@ public class DaySubJob {
@Resource
private OrgMapper orgMapper;
@Resource
private ShorterFeign shorterFeign;
private RedirectService redirectService;
@Scheduled(cron = "0 30 7 * * ? ") //
......@@ -148,12 +141,8 @@ public class DaySubJob {
String corpId = jsonKeyInfo.getStr("corpId");
// ww=corpId&orgCode=orgCode
String link = String.format(daySubjectUrl, corpId, orgEntity.getOrgCode(), daySubjectEntity.getId());
String url = getShortUrl(link);
if (StringUtils.isBlank(url)) {
log.error("早报的短链生成失败, orgCode: {}, link: {}", orgEntity.getOrgCode(), link);
continue;
}
log.info("早报推送使用短链, short-url: {}, origin-url: {}", url, link);
String url = redirectService.getRedirectLink(link);
log.info("早报推送使用重定向链接, redirect-url: {}, origin-url: {}", url, link);
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
......@@ -172,12 +161,8 @@ public class DaySubJob {
String wxAppID = jsonKeyInfo.getStr("sendMessageAppId");
// ww=wxAppID&orgCode=orgCode
String link = String.format(daySubjectUrl, wxAppID, orgEntity.getOrgCode(), daySubjectEntity.getId());
String url = getShortUrl(link);
if (StringUtils.isBlank(url)) {
log.error("早报的短链生成失败, orgCode: {}, link: {}", orgEntity.getOrgCode(), link);
continue;
}
log.info("早报推送使用短链, short-url: {}, origin-url: {}", url, link);
String url = redirectService.getRedirectLink(link);
log.info("早报推送使用重定向链接, redirect-url: {}, origin-url: {}", url, link);
StringBuilder sb = new StringBuilder();
sb.append(mainTitle).append("\n\n")
.append(morningPaperProperties.getSubTitle()).append("\n\n")
......@@ -233,14 +218,6 @@ public class DaySubJob {
return morningPaperProperties.getMainTitles().get(RandomUtil.randomInt(0, size));
}
private String getShortUrl(String url) {
ShorterResp resp = shorterFeign.getShorter(url);
if (resp.isNotSuccess()) {
return null;
}
return String.valueOf(resp.getResult());
}
public static void main(String[] args) throws Exception {
log.info("=========================");
......
package com.tanpu.feo.feojob.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@Service
public class RedirectService {
@Value("${tanpu.redirect.url:}")
private String redirectUrl;
public String getRedirectLink(String url) {
if (StringUtils.isBlank(url)) {
return "";
}
String u = Base64.getEncoder().encodeToString(url.getBytes(StandardCharsets.UTF_8));
return redirectUrl + u;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment