Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4d088aba
authored
Dec 31, 2024
by
谢海旭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加查询百度省市区透传接口
1 parent
61007e40
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
src/main/java/cn/com/glsx/stdinterface/modules/controller/ApiRegionSearchController.java
src/main/java/cn/com/glsx/stdinterface/modules/controller/ApiRegionSearchController.java
0 → 100644
View file @
4d088ab
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
controller
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
/**
* @Title:
* @Description: 透传接口,查询百度地理信息
* @Author xiehx
* @Date 2024/12/31
**/
@RequestMapping
(
"/apiRegion"
)
@RestController
public
class
ApiRegionSearchController
{
// TODO ak放配置
private
static
final
String
BAIDU_MAP_API_URL
=
"https://api.map.baidu.com/api_region_search/v1/?ak=pbKP9T69inAX0GVwS9uar2l1Yz6OLyyg&"
;
@RequestMapping
(
"/search"
)
public
Object
getRegionSearch
(
@RequestParam
Map
<
String
,
String
>
allParams
)
throws
IOException
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
StringBuilder
urlBuilder
=
new
StringBuilder
(
BAIDU_MAP_API_URL
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
allParams
.
entrySet
())
{
urlBuilder
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
URLEncoder
.
encode
(
entry
.
getValue
(),
StandardCharsets
.
UTF_8
.
name
()));
}
HttpGet
request
=
new
HttpGet
(
urlBuilder
.
toString
());
try
(
CloseableHttpResponse
response
=
httpClient
.
execute
(
request
))
{
return
EntityUtils
.
toString
(
response
.
getEntity
());
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment