Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
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
曲欣亮
shop
Commits
19f5144e
Commit
19f5144e
authored
Nov 13, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
e9991572
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
0 deletions
+138
-0
ExpressController.java
...ain/java/com/egolm/shop/controller/ExpressController.java
+41
-0
Express.java
src/main/java/com/egolm/shop/util/Express.java
+93
-0
application.properties
src/main/resources/application.properties
+4
-0
No files found.
src/main/java/com/egolm/shop/controller/ExpressController.java
0 → 100644
View file @
19f5144e
package
com
.
egolm
.
shop
.
controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.fastjson.JSONArray
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.shop.util.Express
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
@RestController
@Api
(
tags
={
"快递接口"
})
@RequestMapping
(
"express"
)
public
class
ExpressController
{
@Autowired
private
Express
express
;
@ApiOperation
(
"快递查询"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sExpressNO"
,
dataType
=
"String"
,
required
=
true
,
value
=
"快递单号"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sExpressType"
,
dataType
=
"String"
,
required
=
false
,
value
=
"快递公司"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"terminal"
,
dataType
=
"String"
,
required
=
true
,
value
=
"终端标识"
,
defaultValue
=
"wechat"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"langID"
,
dataType
=
"String"
,
required
=
false
,
value
=
"语言"
,
defaultValue
=
"936"
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"sign"
,
dataType
=
"String"
,
required
=
true
,
value
=
"签名"
,
defaultValue
=
""
),
@ApiImplicitParam
(
paramType
=
"query"
,
name
=
"timestamp"
,
dataType
=
"String"
,
required
=
true
,
value
=
"时间戳"
,
defaultValue
=
""
)
})
@RequestMapping
(
value
=
"/createGuest"
,
method
=
RequestMethod
.
GET
)
public
Object
createGuest
(
String
sExpressNO
,
String
sExpressType
)
{
JSONArray
data
=
express
.
get
(
sExpressNO
,
sExpressType
);
return
Rjx
.
jsonOk
().
setData
(
data
);
}
}
src/main/java/com/egolm/shop/util/Express.java
0 → 100644
View file @
19f5144e
package
com
.
egolm
.
shop
.
util
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.TimeZone
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.egolm.common.HttpUtil
;
import
com.egolm.common.StringUtil
;
import
com.egolm.shop.config.XException
;
@Component
public
class
Express
{
@Value
(
"opt.express.url"
)
private
String
url
;
@Value
(
"opt.express.secretId"
)
private
String
secretId
;
@Value
(
"opt.express.secretKey"
)
private
String
secretKey
;
private
String
source
=
"market"
;
private
Map
<
String
,
String
>
getHeaders
()
{
Map
<
String
,
String
>
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
"X-Source"
,
source
);
Calendar
cd
=
Calendar
.
getInstance
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"EEE, dd MMM yyyy HH:mm:ss 'GMT'"
,
Locale
.
US
);
sdf
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
String
datetime
=
sdf
.
format
(
cd
.
getTime
());
headers
.
put
(
"X-Date"
,
datetime
);
String
signStr
=
"x-date: "
+
datetime
+
"\n"
+
"x-source: "
+
source
;
String
sig
=
StringUtil
.
toHMACSHA1String
(
signStr
,
secretKey
);
String
auth
=
"hmac id=\""
+
secretId
+
"\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\""
+
sig
+
"\""
;
headers
.
put
(
"Authorization"
,
auth
);
return
headers
;
}
public
JSONArray
get
(
String
sExpressNO
,
String
sExpressType
)
{
Map
<
String
,
String
>
headers
=
this
.
getHeaders
();
Map
<
String
,
String
>
queryParams
=
new
HashMap
<
String
,
String
>();
queryParams
.
put
(
"number"
,
sExpressNO
);
queryParams
.
put
(
"type"
,
sExpressType
);
String
result
=
HttpUtil
.
get
(
url
,
queryParams
,
headers
);
JSONObject
jsonObject
=
null
;
try
{
jsonObject
=
JSON
.
parseObject
(
result
);
}
catch
(
Exception
e
)
{
throw
new
XException
(
"快递查询失败"
);
}
if
(
jsonObject
!=
null
)
{
String
status
=
jsonObject
.
getString
(
"status"
);
if
(
status
!=
null
)
{
status
=
status
.
trim
();
if
(
"0"
.
equals
(
status
))
{
JSONObject
resultObject
=
jsonObject
.
getJSONObject
(
"result"
);
if
(
resultObject
!=
null
)
{
return
resultObject
.
getJSONArray
(
"list"
);
}
}
else
{
if
(
"201"
.
equals
(
status
))
{
throw
new
XException
(
"快递单号为空"
);
}
else
if
(
"202"
.
equals
(
status
))
{
throw
new
XException
(
"快递公司为空"
);
}
else
if
(
"203"
.
equals
(
status
))
{
throw
new
XException
(
"快递公司不存在"
);
}
else
if
(
"204"
.
equals
(
status
))
{
throw
new
XException
(
"快递公司识别失败"
);
}
else
if
(
"205"
.
equals
(
status
))
{
throw
new
XException
(
"没有信息"
);
}
}
}
}
return
new
JSONArray
();
}
public
JSONArray
get
(
String
sExpressNO
)
{
return
this
.
get
(
sExpressNO
,
null
);
}
}
src/main/resources/application.properties
View file @
19f5144e
...
@@ -54,6 +54,10 @@ log.datasource.testWhileIdle=true
...
@@ -54,6 +54,10 @@ log.datasource.testWhileIdle=true
log.datasource.validationQueryTimeout
=
5
log.datasource.validationQueryTimeout
=
5
log.datasource.validationQuery
=
SELECT 1 FROM DUAL
log.datasource.validationQuery
=
SELECT 1 FROM DUAL
opt.express.url
=
https://service-5ptj62bx-1257101137.ap-shanghai.apigateway.myqcloud.com/release/express/type
opt.express.secretId
=
AKID3dJ0MqWwN23oZ8xt4GFB0s8My1rEfUW2diLU
opt.express.secretKey
=
4mp4j4Vu4ZE8lCI9R9jqlo0okFz3bRh24II19d9y
spring.redis.database
=
0
spring.redis.database
=
0
spring.redis.host
=
127.0.0.1
spring.redis.host
=
127.0.0.1
spring.redis.port
=
16379
spring.redis.port
=
16379
...
...
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