Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
feo-jobs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
feo-jobs
Commits
e339efaa
Commit
e339efaa
authored
Aug 25, 2021
by
钱坤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
早报推送的链接改为使用重定向地址
parent
b2d9b8aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
68 deletions
+29
-68
ShorterFeign.java
...java/com/tanpu/feo/feojob/feign/shorter/ShorterFeign.java
+0
-11
ShorterResp.java
.../java/com/tanpu/feo/feojob/feign/shorter/ShorterResp.java
+0
-28
DaySubJob.java
src/main/java/com/tanpu/feo/feojob/jobs/DaySubJob.java
+6
-29
RedirectService.java
...in/java/com/tanpu/feo/feojob/service/RedirectService.java
+23
-0
No files found.
src/main/java/com/tanpu/feo/feojob/feign/shorter/ShorterFeign.java
deleted
100644 → 0
View file @
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
);
}
src/main/java/com/tanpu/feo/feojob/feign/shorter/ShorterResp.java
deleted
100644 → 0
View file @
b2d9b8aa
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
();
}
}
src/main/java/com/tanpu/feo/feojob/jobs/DaySubJob.java
View file @
e339efaa
...
...
@@ -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
(
"========================="
);
...
...
src/main/java/com/tanpu/feo/feojob/service/RedirectService.java
0 → 100644
View file @
e339efaa
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment