Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
tjmdp
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
other-project
tjmdp
Commits
54084114
Commit
54084114
authored
Mar 30, 2019
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改工程,增加小程序第三方包参及几个DEMO接口
parent
53f97cc1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
919 additions
and
30 deletions
+919
-30
pom.xml
pom.xml
+62
-29
WxMaConfiguration.java
src/main/java/com/qiankun/config/WxMaConfiguration.java
+152
-0
WxMaProperties.java
src/main/java/com/qiankun/config/WxMaProperties.java
+101
-0
RainbowPlanController.java
...qiankun/controller/rainbowplan/RainbowPlanController.java
+210
-0
JwtTokenUtil.java
src/main/java/com/qiankun/utils/JwtTokenUtil.java
+128
-0
LoginReqVo.java
src/main/java/com/qiankun/vo/LoginReqVo.java
+49
-0
PublishWish.java
src/main/java/com/qiankun/vo/PublishWish.java
+43
-0
RegisterInfo.java
src/main/java/com/qiankun/vo/RegisterInfo.java
+49
-0
UserInfo.java
src/main/java/com/qiankun/vo/UserInfo.java
+115
-0
spring-beans.xml
src/main/resources/spring-beans.xml
+3
-1
system.properties
src/main/resources/system.properties
+7
-0
login_bg.png
src/main/webapp/resources/images/login_bg.png
+0
-0
No files found.
pom.xml
View file @
54084114
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
<dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.
2.1
</version>
<version>
3.
7
</version>
</dependency>
</dependency>
<dependency>
<dependency>
...
@@ -100,12 +100,12 @@
...
@@ -100,12 +100,12 @@
<version>
2.2
</version>
<version>
2.2
</version>
</dependency>
</dependency>
<
dependency
>
<
!--<dependency>--
>
<
groupId>
net.sf.json-lib
</groupId
>
<
!--<groupId>net.sf.json-lib</groupId>--
>
<
artifactId>
json-lib
</artifactId
>
<
!--<artifactId>json-lib</artifactId>--
>
<
classifier>
jdk15
</classifier
>
<
!--<classifier>jdk15</classifier>--
>
<
version>
2.4
</version
>
<
!--<version>2.4</version>--
>
<
/dependency
>
<
!--</dependency>--
>
...
@@ -116,11 +116,11 @@
...
@@ -116,11 +116,11 @@
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<
dependency
>
<
!--<dependency>--
>
<
groupId>
org.codehaus.jackson
</groupId
>
<
!--<groupId>org.codehaus.jackson</groupId>--
>
<
artifactId>
jackson-mapper-asl
</artifactId
>
<
!--<artifactId>jackson-mapper-asl</artifactId>--
>
<
version>
1.9.13
</version
>
<
!--<version>1.9.13</version>--
>
<
/dependency
>
<
!--</dependency>--
>
<dependency>
<dependency>
<groupId>
commons-dbcp
</groupId>
<groupId>
commons-dbcp
</groupId>
...
@@ -128,12 +128,12 @@
...
@@ -128,12 +128,12 @@
<version>
1.4
</version>
<version>
1.4
</version>
</dependency>
</dependency>
<
dependency
>
<
!--<dependency>--
>
<
groupId>
org.apache.httpcomponents
</groupId
>
<
!--<groupId>org.apache.httpcomponents</groupId>--
>
<
artifactId>
httpclient
</artifactId
>
<
!--<artifactId>httpclient</artifactId>--
>
<
version>
4.3.2
</version
>
<
!--<version>4.3.2</version>--
>
<
scope>
test
</scope
>
<
!--<scope>test</scope>--
>
<
/dependency
>
<
!--</dependency>--
>
<dependency>
<dependency>
<groupId>
opensymphony
</groupId>
<groupId>
opensymphony
</groupId>
...
@@ -160,17 +160,17 @@
...
@@ -160,17 +160,17 @@
<version>
1.3.1
</version>
<version>
1.3.1
</version>
</dependency>
</dependency>
<
dependency
>
<
!--<dependency>--
>
<
groupId>
com.sun.mail
</groupId
>
<
!--<groupId>com.sun.mail</groupId>--
>
<
artifactId>
javax.mail
</artifactId
>
<
!--<artifactId>javax.mail</artifactId>--
>
<
version>
1.5.1
</version
>
<
!--<version>1.5.1</version>--
>
<
/dependency
>
<
!--</dependency>--
>
<
dependency
>
<
!--<dependency>--
>
<
groupId>
org.apache.httpcomponents
</groupId
>
<
!--<groupId>org.apache.httpcomponents</groupId>--
>
<
artifactId>
httpmime
</artifactId
>
<
!--<artifactId>httpmime</artifactId>--
>
<
version>
4.3.2
</version
>
<
!--<version>4.3.2</version>--
>
<
/dependency
>
<
!--</dependency>--
>
<dependency>
<dependency>
...
@@ -202,6 +202,31 @@
...
@@ -202,6 +202,31 @@
<artifactId>
javax.mail
</artifactId>
<artifactId>
javax.mail
</artifactId>
<version>
1.5.1
</version>
<version>
1.5.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.github.binarywang
</groupId>
<artifactId>
weixin-java-miniapp
</artifactId>
<version>
3.3.0
</version>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
<version>
0.9.0
</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.apache.httpcomponents</groupId>-->
<!--<artifactId>httpclient</artifactId>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-logging</artifactId>-->
<!--<groupId>commons-logging</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.httpcomponents</groupId>-->
<!--<artifactId>httpmime</artifactId>-->
<!--</dependency>-->
<dependency>
<dependency>
<groupId>
junit
</groupId>
<groupId>
junit
</groupId>
...
@@ -228,6 +253,14 @@
...
@@ -228,6 +253,14 @@
<groupId>
org.eclipse.jetty
</groupId>
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-maven-plugin
</artifactId>
<artifactId>
jetty-maven-plugin
</artifactId>
</plugin>
</plugin>
</plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
8
</source>
<target>
8
</target>
</configuration>
</plugin>
</plugins>
</build>
</build>
</project>
</project>
src/main/java/com/qiankun/config/WxMaConfiguration.java
0 → 100755
View file @
54084114
package
com
.
qiankun
.
config
;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl
;
import
cn.binarywang.wx.miniapp.bean.WxMaKefuMessage
;
import
cn.binarywang.wx.miniapp.bean.WxMaMessage
;
import
cn.binarywang.wx.miniapp.bean.WxMaTemplateData
;
import
cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage
;
import
cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig
;
import
cn.binarywang.wx.miniapp.message.WxMaMessageHandler
;
import
cn.binarywang.wx.miniapp.message.WxMaMessageRouter
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
me.chanjar.weixin.common.bean.result.WxMediaUploadResult
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
me.chanjar.weixin.common.session.WxSessionManager
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Configuration
public
class
WxMaConfiguration
{
private
final
WxMaMessageHandler
templateMsgHandler
=
new
WxMaMessageHandler
()
{
public
void
handle
(
WxMaMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMaService
service
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
service
.
getMsgService
().
sendTemplateMsg
(
WxMaTemplateMessage
.
builder
()
.
templateId
(
"此处更换为自己的模板id"
)
.
formId
(
"自己替换可用的formid"
)
.
data
(
Lists
.
newArrayList
(
new
WxMaTemplateData
(
"keyword1"
,
"339208499"
,
"#173177"
)))
.
toUser
(
wxMessage
.
getFromUser
())
.
build
());
}
};
private
final
WxMaMessageHandler
logHandler
=
new
WxMaMessageHandler
()
{
public
void
handle
(
WxMaMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMaService
service
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
System
.
out
.
println
(
"收到消息:"
+
wxMessage
.
toString
());
service
.
getMsgService
().
sendKefuMsg
(
WxMaKefuMessage
.
newTextBuilder
().
content
(
"收到信息为:"
+
wxMessage
.
toJson
())
.
toUser
(
wxMessage
.
getFromUser
()).
build
());
}
};
private
final
WxMaMessageHandler
textHandler
=
new
WxMaMessageHandler
()
{
public
void
handle
(
WxMaMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMaService
service
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
service
.
getMsgService
().
sendKefuMsg
(
WxMaKefuMessage
.
newTextBuilder
().
content
(
"回复文本消息"
)
.
toUser
(
wxMessage
.
getFromUser
()).
build
());
}
};
private
final
WxMaMessageHandler
picHandler
=
new
WxMaMessageHandler
()
{
public
void
handle
(
WxMaMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMaService
service
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
try
{
WxMediaUploadResult
uploadResult
=
service
.
getMediaService
()
.
uploadMedia
(
"image"
,
"png"
,
ClassLoader
.
getSystemResourceAsStream
(
"tmp.png"
));
service
.
getMsgService
().
sendKefuMsg
(
WxMaKefuMessage
.
newImageBuilder
()
.
mediaId
(
uploadResult
.
getMediaId
())
.
toUser
(
wxMessage
.
getFromUser
())
.
build
());
}
catch
(
WxErrorException
e
)
{
e
.
printStackTrace
();
}
}
};
private
final
WxMaMessageHandler
qrcodeHandler
=
new
WxMaMessageHandler
()
{
public
void
handle
(
WxMaMessage
wxMessage
,
Map
<
String
,
Object
>
context
,
WxMaService
service
,
WxSessionManager
sessionManager
)
throws
WxErrorException
{
try
{
final
File
file
=
service
.
getQrcodeService
().
createQrcode
(
"123"
,
430
);
WxMediaUploadResult
uploadResult
=
service
.
getMediaService
().
uploadMedia
(
"image"
,
file
);
service
.
getMsgService
().
sendKefuMsg
(
WxMaKefuMessage
.
newImageBuilder
()
.
mediaId
(
uploadResult
.
getMediaId
())
.
toUser
(
wxMessage
.
getFromUser
())
.
build
());
}
catch
(
WxErrorException
e
)
{
e
.
printStackTrace
();
}
}
};
@Autowired
private
WxMaProperties
properties
;
private
static
Map
<
String
,
WxMaMessageRouter
>
routers
=
Maps
.
newHashMap
();
private
static
Map
<
String
,
WxMaService
>
maServices
=
Maps
.
newHashMap
();
// public WxMaConfiguration(WxMaProperties properties) {
// this.properties = properties;
// }
public
static
Map
<
String
,
WxMaMessageRouter
>
getRouters
()
{
return
routers
;
}
public
static
WxMaService
getMaService
(
String
appid
)
{
WxMaService
wxService
=
maServices
.
get
(
appid
);
if
(
wxService
==
null
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"未找到对应appid=[%s]的配置,请核实!"
,
appid
));
}
return
wxService
;
}
// public WxMaConfiguration(){
// this.properties = new WxMaProperties();
// }
@Bean
public
Object
services
()
{
maServices
=
this
.
properties
.
getConfigs
()
.
stream
()
.
map
(
a
->
{
WxMaInMemoryConfig
config
=
new
WxMaInMemoryConfig
();
config
.
setAppid
(
a
.
getAppid
());
config
.
setSecret
(
a
.
getSecret
());
config
.
setToken
(
a
.
getToken
());
config
.
setAesKey
(
a
.
getAesKey
());
config
.
setMsgDataFormat
(
a
.
getMsgDataFormat
());
WxMaService
service
=
new
WxMaServiceImpl
();
service
.
setWxMaConfig
(
config
);
routers
.
put
(
a
.
getAppid
(),
this
.
newRouter
(
service
));
return
service
;
}).
collect
(
Collectors
.
toMap
(
s
->
s
.
getWxMaConfig
().
getAppid
(),
a
->
a
));
return
Boolean
.
TRUE
;
}
private
WxMaMessageRouter
newRouter
(
WxMaService
service
)
{
final
WxMaMessageRouter
router
=
new
WxMaMessageRouter
(
service
);
router
.
rule
().
handler
(
logHandler
).
next
()
.
rule
().
async
(
false
).
content
(
"模板"
).
handler
(
templateMsgHandler
).
end
()
.
rule
().
async
(
false
).
content
(
"文本"
).
handler
(
textHandler
).
end
()
.
rule
().
async
(
false
).
content
(
"图片"
).
handler
(
picHandler
).
end
()
.
rule
().
async
(
false
).
content
(
"二维码"
).
handler
(
qrcodeHandler
).
end
();
return
router
;
}
}
src/main/java/com/qiankun/config/WxMaProperties.java
0 → 100755
View file @
54084114
package
com
.
qiankun
.
config
;
import
com.google.common.collect.Lists
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.ResourceBundle
;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Component
public
class
WxMaProperties
{
private
List
<
Config
>
configs
;
public
List
<
Config
>
getConfigs
()
{
return
configs
;
}
public
void
setConfigs
(
List
<
Config
>
configs
)
{
this
.
configs
=
configs
;
}
public
WxMaProperties
(){
ResourceBundle
rb
=
ResourceBundle
.
getBundle
(
"system"
);
Config
config
=
new
Config
();
config
.
setAppid
(
rb
.
getString
(
"rainbowplan.appid"
));
config
.
setSecret
(
rb
.
getString
(
"rainbowplan.secret"
));
configs
=
Lists
.
newArrayList
();
configs
.
add
(
config
);
}
public
static
class
Config
{
/**
* 设置微信小程序的appid
*/
private
String
appid
;
/**
* 设置微信小程序的Secret
*/
private
String
secret
;
/**
* 设置微信小程序消息服务器配置的token
*/
private
String
token
;
/**
* 设置微信小程序消息服务器配置的EncodingAESKey
*/
private
String
aesKey
;
/**
* 消息格式,XML或者JSON
*/
private
String
msgDataFormat
;
public
String
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
String
appid
)
{
this
.
appid
=
appid
;
}
public
String
getSecret
()
{
return
secret
;
}
public
void
setSecret
(
String
secret
)
{
this
.
secret
=
secret
;
}
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
String
getAesKey
()
{
return
aesKey
;
}
public
void
setAesKey
(
String
aesKey
)
{
this
.
aesKey
=
aesKey
;
}
public
String
getMsgDataFormat
()
{
return
msgDataFormat
;
}
public
void
setMsgDataFormat
(
String
msgDataFormat
)
{
this
.
msgDataFormat
=
msgDataFormat
;
}
}
}
src/main/java/com/qiankun/controller/rainbowplan/RainbowPlanController.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
controller
.
rainbowplan
;
import
cn.binarywang.wx.miniapp.api.WxMaService
;
import
cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.qiankun.annotation.Auth
;
import
com.qiankun.config.WxMaConfiguration
;
import
com.qiankun.utils.JwtTokenUtil
;
import
com.qiankun.vo.PublishWish
;
import
com.qiankun.vo.RegisterInfo
;
import
com.qiankun.vo.UserInfo
;
import
me.chanjar.weixin.common.error.WxErrorException
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
@RestController
@RequestMapping
(
"/wx/rainbowplan/{appid}"
)
public
class
RainbowPlanController
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RainbowPlanController
.
class
);
private
static
Map
<
String
,
UserInfo
>
userInfoMap
=
Maps
.
newConcurrentMap
();
private
static
Map
<
String
,
List
<
PublishWish
>>
wishMap
=
Maps
.
newConcurrentMap
();
@Autowired
private
JwtTokenUtil
tokenUtil
;
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/validateExpired"
,
method
=
RequestMethod
.
GET
)
public
Map
<
String
,
Object
>
validateToken
(
@PathVariable
String
appid
,
@RequestHeader
(
"token"
)
String
token
){
Map
<
String
,
Object
>
result
=
Maps
.
newConcurrentMap
();
result
.
put
(
"result"
,
tokenUtil
.
isTokenExpired
(
token
));
return
result
;
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
GET
)
public
Map
<
String
,
String
>
login
(
@PathVariable
String
appid
,
@RequestParam
String
code
){
if
(
StringUtils
.
isBlank
(
code
))
{
return
null
;
}
final
WxMaService
wxService
=
WxMaConfiguration
.
getMaService
(
appid
);
try
{
WxMaJscode2SessionResult
session
=
wxService
.
getUserService
().
getSessionInfo
(
code
);
this
.
logger
.
info
(
session
.
getSessionKey
());
this
.
logger
.
info
(
session
.
getOpenid
());
Map
<
String
,
String
>
result
=
Maps
.
newConcurrentMap
();
//TODO 判断openid是否在数据库中存在
if
(
userInfoMap
.
containsKey
(
session
.
getOpenid
())){
//生成sKey
String
sKey
=
tokenUtil
.
generateToken
(
session
.
getOpenid
());
// result.put("session",session);
result
.
put
(
"sKey"
,
sKey
);
}
else
{
result
.
put
(
"sKey"
,
""
);
}
result
.
put
(
"openid"
,
session
.
getOpenid
());
return
result
;
}
catch
(
WxErrorException
e
)
{
this
.
logger
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/register"
,
method
=
RequestMethod
.
POST
)
public
String
register
(
@PathVariable
String
appid
,
@RequestBody
RegisterInfo
info
){
if
(
Strings
.
isNullOrEmpty
(
info
.
getOpenid
())){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setUid
(
UUID
.
randomUUID
().
toString
());
userInfo
.
setPhone
(
info
.
getPhone
());
userInfo
.
setName
(
info
.
getName
());
userInfo
.
setGender
(
info
.
getGender
());
userInfoMap
.
put
(
info
.
getOpenid
(),
userInfo
);
return
tokenUtil
.
generateToken
(
info
.
getOpenid
());
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/userInfo"
,
method
=
RequestMethod
.
GET
)
public
UserInfo
getUserInfo
(
@PathVariable
String
appid
,
@RequestHeader
String
sKey
)
throws
Exception
{
if
(
Strings
.
isNullOrEmpty
(
sKey
)){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
String
openid
=
tokenUtil
.
getUsernameFromToken
(
sKey
);
if
(!
userInfoMap
.
containsKey
(
openid
))
{
throw
new
Exception
(
"请求的用户不存在"
);
}
return
userInfoMap
.
get
(
openid
);
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/userInfo"
,
method
=
RequestMethod
.
POST
)
public
String
updateUserInfo
(
@PathVariable
String
appid
,
@RequestBody
UserInfo
info
,
@RequestHeader
String
sKey
){
if
(
Strings
.
isNullOrEmpty
(
sKey
)){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
String
openid
=
tokenUtil
.
getUsernameFromToken
(
sKey
);
UserInfo
userInfo
=
findUserInfo
(
openid
);
userInfo
.
setName
(
info
.
getName
());
userInfo
.
setNickName
(
info
.
getNickName
());
userInfo
.
setPhone
(
info
.
getPhone
());
userInfo
.
setGender
(
info
.
getGender
());
userInfo
.
setBirthday
(
info
.
getBirthday
());
userInfo
.
setBedNum
(
info
.
getBedNum
());
userInfo
.
setReceiveName
(
info
.
getReceiveName
());
userInfo
.
setConnectTel
(
info
.
getConnectTel
());
userInfo
.
setReceiveAddress
(
info
.
getReceiveAddress
());
userInfo
.
setAvatar
(
info
.
getAvatar
());
return
"OK"
;
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/userInfoWithAvatar"
,
method
=
RequestMethod
.
POST
)
public
String
updateUserInfoWithAvatar
(
@PathVariable
String
appid
,
UserInfo
info
,
@RequestHeader
String
sKey
)
throws
IOException
{
if
(
Strings
.
isNullOrEmpty
(
sKey
)){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
String
openid
=
tokenUtil
.
getUsernameFromToken
(
sKey
);
UserInfo
userInfo
=
findUserInfo
(
openid
);
if
(!
info
.
getFile
().
isEmpty
()){
// BASE64Encoder encoder = new BASE64Encoder();
// String imageData = encoder.encode(info.getFile().getBytes());
String
originalFileName
=
info
.
getFile
().
getOriginalFilename
();
String
path
=
"/Users/liuyang/uploadImage"
;
File
destFile
=
new
File
(
path
,
originalFileName
);
FileUtils
.
writeByteArrayToFile
(
destFile
,
info
.
getFile
().
getBytes
());
userInfo
.
setName
(
info
.
getName
());
userInfo
.
setNickName
(
info
.
getNickName
());
userInfo
.
setPhone
(
info
.
getPhone
());
userInfo
.
setGender
(
info
.
getGender
());
userInfo
.
setBirthday
(
info
.
getBirthday
());
userInfo
.
setBedNum
(
info
.
getBedNum
());
userInfo
.
setReceiveName
(
info
.
getReceiveName
());
userInfo
.
setConnectTel
(
info
.
getConnectTel
());
userInfo
.
setReceiveAddress
(
info
.
getReceiveAddress
());
userInfo
.
setAvatar
(
info
.
getAvatar
());
userInfo
.
setAvatar
(
originalFileName
);
}
return
"OK"
;
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/publishWish"
,
method
=
RequestMethod
.
POST
)
public
String
publishWish
(
@PathVariable
String
appid
,
PublishWish
publishWish
,
@RequestHeader
String
sKey
)
throws
IOException
{
if
(
Strings
.
isNullOrEmpty
(
sKey
)){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
String
openid
=
tokenUtil
.
getUsernameFromToken
(
sKey
);
if
(!
publishWish
.
getFile
().
isEmpty
()){
// BASE64Encoder encoder = new BASE64Encoder();
// String imageData = encoder.encode(info.getFile().getBytes());
String
originalFileName
=
publishWish
.
getFile
().
getOriginalFilename
();
String
path
=
"/Users/liuyang/uploadImage"
;
File
destFile
=
new
File
(
path
,
originalFileName
);
FileUtils
.
writeByteArrayToFile
(
destFile
,
publishWish
.
getFile
().
getBytes
());
List
<
PublishWish
>
wishList
=
Lists
.
newArrayList
();
if
(
wishMap
.
containsKey
(
openid
)){
wishList
=
wishMap
.
get
(
openid
);
}
PublishWish
wish
=
new
PublishWish
();
wish
.
setTitle
(
publishWish
.
getTitle
());
wish
.
setWish
(
publishWish
.
getWish
());
wish
.
setWishImage
(
originalFileName
);
wishList
.
add
(
wish
);
wishMap
.
put
(
openid
,
wishList
);
}
return
"OK"
;
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/wish/list"
,
method
=
RequestMethod
.
GET
)
public
List
<
PublishWish
>
wishList
(
@PathVariable
String
appid
,
@RequestHeader
String
sKey
){
if
(
Strings
.
isNullOrEmpty
(
sKey
)){
throw
new
IllegalArgumentException
(
"请求参数错误"
);
}
String
openid
=
tokenUtil
.
getUsernameFromToken
(
sKey
);
return
wishMap
.
get
(
openid
);
}
private
UserInfo
findUserInfo
(
String
openid
){
return
userInfoMap
.
get
(
openid
);
}
@Auth
(
verifyLogin
=
false
,
verifyURL
=
false
)
@RequestMapping
(
value
=
"/loadResource"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
byte
[]>
loadResource
(
@RequestParam
String
imageName
)
throws
IOException
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
File
file
=
new
File
(
"/Users/liuyang/uploadImage"
,
imageName
);
return
new
ResponseEntity
<>(
FileUtils
.
readFileToByteArray
(
file
),
headers
,
HttpStatus
.
OK
);
}
}
src/main/java/com/qiankun/utils/JwtTokenUtil.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
utils
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
@Component
public
class
JwtTokenUtil
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3301605591108950415L
;
private
static
final
String
CLAIM_KEY_USERNAME
=
"sub"
;
private
static
final
String
CLAIM_KEY_CREATED
=
"created"
;
private
String
secret
=
"ArgusMiniAppRainbowPlan"
;
private
Long
expiration
=
604800
l
;
public
String
getUsernameFromToken
(
String
token
)
{
String
username
;
try
{
final
Claims
claims
=
getClaimsFromToken
(
token
);
username
=
claims
.
getSubject
();
}
catch
(
Exception
e
)
{
username
=
null
;
}
return
username
;
}
public
Date
getCreatedDateFromToken
(
String
token
)
{
Date
created
;
try
{
final
Claims
claims
=
getClaimsFromToken
(
token
);
created
=
new
Date
((
Long
)
claims
.
get
(
CLAIM_KEY_CREATED
));
}
catch
(
Exception
e
)
{
created
=
null
;
}
return
created
;
}
public
Date
getExpirationDateFromToken
(
String
token
)
{
Date
expiration
;
try
{
final
Claims
claims
=
getClaimsFromToken
(
token
);
expiration
=
claims
.
getExpiration
();
}
catch
(
Exception
e
)
{
expiration
=
null
;
}
return
expiration
;
}
private
Claims
getClaimsFromToken
(
String
token
)
{
Claims
claims
;
try
{
claims
=
Jwts
.
parser
()
.
setSigningKey
(
secret
)
.
parseClaimsJws
(
token
)
.
getBody
();
}
catch
(
Exception
e
)
{
claims
=
null
;
}
return
claims
;
}
private
Date
generateExpirationDate
()
{
return
new
Date
(
System
.
currentTimeMillis
()
+
expiration
*
1000
);
}
public
Boolean
isTokenExpired
(
String
token
)
{
final
Date
expiration
=
getExpirationDateFromToken
(
token
);
return
expiration
.
before
(
new
Date
());
}
private
Boolean
isCreatedBeforeLastPasswordReset
(
Date
created
,
Date
lastPasswordReset
)
{
return
(
lastPasswordReset
!=
null
&&
created
.
before
(
lastPasswordReset
));
}
public
String
generateToken
(
String
openId
)
{
Map
<
String
,
Object
>
claims
=
new
HashMap
<>();
claims
.
put
(
CLAIM_KEY_USERNAME
,
openId
);
claims
.
put
(
CLAIM_KEY_CREATED
,
new
Date
());
return
generateToken
(
claims
);
}
String
generateToken
(
Map
<
String
,
Object
>
claims
)
{
return
Jwts
.
builder
()
.
setClaims
(
claims
)
.
setExpiration
(
generateExpirationDate
())
.
signWith
(
SignatureAlgorithm
.
HS512
,
secret
)
.
compact
();
}
public
Boolean
canTokenBeRefreshed
(
String
token
,
Date
lastPasswordReset
)
{
final
Date
created
=
getCreatedDateFromToken
(
token
);
return
!
isCreatedBeforeLastPasswordReset
(
created
,
lastPasswordReset
)
&&
!
isTokenExpired
(
token
);
}
public
String
refreshToken
(
String
token
)
{
String
refreshedToken
;
try
{
final
Claims
claims
=
getClaimsFromToken
(
token
);
claims
.
put
(
CLAIM_KEY_CREATED
,
new
Date
());
refreshedToken
=
generateToken
(
claims
);
}
catch
(
Exception
e
)
{
refreshedToken
=
null
;
}
return
refreshedToken
;
}
public
Boolean
validateToken
(
String
token
,
String
openId
)
{
final
String
username
=
getUsernameFromToken
(
token
);
// final Date created = getCreatedDateFromToken(token);
// final Date expiration = getExpirationDateFromToken(token);
return
(
username
.
equals
(
openId
)
&&
!
isTokenExpired
(
token
));
}
}
src/main/java/com/qiankun/vo/LoginReqVo.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
vo
;
public
class
LoginReqVo
{
private
String
code
;
private
String
signature
;
private
String
rawData
;
private
String
encryptedData
;
private
String
iv
;
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getSignature
()
{
return
signature
;
}
public
void
setSignature
(
String
signature
)
{
this
.
signature
=
signature
;
}
public
String
getRawData
()
{
return
rawData
;
}
public
void
setRawData
(
String
rawData
)
{
this
.
rawData
=
rawData
;
}
public
String
getEncryptedData
()
{
return
encryptedData
;
}
public
void
setEncryptedData
(
String
encryptedData
)
{
this
.
encryptedData
=
encryptedData
;
}
public
String
getIv
()
{
return
iv
;
}
public
void
setIv
(
String
iv
)
{
this
.
iv
=
iv
;
}
}
src/main/java/com/qiankun/vo/PublishWish.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
vo
;
import
org.springframework.web.multipart.MultipartFile
;
public
class
PublishWish
{
public
String
title
;
public
String
wish
;
public
String
wishImage
;
public
MultipartFile
file
;
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getWish
()
{
return
wish
;
}
public
void
setWish
(
String
wish
)
{
this
.
wish
=
wish
;
}
public
String
getWishImage
()
{
return
wishImage
;
}
public
void
setWishImage
(
String
wishImage
)
{
this
.
wishImage
=
wishImage
;
}
public
MultipartFile
getFile
()
{
return
file
;
}
public
void
setFile
(
MultipartFile
file
)
{
this
.
file
=
file
;
}
}
src/main/java/com/qiankun/vo/RegisterInfo.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
vo
;
public
class
RegisterInfo
{
public
String
name
;
public
String
phone
;
public
String
gender
;
public
String
openid
;
public
String
inviter
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
public
String
getGender
()
{
return
gender
;
}
public
void
setGender
(
String
gender
)
{
this
.
gender
=
gender
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
;
}
public
String
getInviter
()
{
return
inviter
;
}
public
void
setInviter
(
String
inviter
)
{
this
.
inviter
=
inviter
;
}
}
src/main/java/com/qiankun/vo/UserInfo.java
0 → 100644
View file @
54084114
package
com
.
qiankun
.
vo
;
import
org.springframework.web.multipart.MultipartFile
;
public
class
UserInfo
{
public
String
uid
;
public
String
phone
;
public
String
name
;
public
String
nickName
;
public
String
gender
;
public
String
birthday
;
public
String
bedNum
;
public
String
receiveName
;
public
String
connectTel
;
public
String
receiveAddress
;
public
String
avatar
;
public
MultipartFile
file
;
public
String
getUid
()
{
return
uid
;
}
public
void
setUid
(
String
uid
)
{
this
.
uid
=
uid
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getNickName
()
{
return
nickName
;
}
public
void
setNickName
(
String
nickName
)
{
this
.
nickName
=
nickName
;
}
public
String
getGender
()
{
return
gender
;
}
public
void
setGender
(
String
gender
)
{
this
.
gender
=
gender
;
}
public
String
getBirthday
()
{
return
birthday
;
}
public
void
setBirthday
(
String
birthday
)
{
this
.
birthday
=
birthday
;
}
public
String
getBedNum
()
{
return
bedNum
;
}
public
void
setBedNum
(
String
bedNum
)
{
this
.
bedNum
=
bedNum
;
}
public
String
getReceiveName
()
{
return
receiveName
;
}
public
void
setReceiveName
(
String
receiveName
)
{
this
.
receiveName
=
receiveName
;
}
public
String
getConnectTel
()
{
return
connectTel
;
}
public
void
setConnectTel
(
String
connectTel
)
{
this
.
connectTel
=
connectTel
;
}
public
String
getReceiveAddress
()
{
return
receiveAddress
;
}
public
void
setReceiveAddress
(
String
receiveAddress
)
{
this
.
receiveAddress
=
receiveAddress
;
}
public
String
getAvatar
()
{
return
avatar
;
}
public
void
setAvatar
(
String
avatar
)
{
this
.
avatar
=
avatar
;
}
public
MultipartFile
getFile
()
{
return
file
;
}
public
void
setFile
(
MultipartFile
file
)
{
this
.
file
=
file
;
}
}
src/main/resources/spring-beans.xml
View file @
54084114
...
@@ -74,7 +74,8 @@
...
@@ -74,7 +74,8 @@
<context:annotation-config
/>
<context:annotation-config
/>
<context:component-scan
<context:component-scan
base-package=
"com.qiankun.service,com.qiankun.dao"
/>
base-package=
"com.qiankun"
/>
</beans>
</beans>
\ No newline at end of file
src/main/resources/system.properties
View file @
54084114
...
@@ -4,3 +4,9 @@ file_path=D:/file/
...
@@ -4,3 +4,9 @@ file_path=D:/file/
account
=
admin
account
=
admin
password
=
passed
password
=
passed
rainbowplan.appid
=
wx7289ed9f69379a53
rainbowplan.secret
=
cc4df9e8a63d2b0faa2a25bbec79d2e3
rainbowplan.token
=
rainbowplan.aesKey
=
rainbowplan.msgDataFormat
:
JSON
\ No newline at end of file
src/main/webapp/resources/images/login_bg.png
0 → 100644
View file @
54084114
372 KB
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