Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
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
马天浩
jiwei-api
Commits
5202f30d
Commit
5202f30d
authored
Mar 17, 2021
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[鸿程接口] <add> 浙江杭州规划和自然资源局不动产权属查询
parent
a1b6e8e7
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1049 additions
and
1 deletion
+1049
-1
pom.xml
pom.xml
+11
-0
HongChengController.java
...com/mth/requestsecret/controller/HongChengController.java
+71
-0
RestTemplateService.java
...va/com/mth/requestsecret/service/RestTemplateService.java
+54
-1
JsonMapper.java
src/main/java/com/mth/requestsecret/util/JsonMapper.java
+264
-0
RsaUtil.java
src/main/java/com/mth/requestsecret/util/RsaUtil.java
+629
-0
HongChengUser.java
...ava/com/mth/requestsecret/vo/hongcheng/HongChengUser.java
+20
-0
No files found.
pom.xml
View file @
5202f30d
...
...
@@ -99,6 +99,17 @@
<version>
2.6
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.11
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.module
</groupId>
<artifactId>
jackson-module-jaxb-annotations
</artifactId>
<version>
2.10.2
</version>
</dependency>
<dependency>
<groupId>
org.dom4j
</groupId>
<artifactId>
dom4j
</artifactId>
...
...
src/main/java/com/mth/requestsecret/controller/HongChengController.java
0 → 100644
View file @
5202f30d
package
com
.
mth
.
requestsecret
.
controller
;
import
com.google.common.collect.Lists
;
import
com.mth.requestsecret.service.RestTemplateService
;
import
com.mth.requestsecret.util.DSLUtils
;
import
com.mth.requestsecret.vo.hongcheng.HongChengUser
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author MaTianHao
* @date 2021/3/16
*/
@RestController
@Slf4j
public
class
HongChengController
{
@Autowired
private
RestTemplateService
restTemplateService
;
/**
* 浙江杭州规划和自然资源局不动产权属查询
*
* @param user
* @return
*/
@PostMapping
(
"/realEstateOwnership"
)
public
ResponseEntity
realEstateOwnership
(
HongChengUser
user
)
throws
UnsupportedEncodingException
{
// api签名
String
apiMethod
=
"30160300772/20210308111381091663091696"
;
// api参数
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"timestamp"
,
DSLUtils
.
dateToLong
(
new
Date
())
+
""
);
// 查档编号,自定义流水号,例:Q20200610-00001
paramMap
.
put
(
"cdbh"
,
"Q20200610-00001"
);
// 行政区编码,例:330101
paramMap
.
put
(
"xzqbm"
,
"330101"
);
// 是否启用全大市查询 1:是 0:否
paramMap
.
put
(
"isAllCity"
,
"1"
);
// 是否查询限制信息 1:是 0:否
paramMap
.
put
(
"isShowXzxx"
,
"1"
);
// 是否启用电子签章 1:启用 0:不启用
paramMap
.
put
(
"qyca"
,
"0"
);
// 生成的pdf的说明一栏文字
paramMap
.
put
(
"sm"
,
""
);
// 查询范围
paramMap
.
put
(
"cxfw"
,
""
);
// 查档用途
paramMap
.
put
(
"cdyt"
,
"无房证明"
);
// 机构名称
paramMap
.
put
(
"jgmc"
,
""
);
// 背景水印
paramMap
.
put
(
"bjsy"
,
""
);
// 查询标题
paramMap
.
put
(
"cxbt"
,
"不动产登记信息查询记录"
);
// 姓名,证件号
paramMap
.
put
(
"querymanList"
,
Lists
.
newArrayList
(
user
));
return
restTemplateService
.
hongChengSendRequest
(
paramMap
,
apiMethod
);
}
}
src/main/java/com/mth/requestsecret/service/RestTemplateService.java
View file @
5202f30d
...
...
@@ -13,6 +13,8 @@ import org.springframework.util.LinkedMultiValueMap;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
...
...
@@ -70,9 +72,21 @@ public class RestTemplateService {
/**
* 资产资源接口地址
*/
@Value
(
(
"${zczy.address}"
)
)
@Value
(
"${zczy.address}"
)
private
String
zczyAddress
;
/**
* 鸿程相关
*/
@Value
(
"${hongcheng.address}"
)
private
String
hongchengAddress
;
@Value
(
"${hongcheng.userId}"
)
private
String
hongchengUserId
;
@Value
(
"${hongcheng.appSecret}"
)
private
String
hongchengAppSecret
;
@Value
(
"${hongcheng.priviteKey}"
)
private
String
hongchengPriviteKey
;
/**
* 瑞成平台接口发送请求
*
...
...
@@ -368,4 +382,43 @@ public class RestTemplateService {
.
header
(
HttpHeaders
.
CONTENT_TYPE
,
MediaType
.
APPLICATION_JSON_VALUE
)
.
body
(
decryptStr
);
}
/**
* 鸿程 浙江杭州规划和自然资源局不动产权属查询
* @param paramMap
* @param apiMethod
*/
public
ResponseEntity
hongChengSendRequest
(
Map
<
String
,
Object
>
paramMap
,
String
apiMethod
)
throws
UnsupportedEncodingException
{
String
url
=
hongchengAddress
+
apiMethod
;
String
jsonParam
=
JsonMapper
.
toJsonString
(
paramMap
);
jsonParam
=
URLEncoder
.
encode
(
jsonParam
,
"UTF-8"
);
// 私钥加密参数
String
encryptParam
=
RsaUtil
.
encryptByPrivateKey
(
hongchengPriviteKey
,
jsonParam
);
// 生成数字签名
String
sign
=
RsaUtil
.
sign
(
hongchengPriviteKey
,
encryptParam
);
// 构建请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
MultiValueMap
<
String
,
String
>
body
=
new
LinkedMultiValueMap
<>();
body
.
add
(
"appSecret"
,
hongchengAppSecret
);
body
.
add
(
"userId"
,
hongchengUserId
);
body
.
add
(
"encryptParam"
,
encryptParam
);
body
.
add
(
"sign"
,
sign
);
HttpEntity
httpEntity
=
new
HttpEntity
<>(
body
,
headers
);
log
.
info
(
"不动产权属查询api:{}"
,
apiMethod
);
log
.
info
(
"api url:{}"
,
url
);
log
.
info
(
"原参数:{}"
,
paramMap
);
log
.
info
(
"加密参数encryptParam:{}"
,
encryptParam
);
log
.
info
(
"签名sign:{}"
,
sign
);
// 发送请求
ResponseEntity
<
String
>
responseEntity
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
log
.
info
(
"api response:{}"
,
responseEntity
);
return
responseEntity
;
}
}
\ No newline at end of file
src/main/java/com/mth/requestsecret/util/JsonMapper.java
0 → 100644
View file @
5202f30d
package
com
.
mth
.
requestsecret
.
util
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser.Feature
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.*
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.util.JSONPObject
;
import
com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TimeZone
;
/**
* 简单封装Jackson,实现JSON String<->Java Object的Mapper.
* 封装不同的输出风格, 使用不同的builder函数创建实例.
* @author ThinkGem
* @version 2013-11-15
*/
public
class
JsonMapper
extends
ObjectMapper
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JsonMapper
.
class
);
private
static
JsonMapper
mapper
;
public
JsonMapper
()
{
this
(
Include
.
ALWAYS
);
//修改这里控制把对象转换成json数组,不管对象属性有没有值,都创建节点
}
public
JsonMapper
(
Include
include
)
{
// 设置输出时包含属性的风格
if
(
include
!=
null
)
{
this
.
setSerializationInclusion
(
include
);
}
// 允许单引号、允许不带引号的字段名称
this
.
enableSimple
();
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
this
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
// 空值处理为空串
this
.
getSerializerProvider
().
setNullValueSerializer
(
new
JsonSerializer
<
Object
>(){
@Override
public
void
serialize
(
Object
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
,
JsonProcessingException
{
jgen
.
writeString
(
""
);
}
});
// 进行HTML解码。
this
.
registerModule
(
new
SimpleModule
().
addSerializer
(
String
.
class
,
new
JsonSerializer
<
String
>(){
@Override
public
void
serialize
(
String
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
,
JsonProcessingException
{
jgen
.
writeString
(
StringEscapeUtils
.
unescapeHtml4
(
value
));
}
}));
// 设置时区
this
.
setTimeZone
(
TimeZone
.
getDefault
());
//getTimeZone("GMT+8:00")
}
/**
* 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
*/
public
static
JsonMapper
getInstance
()
{
if
(
mapper
==
null
){
mapper
=
new
JsonMapper
().
enableSimple
();
}
return
mapper
;
}
/**
* 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
*/
public
static
JsonMapper
nonDefaultMapper
()
{
if
(
mapper
==
null
){
mapper
=
new
JsonMapper
(
Include
.
NON_DEFAULT
);
}
return
mapper
;
}
/**
* Object可以是POJO,也可以是Collection或数组。
* 如果对象为Null, 返回"null".
* 如果集合为空集合, 返回"[]".
*/
public
String
toJson
(
Object
object
)
{
try
{
return
this
.
writeValueAsString
(
object
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"write to json string error:"
+
object
,
e
);
return
null
;
}
}
/**
* 反序列化POJO或简单Collection如List<String>.
*
* 如果JSON字符串为Null或"null"字符串, 返回Null.
* 如果JSON字符串为"[]", 返回空集合.
*
* 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String,JavaType)
* @see #fromJson(String, JavaType)
*/
public
<
T
>
T
fromJson
(
String
jsonString
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
this
.
readValue
(
jsonString
,
clazz
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
/**
* 反序列化复杂Collection如List<Bean>, 先使用函數createCollectionType构造类型,然后调用本函数.
* @see #createCollectionType(Class, Class...)
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
fromJson
(
String
jsonString
,
JavaType
javaType
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
(
T
)
this
.
readValue
(
jsonString
,
javaType
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
/**
* 構造泛型的Collection Type如:
* ArrayList<MyBean>, 则调用constructCollectionType(ArrayList.class,MyBean.class)
* HashMap<String,MyBean>, 则调用(HashMap.class,String.class, MyBean.class)
*/
public
JavaType
createCollectionType
(
Class
<?>
collectionClass
,
Class
<?>...
elementClasses
)
{
return
this
.
getTypeFactory
().
constructParametricType
(
collectionClass
,
elementClasses
);
}
/**
* 當JSON裡只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性.
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
update
(
String
jsonString
,
T
object
)
{
try
{
return
(
T
)
this
.
readerForUpdating
(
object
).
readValue
(
jsonString
);
}
catch
(
JsonProcessingException
e
)
{
logger
.
warn
(
"update json string:"
+
jsonString
+
" to object:"
+
object
+
" error."
,
e
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"update json string:"
+
jsonString
+
" to object:"
+
object
+
" error."
,
e
);
}
return
null
;
}
/**
* 輸出JSONP格式數據.
*/
public
String
toJsonP
(
String
functionName
,
Object
object
)
{
return
toJson
(
new
JSONPObject
(
functionName
,
object
));
}
/**
* 設定是否使用Enum的toString函數來讀寫Enum,
* 為False時時使用Enum的name()函數來讀寫Enum, 默認為False.
* 注意本函數一定要在Mapper創建後, 所有的讀寫動作之前調用.
*/
public
JsonMapper
enableEnumUseToString
()
{
this
.
enable
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
);
this
.
enable
(
DeserializationFeature
.
READ_ENUMS_USING_TO_STRING
);
return
this
;
}
/**
* 支持使用Jaxb的Annotation,使得POJO上的annotation不用与Jackson耦合。
* 默认会先查找jaxb的annotation,如果找不到再找jackson的。
*/
public
JsonMapper
enableJaxbAnnotation
()
{
JaxbAnnotationModule
module
=
new
JaxbAnnotationModule
();
this
.
registerModule
(
module
);
return
this
;
}
/**
* 允许单引号
* 允许不带引号的字段名称
*/
public
JsonMapper
enableSimple
()
{
this
.
configure
(
Feature
.
ALLOW_SINGLE_QUOTES
,
true
);
this
.
configure
(
Feature
.
ALLOW_UNQUOTED_FIELD_NAMES
,
true
);
return
this
;
}
/**
* 取出Mapper做进一步的设置或使用其他序列化API.
*/
public
ObjectMapper
getMapper
()
{
return
this
;
}
/**
* 对象转换为JSON字符串
* @param object
* @return
*/
public
static
String
toJsonString
(
Object
object
){
return
JsonMapper
.
getInstance
().
toJson
(
object
);
}
/**
* JSON字符串转换为对象
* @param jsonString
* @param clazz
* @return
*/
public
static
Object
fromJsonString
(
String
jsonString
,
Class
<?>
clazz
){
return
JsonMapper
.
getInstance
().
fromJson
(
jsonString
,
clazz
);
}
/**
* 测试
*/
public
static
void
main
(
String
[]
args
)
{
List
<
Map
<
String
,
Object
>>
list
=
Lists
.
newArrayList
();
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
1
);
map
.
put
(
"pId"
,
-
1
);
map
.
put
(
"name"
,
"根节点"
);
list
.
add
(
map
);
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
2
);
map
.
put
(
"pId"
,
1
);
map
.
put
(
"name"
,
"你好"
);
map
.
put
(
"open"
,
true
);
list
.
add
(
map
);
//String json = JsonMapper.getInstance().toJson(list);
//System.out.println(json);
Map
<
String
,
Object
>
map2
=
Maps
.
newHashMap
();
map2
.
put
(
"id"
,
2
);
map2
.
put
(
"pId"
,
1
);
map2
.
put
(
"name"
,
"你好"
);
map2
.
put
(
"open"
,
true
);
String
json2
=
JsonMapper
.
getInstance
().
toJson
(
map2
);
JavaType
javaType
=
JsonMapper
.
getInstance
().
createCollectionType
(
Map
.
class
,
String
.
class
,
Object
.
class
);
Map
<
String
,
Object
>
map3
=
JsonMapper
.
getInstance
().
fromJson
(
json2
,
javaType
);
System
.
out
.
println
(
map3
.
toString
());
}
}
src/main/java/com/mth/requestsecret/util/RsaUtil.java
0 → 100644
View file @
5202f30d
This diff is collapsed.
Click to expand it.
src/main/java/com/mth/requestsecret/vo/hongcheng/HongChengUser.java
0 → 100644
View file @
5202f30d
package
com
.
mth
.
requestsecret
.
vo
.
hongcheng
;
import
lombok.Data
;
/**
* @author MaTianHao
* @date 2021/3/17
*/
@Data
public
class
HongChengUser
{
/**
* 姓名
*/
private
String
name
;
/**
* 证件号
*/
private
String
zjh
;
}
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