Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
fbf1305f
Commit
fbf1305f
authored
Aug 18, 2023
by
muhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 发送短信验证码
parent
b4ae9d42
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
5 deletions
+104
-5
ch-core/src/main/java/com/wwdz/ch/core/notify/AliSmsSender.java
...e/src/main/java/com/wwdz/ch/core/notify/AliSmsSender.java
+85
-0
ch-core/src/main/resources/application-dev.yml
ch-core/src/main/resources/application-dev.yml
+6
-0
ch-core/src/main/resources/application-prod.yml
ch-core/src/main/resources/application-prod.yml
+6
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+7
-5
No files found.
ch-core/src/main/java/com/wwdz/ch/core/notify/AliSmsSender.java
0 → 100644
View file @
fbf1305f
package
com.wwdz.ch.core.notify
;
import
com.aliyun.dysmsapi20170525.models.SendSmsResponse
;
import
com.xxdxxs.utils.JsonUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.Map
;
@Slf4j
@Service
public
class
AliSmsSender
implements
SmsSender
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Value
(
"${dts.notify.alisms.accessKey}"
)
private
String
accessKeyId
;
@Value
(
"${dts.notify.alisms.secretKey}"
)
private
String
accessKeySecret
;
@Value
(
"${dts.notify.alisms.url}"
)
private
String
url
;
@Value
(
"${dts.notify.alisms.templateCode}"
)
private
String
templateCode
;
//短信API产品名称(短信产品名固定,无需修改)
final
String
product
=
"Dysmsapi"
;
//短信API产品域名(接口地址固定,无需修改)
final
String
domain
=
"dysmsapi.aliyuncs.com"
;
public
com
.
aliyun
.
dysmsapi20170525
.
Client
createClient
()
throws
Exception
{
com
.
aliyun
.
teaopenapi
.
models
.
Config
config
=
new
com
.
aliyun
.
teaopenapi
.
models
.
Config
()
.
setAccessKeyId
(
accessKeyId
)
.
setAccessKeySecret
(
accessKeySecret
);
// 访问的域名
config
.
endpoint
=
"dysmsapi.aliyuncs.com"
;
return
new
com
.
aliyun
.
dysmsapi20170525
.
Client
(
config
);
}
@Override
public
SmsResult
send
(
String
phone
,
String
content
)
{
return
null
;
}
@Override
public
SmsResult
sendWithTemplate
(
String
phone
,
int
templateId
,
String
[]
params
)
{
return
null
;
}
public
SmsResult
sendWithTemplate
(
String
phone
,
String
verifyCode
)
{
try
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"msg"
,
verifyCode
+
"短信验证码,1分钟内有效,请勿向任何人提供或泄露。"
);
com
.
aliyun
.
dysmsapi20170525
.
Client
client
=
createClient
();
com
.
aliyun
.
dysmsapi20170525
.
models
.
SendSmsRequest
sendSmsRequest
=
new
com
.
aliyun
.
dysmsapi20170525
.
models
.
SendSmsRequest
()
.
setPhoneNumbers
(
phone
)
.
setTemplateCode
(
templateCode
)
.
setTemplateParam
(
JsonUtils
.
fromMap
(
map
))
.
setSignName
(
"玩物得志"
);
SendSmsResponse
sendSmsResponse
=
client
.
sendSmsWithOptions
(
sendSmsRequest
,
new
com
.
aliyun
.
teautil
.
models
.
RuntimeOptions
());
logger
.
info
(
"短线验证发送结果 : {} "
,
JsonUtils
.
from
(
sendSmsResponse
));
if
(
"OK"
.
equals
(
sendSmsResponse
.
getBody
().
code
))
{
SmsResult
smsResult
=
new
SmsResult
();
smsResult
.
setSuccessful
(
true
);
smsResult
.
setResult
(
verifyCode
);
return
smsResult
;
}
throw
new
RuntimeException
(
"验证码发送失败"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"AliSmsSender.sendWithTemplate(),mobile={}"
,
phone
,
e
);
throw
new
RuntimeException
(
"验证码发送失败"
);
}
}
}
ch-core/src/main/resources/application-dev.yml
View file @
fbf1305f
...
@@ -37,6 +37,12 @@ dts:
...
@@ -37,6 +37,12 @@ dts:
-
name
:
refund
-
name
:
refund
templateId
:
112233
templateId
:
112233
alisms
:
accessKey
:
LTAIehMFG7EhsJY8
secretKey
:
1Q3mIc2tYaKT3tw3FCbKGu48AtiWSD
url
:
http://MQ_INST_1961444063236731_BXc2xu0h.cn-hangzhou.mq-internal.aliyuncs.com:8080
templateCode
:
SMS_212085019
# 微信模版通知配置
# 微信模版通知配置
# 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值
# 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值
wx
:
wx
:
...
...
ch-core/src/main/resources/application-prod.yml
View file @
fbf1305f
...
@@ -37,6 +37,12 @@ dts:
...
@@ -37,6 +37,12 @@ dts:
-
name
:
refund
-
name
:
refund
templateId
:
112233
templateId
:
112233
alisms
:
accessKey
:
LTAIehMFG7EhsJY8
secretKey
:
1Q3mIc2tYaKT3tw3FCbKGu48AtiWSD
url
:
http://MQ_INST_1961444063236731_BXc2xu0h.cn-hangzhou.mq-internal.aliyuncs.com:8080
templateCode
:
SMS_212085019
# 微信模版通知配置
# 微信模版通知配置
# 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值
# 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 NotifyType 枚举值
wx
:
wx
:
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
fbf1305f
...
@@ -3,8 +3,8 @@ package com.wwdz.ch.wx.impl;
...
@@ -3,8 +3,8 @@ package com.wwdz.ch.wx.impl;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.captcha.CaptchaCodeManager
;
import
com.wwdz.ch.core.captcha.CaptchaCodeManager
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.notify.AliSmsSender
;
import
com.wwdz.ch.core.notify.NotifyService
;
import
com.wwdz.ch.core.notify.NotifyService
;
import
com.wwdz.ch.core.notify.NotifyType
;
import
com.wwdz.ch.core.notify.SmsResult
;
import
com.wwdz.ch.core.notify.SmsResult
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.type.UserTypeEnum
;
import
com.wwdz.ch.core.type.UserTypeEnum
;
...
@@ -61,6 +61,8 @@ public class UserServiceImpl implements UserService {
...
@@ -61,6 +61,8 @@ public class UserServiceImpl implements UserService {
@Value
(
"${avatar-url}"
)
@Value
(
"${avatar-url}"
)
private
String
avatarUrl
;
private
String
avatarUrl
;
@Autowired
private
AliSmsSender
aliSmsSender
;
@Transactional
@Transactional
...
@@ -179,14 +181,14 @@ public class UserServiceImpl implements UserService {
...
@@ -179,14 +181,14 @@ public class UserServiceImpl implements UserService {
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
}
}
if
(!
RegexUtil
.
isMobileExact
(
dto
.
getMobile
()))
{
return
Result
.
failed
(
"手机号格式不正确"
);
}
String
activeProfile
=
applicationContext
.
getEnvironment
().
getActiveProfiles
()[
0
];
String
activeProfile
=
applicationContext
.
getEnvironment
().
getActiveProfiles
()[
0
];
String
code
=
"123456"
;
String
code
=
"123456"
;
if
(!
StringUtils
.
equals
(
"dev"
,
activeProfile
))
{
if
(!
StringUtils
.
equals
(
"dev"
,
activeProfile
))
{
if
(!
RegexUtil
.
isMobileExact
(
dto
.
getMobile
()))
{
return
Result
.
failed
(
"手机号格式不正确"
);
}
code
=
CharUtil
.
getRandomNum
(
6
);
code
=
CharUtil
.
getRandomNum
(
6
);
SmsResult
smsResult
=
notifyService
.
notifySmsTemplate
(
dto
.
getMobile
(),
NotifyType
.
CAPTCHA
,
new
String
[]{
code
,
"1"
}
);
SmsResult
smsResult
=
aliSmsSender
.
sendWithTemplate
(
dto
.
getMobile
(),
code
);
if
(
smsResult
!=
null
)
{
if
(
smsResult
!=
null
)
{
logger
.
info
(
"*****腾讯云短信发送->请求验证码,短信发送结果:{}"
,
JSONObject
.
toJSONString
(
smsResult
));
logger
.
info
(
"*****腾讯云短信发送->请求验证码,短信发送结果:{}"
,
JSONObject
.
toJSONString
(
smsResult
));
}
}
...
...
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