Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
youka-api
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
java-youka-wallet
youka-api
Commits
dbb9c31c
Commit
dbb9c31c
authored
Mar 22, 2018
by
Java-聂换换
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加发送验证码
parent
375049a9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
316 additions
and
4 deletions
+316
-4
MessageUtils.java
src/main/java/com/thinkgem/jeesite/modules/message/MessageUtils.java
+89
-0
ReceiveServlet.java
src/main/java/com/thinkgem/jeesite/modules/message/ReceiveServlet.java
+92
-0
SendDemo.java
src/main/java/com/thinkgem/jeesite/modules/message/SendDemo.java
+104
-0
IdentityCodeRequest.java
src/main/java/com/thinkgem/jeesite/modules/user/bean/IdentityCodeRequest.java
+10
-0
UserApiService.java
src/main/java/com/thinkgem/jeesite/modules/user/service/UserApiService.java
+13
-2
youka.properties
src/main/resources/youka.properties
+8
-2
No files found.
src/main/java/com/thinkgem/jeesite/modules/message/MessageUtils.java
0 → 100644
View file @
dbb9c31c
package
com
.
thinkgem
.
jeesite
.
modules
.
message
;
import
com.alibaba.fastjson.JSONObject
;
import
com.thinkgem.jeesite.common.config.Global
;
import
com.thinkgem.jeesite.common.utils.IdGen
;
import
com.thinkgem.jeesite.modules.user.bean.IdentityCodeRequest
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.http.client.fluent.Request
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
/**
* @author niehh
* @Description: 短信工具类
* @date 2018年03月22日 13:54
*/
public
class
MessageUtils
{
public
static
JSONObject
sendMessage
(
String
mobile
,
String
code
,
String
message
)
throws
IOException
,
NoSuchAlgorithmException
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
timestamp
=
sdf
.
format
(
new
Date
());
// // 必须的验证参数
String
username
=
Global
.
getConfig
(
"message.username"
);
String
password
=
Global
.
getConfig
(
"message.password"
);
String
url
=
Global
.
getConfig
(
"message.url"
);
String
extendCode
=
code
;
int
dataCoding
=
15
;
// UNICODE 编码
int
responseFormat
=
2
;
// 返回格式为 Json 格式
long
externalId
=
0x123456789
L
;
// 自定义消int dataCoding = 8; // UNICODE 编码
int
transferEncoding
=
3
;
// URLEncode+UTFint responseFormat = 2; // 返回格式为 Json 格String message = "这是一条测试短信,返回 J// 计算密码摘要
// SimpleDateFormat sdf = new SimpleDateFormString timestamp = sdf.format(new Date() );
MessageDigest
md5
=
null
;
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
md5
.
update
(
username
.
getBytes
(
"utf8"
)
);
md5
.
update
(
password
.
getBytes
(
"utf8"
)
);
md5
.
update
(
timestamp
.
getBytes
(
"utf8"
)
);
md5
.
update
(
message
.
getBytes
(
"utf8"
)
);
password
=
Base64
.
encodeBase64String
(
md5
.
digest
()
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
url
)
.
append
(
"?un="
).
append
(
username
)
.
append
(
"&pw="
).
append
(
URLEncoder
.
encode
(
password
,
"utf8"
)
)
.
append
(
"&ts="
).
append
(
timestamp
)
.
append
(
"&da="
).
append
(
mobile
)
.
append
(
"&sa="
).
append
(
extendCode
)
.
append
(
"&ex="
).
append
(
externalId
)
.
append
(
"&dc="
).
append
(
dataCoding
)
.
append
(
"&tf="
).
append
(
transferEncoding
)
.
append
(
"&rf="
).
append
(
responseFormat
)
.
append
(
"&sm="
).
append
(
URLEncoder
.
encode
(
message
,
"utf8"
)
);
String
req
=
sb
.
toString
();
System
.
out
.
println
(
"request: "
+
req
);
// 以GET方式发起请求
String
result
=
Request
.
Get
(
req
).
execute
().
returnContent
().
asString
();
System
.
out
.
println
(
"response: "
+
result
);
return
JSONObject
.
parseObject
(
result
);
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
NoSuchAlgorithmException
{
IdentityCodeRequest
request
=
new
IdentityCodeRequest
();
request
.
setMobile
(
"13722537737"
);
request
.
setMessage
(
"验证码:{1}"
);
// 生成验证码
String
identifyCode
=
IdGen
.
randomBase62
(
6
).
toUpperCase
();
// 发送验证码
if
(
request
.
getMessage
()
!=
null
){
request
.
setMessage
(
request
.
getMessage
().
replace
(
"{1}"
,
identifyCode
));
}
else
{
request
.
setMessage
(
"验证码:"
+
identifyCode
);
}
MessageUtils
.
sendMessage
(
"13722537737"
,
"28"
,
request
.
getMessage
());
}
}
src/main/java/com/thinkgem/jeesite/modules/message/ReceiveServlet.java
0 → 100644
View file @
dbb9c31c
package
com
.
thinkgem
.
jeesite
.
modules
.
message
;
import
java.io.IOException
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.codec.DecoderException
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.lang.math.NumberUtils
;
/**
* HTTP方式接收状态报告的方式, 请部署到tomcat
* 并对web.xml作适当配置
*/
public
class
ReceiveServlet
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
0x1
L
;
private
byte
[]
decodeBytes
(
String
s
)
{
if
(
s
==
null
)
return
new
byte
[
0
];
try
{
return
Hex
.
decodeHex
(
s
.
toCharArray
());
}
catch
(
DecoderException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
String
decodeMessage
(
int
dc
,
byte
[]
buf
)
{
if
(
buf
==
null
)
return
""
;
try
{
// 这里只解码了8
if
(
dc
==
8
)
return
new
String
(
buf
,
"UTF-16BE"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
new
String
(
buf
);
}
/**
* 服务器通过GET方式向客户端投递状态报告和上行
*/
@Override
protected
void
doGet
(
HttpServletRequest
req
,
HttpServletResponse
resp
)
throws
ServletException
,
IOException
{
// 输出请求信息
System
.
out
.
println
(
req
.
getQueryString
());
String
op
=
req
.
getParameter
(
"op"
);
if
(
"mo"
.
equals
(
op
))
{
// 上行信息
int
dc
=
NumberUtils
.
toInt
(
req
.
getParameter
(
"dc"
));
String
mobile
=
req
.
getParameter
(
"sa"
);
String
extendCode
=
req
.
getParameter
(
"da"
);
byte
[]
data
=
decodeBytes
(
req
.
getParameter
(
"sm"
));
String
message
=
decodeMessage
(
dc
,
data
);
// 业务处理
onReceiveMO
(
extendCode
,
mobile
,
message
);
}
else
if
(
"dr"
.
equals
(
op
))
{
// 状态报告
String
id
=
req
.
getParameter
(
"id"
);
String
status
=
req
.
getParameter
(
"su"
);
int
result
=
NumberUtils
.
toInt
(
req
.
getParameter
(
"rp"
),
9
);
// 业务处理
onReceiveReport
(
id
,
result
,
status
);
}
else
{
// 未定义,不会到达这里
}
resp
.
getWriter
().
write
(
"ok"
);
}
private
void
onReceiveMO
(
String
extendCode
,
String
mobile
,
String
message
)
{
// 请迅速返回,一般是放入内存后直接返回
System
.
out
.
println
(
"extendCode: "
+
extendCode
);
System
.
out
.
println
(
"mobile: "
+
mobile
);
System
.
out
.
println
(
"message: "
+
message
);
}
private
void
onReceiveReport
(
String
id
,
int
result
,
String
status
)
{
// 请迅速返回,一般是放入内存后直接返回
System
.
out
.
println
(
"id: "
+
id
);
System
.
out
.
println
(
"result: "
+
result
);
// 0 为成功,其他失败
System
.
out
.
println
(
"status: "
+
status
);
}
}
\ No newline at end of file
src/main/java/com/thinkgem/jeesite/modules/message/SendDemo.java
0 → 100644
View file @
dbb9c31c
package
com
.
thinkgem
.
jeesite
.
modules
.
message
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
com.thinkgem.jeesite.common.config.Global
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.http.client.fluent.Request
;
/**
* 演示明码发送短信,不建议在生产环境使用。但可以在浏览器上手动测试
*/
public
class
SendDemo
{
// public static void main(String[] args) throws Exception {
//
// // ====================================================================
// // 本例子只是用于演示,请不要在实际生产中使用
// // ====================================================================
//
// // 必须的验证参数
// String username = Global.getConfig("message.username");
// String password = Global.getConfig("message.password");
// String url = Global.getConfig("message.url");
//
// // 短信相关的必须参数
// String mobile = "13722537737";
// String extendCode = "4443";
// String message = "测试明码验证,不安全【XX公司】";
//
// // 装配GET所需的参数
// StringBuilder sb = new StringBuilder(2000);
// sb.append(url);
// sb.append("?dc=15"); // 表明发送的是中文
// sb.append("&sm=").append( URLEncoder.encode(message, "utf8") );
// sb.append("&da=").append( mobile );
// sb.append("&sa=").append( extendCode );
// sb.append("&un=").append( username );
// sb.append("&pw=").append(URLEncoder.encode(password,"utf8") ); // 这里采用明码验证方式,不安全;签名方式请参看SendWithSign
// sb.append("&tf=3"); // 表示短信内容为 urlencode+utf8
//
//
// String request = sb.toString();
// System.out.println( request );
//
// // 以GET方式发起请求
// String result = Request.Get( request ).execute().returnContent().asString();
//
// System.out.println( result );
// }
public
static
void
main
(
String
[]
args
)
throws
NoSuchAlgorithmException
,
IOException
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
timestamp
=
sdf
.
format
(
new
Date
());
// // 必须的验证参数
String
username
=
Global
.
getConfig
(
"message.username"
);
String
password
=
Global
.
getConfig
(
"message.password"
);
String
url
=
Global
.
getConfig
(
"message.url"
);
// 短信相关的必须参数
String
mobile
=
"13722537737"
;
String
extendCode
=
"4443"
;
String
message
=
"测试明码验证,不安全【XX公司】"
;
int
dataCoding
=
15
;
// UNICODE 编码
int
responseFormat
=
2
;
// 返回格式为 Json 格式
long
externalId
=
0x123456789
L
;
// 自定义消int dataCoding = 8; // UNICODE 编码
int
transferEncoding
=
3
;
// URLEncode+UTFint responseFormat = 2; // 返回格式为 Json 格String message = "这是一条测试短信,返回 J// 计算密码摘要
// SimpleDateFormat sdf = new SimpleDateFormString timestamp = sdf.format(new Date() );
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
md5
.
update
(
username
.
getBytes
(
"utf8"
)
);
md5
.
update
(
password
.
getBytes
(
"utf8"
)
);
md5
.
update
(
timestamp
.
getBytes
(
"utf8"
)
);
md5
.
update
(
message
.
getBytes
(
"utf8"
)
);
password
=
Base64
.
encodeBase64String
(
md5
.
digest
()
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
url
)
.
append
(
"?un="
).
append
(
username
)
.
append
(
"&pw="
).
append
(
URLEncoder
.
encode
(
password
,
"utf8"
)
)
.
append
(
"&ts="
).
append
(
timestamp
)
.
append
(
"&da="
).
append
(
mobile
)
.
append
(
"&sa="
).
append
(
extendCode
)
.
append
(
"&ex="
).
append
(
externalId
)
.
append
(
"&dc="
).
append
(
dataCoding
)
.
append
(
"&tf="
).
append
(
transferEncoding
)
.
append
(
"&rf="
).
append
(
responseFormat
)
.
append
(
"&sm="
).
append
(
URLEncoder
.
encode
(
message
,
"utf8"
)
);
String
req
=
sb
.
toString
();
System
.
out
.
println
(
"request: "
+
req
);
// 以GET方式发起请求
String
result
=
Request
.
Get
(
req
).
execute
().
returnContent
().
asString
();
System
.
out
.
println
(
"response: "
+
result
);
}
}
src/main/java/com/thinkgem/jeesite/modules/user/bean/IdentityCodeRequest.java
View file @
dbb9c31c
...
...
@@ -6,6 +6,8 @@ public class IdentityCodeRequest extends Request {
private
String
function
;
// 请求验证码的功能
private
String
mobile
;
// 手机号
private
String
message
;
public
String
getFunction
()
{
return
function
;
}
...
...
@@ -21,4 +23,12 @@ public class IdentityCodeRequest extends Request {
public
void
setMobile
(
String
mobile
)
{
this
.
mobile
=
mobile
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
src/main/java/com/thinkgem/jeesite/modules/user/service/UserApiService.java
View file @
dbb9c31c
...
...
@@ -7,6 +7,7 @@ import com.thinkgem.jeesite.common.constant.ComCode;
import
com.thinkgem.jeesite.common.utils.IdGen
;
import
com.thinkgem.jeesite.common.utils.MD5
;
import
com.thinkgem.jeesite.modules.commonError.MyException
;
import
com.thinkgem.jeesite.modules.message.MessageUtils
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.dto.MerchantDto
;
import
com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayService
;
import
com.thinkgem.jeesite.modules.pay.entity.RateEntity
;
...
...
@@ -19,7 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -47,10 +50,18 @@ public class UserApiService {
}
@Transactional
(
readOnly
=
false
)
public
String
getIdentifyCode
(
IdentityCodeRequest
request
)
{
public
String
getIdentifyCode
(
IdentityCodeRequest
request
)
throws
IOException
,
NoSuchAlgorithmException
{
// 生成验证码
String
identifyCode
=
IdGen
.
randomBase62
(
6
).
toUpperCase
();
// TODO 发送验证码
// 发送验证码
if
(
request
.
getMessage
()
!=
null
){
request
.
setMessage
(
request
.
getMessage
().
replace
(
"{1}"
,
identifyCode
));
}
else
{
request
.
setMessage
(
"验证码:"
+
identifyCode
);
}
MessageUtils
.
sendMessage
(
request
.
getMobile
(),
"28"
,
request
.
getMessage
());
// 验证码入库
IdentityCodeEntity
identityCodeEntity
=
new
IdentityCodeEntity
(
IdGen
.
randomBase62
(
64
),
request
.
getFunction
(),
request
.
getMobile
(),
identifyCode
);
userDao
.
saveIdentifyCode
(
identityCodeEntity
);
...
...
src/main/resources/youka.properties
View file @
dbb9c31c
...
...
@@ -102,4 +102,10 @@ image.save.url=/data/youka/image/
#图片返回路径
image.return.url
=
youka-api/image/
#ali接口获取银行logo
logo.bank.url
=
https://apimg.alipay.com/combo.png?d=cashier&t=
\ No newline at end of file
logo.bank.url
=
https://apimg.alipay.com/combo.png?d=cashier&t=
## 短信相关
message.username
=
710047
message.password
=
HY1034ZY
message.url
=
http://122.144.179.5:7891/mt
\ No newline at end of file
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