Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
online-edu-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
online-edu
online-edu-backend
Commits
65786dce
Commit
65786dce
authored
Oct 29, 2021
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加新爱康的短信配置
parent
0517b07e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
SmsService.java
src/main/java/com/qkdata/biz/sms/service/SmsService.java
+50
-5
application-prod.yml
src/main/resources/application-prod.yml
+5
-0
application.yml
src/main/resources/application.yml
+1
-0
No files found.
src/main/java/com/qkdata/biz/sms/service/SmsService.java
View file @
65786dce
package
com
.
qkdata
.
biz
.
sms
.
service
;
package
com
.
qkdata
.
biz
.
sms
.
service
;
import
com.alipay.api.domain.BizOrderInfo
;
import
com.qkdata.biz.common.BizConstants
;
import
com.qkdata.biz.sms.vo.SmsRequest
;
import
com.qkdata.biz.sms.vo.SmsRequest
;
import
com.qkdata.biz.sms.vo.SmsResponse
;
import
com.qkdata.biz.sms.vo.SmsResponse
;
import
com.qkdata.biz.sms.vo.SmsV2Condition
;
import
com.qkdata.biz.sms.vo.SmsV2Condition
;
import
com.qkdata.common.base.exception.BusinessException
;
import
com.qkdata.common.base.exception.BusinessException
;
import
com.qkdata.common.constants.Constants
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Base64
;
import
java.util.Collections
;
import
java.util.Collections
;
@Slf4j
@Slf4j
...
@@ -18,21 +25,59 @@ public class SmsService {
...
@@ -18,21 +25,59 @@ public class SmsService {
@Value
(
"${sms.api.v3}"
)
@Value
(
"${sms.api.v3}"
)
private
String
api
;
private
String
api
;
@Value
(
"${sms.type}"
)
private
String
smsType
;
/**
* 登录验证码
*/
private
String
smsContent
=
"SMS_205630239;xak;%s;2"
;
/**
* 验证身份
*/
private
String
validateContent
=
"SMS_205630240;xak;%s;2"
;
@Autowired
@Autowired
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
public
void
sendSmsV3
(
SmsV2Condition
condition
)
{
public
void
sendSmsV3
(
SmsV2Condition
condition
)
{
if
(
smsType
.
equals
(
"tjxak"
))
{
try
{
String
content
=
""
;
if
(
condition
.
getCode
().
equals
(
BizConstants
.
SMS_TEMPLATE_CODE
)){
content
=
String
.
format
(
smsContent
,
condition
.
getParams
().
get
(
"code"
));
}
else
if
(
condition
.
getCode
().
equals
(
BizConstants
.
SMS_CHECK_USER_TEMPLATE_CODE
)){
content
=
String
.
format
(
validateContent
,
condition
.
getParams
().
get
(
"code"
));
}
else
{
throw
new
BusinessException
(
"短信模板编号不正确"
);
}
SmsRequest
smsRequest
=
new
SmsRequest
(
Collections
.
singletonList
(
condition
));
content
=
Base64
.
getUrlEncoder
().
encodeToString
(
content
.
getBytes
(
"UTF-8"
));
SmsResponse
smsResponse
=
restTemplate
.
postForObject
(
api
,
smsRequest
,
SmsResponse
.
class
);
String
url
=
String
.
format
(
api
,
condition
.
getMobile
(),
content
);
if
(
smsResponse
==
null
||
smsResponse
.
hasError
())
{
log
.
debug
(
"sms req url:"
+
url
);
log
.
error
(
"短信发送失败:{}"
,
smsResponse
,
toString
());
ResponseEntity
<
String
>
resp
=
restTemplate
.
getForEntity
(
url
,
String
.
class
);
throw
new
BusinessException
(
"短信发送失败"
);
if
(
resp
.
getStatusCode
()
!=
HttpStatus
.
OK
||
!
resp
.
getBody
().
equals
(
"OK"
))
{
log
.
error
(
"短信发送失败:{}"
,
resp
.
getBody
());
throw
new
BusinessException
(
"短信发送失败"
);
}
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
BusinessException
(
"短信发送失败"
);
}
catch
(
Throwable
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
BusinessException
(
"短信发送失败"
);
}
}
else
{
SmsRequest
smsRequest
=
new
SmsRequest
(
Collections
.
singletonList
(
condition
));
SmsResponse
smsResponse
=
restTemplate
.
postForObject
(
api
,
smsRequest
,
SmsResponse
.
class
);
if
(
smsResponse
==
null
||
smsResponse
.
hasError
())
{
log
.
error
(
"短信发送失败:{}"
,
smsResponse
,
toString
());
throw
new
BusinessException
(
"短信发送失败"
);
}
}
}
}
}
}
}
src/main/resources/application-prod.yml
0 → 100644
View file @
65786dce
sms
:
type
:
tjxak
api
:
v3
:
http://sms.tjxak.com/smsGateWay/sms?t=%s&c=%s
src/main/resources/application.yml
View file @
65786dce
...
@@ -118,6 +118,7 @@ wx:
...
@@ -118,6 +118,7 @@ wx:
keyPath
:
classpath:apiclient_cert.p12
keyPath
:
classpath:apiclient_cert.p12
sandbox
:
false
sandbox
:
false
sms
:
sms
:
type
:
aliyun
api
:
api
:
v3
:
http://sms-service/sms/api/v3
v3
:
http://sms-service/sms/api/v3
aliyun
:
aliyun
:
...
...
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