Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
d10cbc0f
Commit
d10cbc0f
authored
Nov 11, 2020
by
ilal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消息提醒
parent
8a9bacb0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
199 additions
and
0 deletions
+199
-0
src/main/java/cn/timer/api/controller/htzz/atttimer/AlicloudSMS.java
+139
-0
src/main/java/cn/timer/api/controller/htzz/atttimer/NewsTaskTiming.java
+60
-0
No files found.
src/main/java/cn/timer/api/controller/htzz/atttimer/AlicloudSMS.java
0 → 100644
View file @
d10cbc0f
package
cn
.
timer
.
api
.
controller
.
htzz
.
atttimer
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.CommonResponse
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.aliyuncs.exceptions.ServerException
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
cn.timer.api.bean.admin.AdminMsgTemplate
;
import
cn.timer.api.bean.htzz.HtzzAdminZzda
;
import
cn.timer.api.config.enums.PinType
;
import
cn.timer.api.controller.kqgl.ClockInTool
;
@Transactional
@Component
public
class
AlicloudSMS
{
@Value
(
"${config-8timer.Aliyun.PROJECT_NAME}"
)
public
String
PROJECT_NAME
;
@Value
(
"${config-8timer.Aliyun.REGION_ID}"
)
public
String
REGION_ID
;
@Value
(
"${config-8timer.Aliyun.ACCESSKEY_ID}"
)
public
String
ACCESSKEY_ID
;
@Value
(
"${config-8timer.Aliyun.SECRET}"
)
public
String
SECRET
;
final
static
String
CODE_NAME
=
"TemplateCode"
;
// 短信模板代码参数名
final
static
String
TEMPLATE_PARAM
=
"TemplateParam"
;
// 自定义参数
final
static
String
DOMAIN
=
"dysmsapi.aliyuncs.com"
;
final
static
String
VERSION
=
"2017-05-25"
;
final
static
String
ACTION_SEND
=
"SendSms"
;
// 发短信
final
static
String
ACTION_QUERY
=
"QuerySendDetails"
;
// 短信查询
final
static
String
PAGE_SIZE
=
"1"
;
final
static
String
CURRENT_PAGE
=
"1"
;
/**
* 提醒功能
*/
@SuppressWarnings
(
"deprecation"
)
public
List
<
Object
>
remind
(
HtzzAdminZzda
zzda
,
String
phone
,
String
tzname
)
{
//短信模板详情
AdminMsgTemplate
dxmb
=
AdminMsgTemplate
.
builder
().
id
(
zzda
.
getTemplateId
()).
build
().
selectById
();
String
str
=
dxmb
.
getContent
();
String
code
=
dxmb
.
getPlatformNum
();
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
REGION_ID
,
ACCESSKEY_ID
,
SECRET
);
IAcsClient
client
=
new
DefaultAcsClient
(
profile
);
CommonRequest
request
=
new
CommonRequest
();
request
.
setMethod
(
MethodType
.
POST
);
request
.
setDomain
(
DOMAIN
);
request
.
setVersion
(
VERSION
);
request
.
setAction
(
ACTION_SEND
);
request
.
putQueryParameter
(
"RegionId"
,
REGION_ID
);
request
.
putQueryParameter
(
"PhoneNumbers"
,
phone
);
request
.
putQueryParameter
(
"SignName"
,
PROJECT_NAME
);
request
.
putQueryParameter
(
CODE_NAME
,
code
);
//模版CODE
ArrayList
<
String
>
word
=
new
ArrayList
<
String
>();
int
m
=
0
,
n
=
0
;
int
count
=
0
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
if
(
str
.
charAt
(
i
)
==
'{'
)
{
if
(
count
==
0
)
{
m
=
i
;
}
count
++;
}
if
(
str
.
charAt
(
i
)
==
'}'
)
{
count
--;
if
(
count
==
0
)
{
n
=
i
;
word
.
add
(
str
.
substring
(
m
,
n
+
1
).
replace
(
"{"
,
""
).
replace
(
"}"
,
""
));
}
}
}
JsonArray
array
=
new
JsonArray
();
JsonObject
lan
=
new
JsonObject
();
for
(
String
bl
:
word
)
{
if
(
bl
.
equals
(
"name"
))
{
lan
.
addProperty
(
bl
,
tzname
);
}
else
if
(
bl
.
equals
(
"yxdqr"
)){
lan
.
addProperty
(
bl
,
ClockInTool
.
SunNovCSTYMD
(
zzda
.
getYxdqr
()));
}
else
{
String
strjson
=
JSON
.
toJSONString
(
zzda
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
strjson
);
String
value
=
jsonObject
.
getString
(
bl
);
lan
.
addProperty
(
bl
,
value
);
}
}
array
.
add
(
lan
);
String
SMSformat
=
String
.
valueOf
(
array
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
System
.
out
.
println
(
SMSformat
);
//短信模板格式
request
.
putQueryParameter
(
TEMPLATE_PARAM
,
SMSformat
);
CommonResponse
response
=
null
;
String
a
=
null
;
try
{
response
=
client
.
getCommonResponse
(
request
);
a
=
response
.
getData
();
System
.
err
.
println
(
"response:"
+
a
);
// 短信服务响应内容
}
catch
(
ServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
}
Integer
id
=
null
;
if
(
a
!=
null
&&
a
.
contains
(
"OK"
))
{
List
<
Object
>
list
=
new
ArrayList
<
Object
>();
list
.
add
(
id
);
list
.
add
(
JSONObject
.
parseObject
(
response
.
getData
()));
return
list
;
// 代表请求成功
}
return
null
;
}
}
src/main/java/cn/timer/api/controller/htzz/atttimer/NewsTaskTiming.java
0 → 100644
View file @
d10cbc0f
package
cn
.
timer
.
api
.
controller
.
htzz
.
atttimer
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
cn.timer.api.bean.htzz.HtzzAdminZzda
;
import
cn.timer.api.bean.htzz.HtzzAssoHtgx
;
import
cn.timer.api.bean.htzz.HtzzAssoZztx
;
import
cn.timer.api.controller.kqgl.ClockInTool
;
/**
* 消息定时器
*
*/
@Configuration
// 1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling
// 2.开启定时任务
public
class
NewsTaskTiming
{
@Autowired
private
AlicloudSMS
sms
;
@Scheduled
(
cron
=
"0 33 14 * * ?"
)
public
void
MessageAlert
()
throws
ParseException
{
//当前时间
String
nowdate
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
).
format
(
new
Date
()).
toString
();
//
List
<
HtzzAdminZzda
>
htzzs
=
HtzzAdminZzda
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
HtzzAdminZzda
>().
lambda
().
eq
(
HtzzAdminZzda:
:
getTxkgType
,
1
)
.
ge
(
HtzzAdminZzda:
:
getYxdqr
,
nowdate
));
for
(
HtzzAdminZzda
zz
:
htzzs
)
{
String
dqrq
=
ClockInTool
.
SunNovCSTYMD
(
zz
.
getYxdqr
());
//有效期到期日
//合同证照提醒表设置
HtzzAssoZztx
zzsz
=
HtzzAssoZztx
.
builder
().
build
().
selectOne
(
new
QueryWrapper
<
HtzzAssoZztx
>().
lambda
().
eq
(
HtzzAssoZztx:
:
getZzdaId
,
zz
.
getId
()));
if
(
zzsz
!=
null
)
{
int
txsj
=
zzsz
.
getTxsj
();
//提醒时间周期 0-到期提醒 1-提前一天 2-提前二天 ...
String
tqsj
=
ClockInTool
.
requires_extra_times
(
dqrq
,-
txsj
,
3
,
1
);
if
(
nowdate
.
equals
(
tqsj
))
{
List
<
HtzzAssoHtgx
>
txrs
=
HtzzAssoHtgx
.
builder
().
build
().
selectList
(
new
QueryWrapper
<
HtzzAssoHtgx
>().
lambda
().
eq
(
HtzzAssoHtgx:
:
getHtid
,
zz
.
getId
()));
for
(
HtzzAssoHtgx
rt
:
txrs
)
{
//发送短信
List
<
Object
>
list
=
sms
.
remind
(
zz
,
rt
.
getPhone
(),
rt
.
getName
());
}
}
}
}
}
}
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