Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
7597c60a
Commit
7597c60a
authored
Oct 21, 2018
by
Junling Bu
Browse files
feat[litemall-wx-api]: 小程序后台服务进一步校验参数
parent
637ee6c8
Changes
6
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java
View file @
7597c60a
...
...
@@ -9,6 +9,7 @@ import org.linlinjava.litemall.db.service.LitemallRegionService;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -124,6 +125,57 @@ public class WxAddressController {
return
ResponseUtil
.
ok
(
data
);
}
private
Object
validate
(
LitemallAddress
address
)
{
String
name
=
address
.
getName
();
if
(
StringUtils
.
isEmpty
(
name
)){
return
ResponseUtil
.
badArgument
();
}
// 测试收货手机号码是否正确
String
mobile
=
address
.
getMobile
();
if
(
StringUtils
.
isEmpty
(
mobile
)){
return
ResponseUtil
.
badArgument
();
}
if
(!
RegexUtil
.
isMobileExact
(
mobile
)){
return
ResponseUtil
.
badArgument
();
}
Integer
pid
=
address
.
getProvinceId
();
if
(
pid
==
null
){
return
ResponseUtil
.
badArgument
();
}
if
(
addressService
.
findById
(
pid
)
==
null
){
return
ResponseUtil
.
badArgumentValue
();
}
Integer
cid
=
address
.
getCityId
();
if
(
cid
==
null
){
return
ResponseUtil
.
badArgument
();
}
if
(
addressService
.
findById
(
cid
)
==
null
){
return
ResponseUtil
.
badArgumentValue
();
}
Integer
aid
=
address
.
getAreaId
();
if
(
aid
==
null
){
return
ResponseUtil
.
badArgument
();
}
if
(
addressService
.
findById
(
aid
)
==
null
){
return
ResponseUtil
.
badArgumentValue
();
}
String
detailedAddress
=
address
.
getAddress
();
if
(
StringUtils
.
isEmpty
(
detailedAddress
)){
return
ResponseUtil
.
badArgument
();
}
Boolean
isDefault
=
address
.
getIsDefault
();
if
(
isDefault
==
null
){
return
ResponseUtil
.
badArgument
();
}
return
null
;
}
/**
* 添加或更新收货地址
*
...
...
@@ -138,14 +190,9 @@ public class WxAddressController {
if
(
userId
==
null
){
return
ResponseUtil
.
unlogin
();
}
if
(
address
==
null
){
return
ResponseUtil
.
badArgument
();
}
// 测试收货手机号码是否正确
String
mobile
=
address
.
getMobile
();
if
(!
RegexUtil
.
isMobileExact
(
mobile
)){
return
ResponseUtil
.
badArgument
();
Object
error
=
validate
(
address
);
if
(
error
!=
null
){
return
error
;
}
if
(
address
.
getIsDefault
()){
...
...
@@ -181,12 +228,9 @@ public class WxAddressController {
if
(
userId
==
null
){
return
ResponseUtil
.
unlogin
();
}
if
(
address
==
null
){
return
ResponseUtil
.
badArgument
();
}
Integer
id
=
address
.
getId
();
if
(
id
==
null
){
return
ResponseUtil
.
badArgument
Value
();
return
ResponseUtil
.
badArgument
();
}
addressService
.
delete
(
id
);
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java
View file @
7597c60a
...
...
@@ -68,7 +68,7 @@ public class WxAuthController {
* }
* 失败则 { errno: XXX, errmsg: XXX }
*/
@
Reque
stMapping
(
"login"
)
@
Po
stMapping
(
"login"
)
public
Object
login
(
@RequestBody
String
body
,
HttpServletRequest
request
)
{
String
username
=
JacksonUtil
.
parseString
(
body
,
"username"
);
String
password
=
JacksonUtil
.
parseString
(
body
,
"password"
);
...
...
@@ -125,7 +125,7 @@ public class WxAuthController {
* }
* 失败则 { errno: XXX, errmsg: XXX }
*/
@
Reque
stMapping
(
"login_by_weixin"
)
@
Po
stMapping
(
"login_by_weixin"
)
public
Object
loginByWeixin
(
@RequestBody
WxLoginInfo
wxLoginInfo
,
HttpServletRequest
request
)
{
String
code
=
wxLoginInfo
.
getCode
();
UserInfo
userInfo
=
wxLoginInfo
.
getUserInfo
();
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java
View file @
7597c60a
...
...
@@ -296,7 +296,7 @@ public class WxCartController {
* 如果原来没有勾选,则设置勾选状态;如果商品已经勾选,则设置非勾选状态。
*
* @param userId 用户ID
* @param body 购物车商品信息, { productIds: xxx }
* @param body 购物车商品信息, { productIds: xxx
, isChecked: 1/0
}
* @return 购物车信息
* 成功则
* {
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java
View file @
7597c60a
package
org.linlinjava.litemall.wx.web
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.linlinjava.litemall.db.domain.LitemallComment
;
import
org.linlinjava.litemall.db.domain.LitemallGoodsSpecification
;
import
org.linlinjava.litemall.db.service.LitemallCommentService
;
import
org.linlinjava.litemall.db.service.LitemallGoodsService
;
import
org.linlinjava.litemall.db.service.LitemallTopicService
;
import
org.linlinjava.litemall.db.service.LitemallUserService
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.wx.annotation.LoginUser
;
...
...
@@ -29,6 +33,45 @@ public class WxCommentController {
private
LitemallUserService
userService
;
@Autowired
private
UserInfoService
userInfoService
;
@Autowired
private
LitemallGoodsService
goodsService
;
@Autowired
private
LitemallTopicService
topicService
;
private
Object
validate
(
LitemallComment
comment
)
{
String
content
=
comment
.
getContent
();
if
(
StringUtils
.
isEmpty
(
content
)){
return
ResponseUtil
.
badArgument
();
}
Short
star
=
comment
.
getStar
();
if
(
star
==
null
){
return
ResponseUtil
.
badArgument
();
}
if
(
star
<
0
||
star
>
5
){
return
ResponseUtil
.
badArgumentValue
();
}
Byte
type
=
comment
.
getType
();
Integer
valueId
=
comment
.
getValueId
();
if
(
type
==
null
||
valueId
==
null
){
return
ResponseUtil
.
badArgument
();
}
if
(
type
==
0
){
if
(
goodsService
.
findById
(
valueId
)
==
null
){
return
ResponseUtil
.
badArgumentValue
();
}
}
else
if
(
type
==
1
){
if
(
topicService
.
findById
(
valueId
)
==
null
){
return
ResponseUtil
.
badArgumentValue
();
}
}
else
{
return
ResponseUtil
.
badArgumentValue
();
}
return
null
;
}
/**
* 发表评论
...
...
@@ -53,8 +96,9 @@ public class WxCommentController {
if
(
userId
==
null
){
return
ResponseUtil
.
unlogin
();
}
if
(
comment
==
null
){
return
ResponseUtil
.
badArgument
();
Object
error
=
validate
(
comment
);
if
(
error
!=
null
){
return
error
;
}
comment
.
setAddTime
(
LocalDateTime
.
now
());
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFeedbackController.java
View file @
7597c60a
package
org.linlinjava.litemall.wx.web
;
import
org.
linlinjava.litemall.core.util.Jackson
Util
;
import
org.
apache.commons.lang3.String
Util
s
;
import
org.linlinjava.litemall.core.util.RegexUtil
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
import
org.linlinjava.litemall.db.domain.LitemallFeedback
;
...
...
@@ -13,8 +13,6 @@ import org.apache.commons.logging.LogFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.time.LocalDateTime
;
/**
...
...
@@ -32,18 +30,39 @@ public class WxFeedbackController {
@Autowired
private
LitemallUserService
userService
;
private
Object
validate
(
LitemallFeedback
feedback
)
{
String
content
=
feedback
.
getContent
();
if
(
StringUtils
.
isEmpty
(
content
)){
return
ResponseUtil
.
badArgument
();
}
String
type
=
feedback
.
getFeedType
();
if
(
StringUtils
.
isEmpty
(
type
)){
return
ResponseUtil
.
badArgument
();
}
// 测试手机号码是否正确
String
mobile
=
feedback
.
getMobile
();
if
(
StringUtils
.
isEmpty
(
mobile
)){
return
ResponseUtil
.
badArgument
();
}
if
(!
RegexUtil
.
isMobileExact
(
mobile
))
{
return
ResponseUtil
.
badArgument
();
}
return
null
;
}
/**
* 意见反馈
*
意见反馈
*/
@PostMapping
(
"submit"
)
public
Object
submit
(
@LoginUser
Integer
userId
,
@RequestBody
LitemallFeedback
feedback
)
{
if
(
userId
==
null
)
{
return
ResponseUtil
.
unlogin
();
}
// 测试手机号码是否正确
if
(!
RegexUtil
.
isMobileExact
(
feedback
.
getMobile
()))
{
return
ResponseUtil
.
badArgument
();
Object
error
=
validate
(
feedback
);
if
(
error
!=
null
){
return
error
;
}
LitemallUser
user
=
userService
.
findById
(
userId
);
...
...
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java
View file @
7597c60a
...
...
@@ -102,9 +102,6 @@ public class WxOrderController {
@Autowired
private
ExpressService
expressService
;
public
WxOrderController
()
{
}
private
String
detailedAddress
(
LitemallAddress
litemallAddress
)
{
Integer
provinceId
=
litemallAddress
.
getProvinceId
();
Integer
cityId
=
litemallAddress
.
getCityId
();
...
...
@@ -141,7 +138,7 @@ public class WxOrderController {
* }
* 失败则 { errno: XXX, errmsg: XXX }
*/
@
Reques
tMapping
(
"list"
)
@
Ge
tMapping
(
"list"
)
public
Object
list
(
@LoginUser
Integer
userId
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
showType
,
@RequestParam
(
defaultValue
=
"1"
)
Integer
page
,
...
...
Write
Preview
Supports
Markdown
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