Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xzxt-jsoup
Overview
Overview
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
陈甜
xzxt-jsoup
Commits
c0932418
Commit
c0932418
authored
Jul 27, 2019
by
cc150520900118
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加新版银行卡查询功能
parent
f986e866
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
389 additions
and
1 deletions
+389
-1
src/main/java/com/founder/controller/CardLiushuiController.java
+13
-0
src/main/java/com/founder/jsoup/JsoupCookieCrawNew.java
+213
-0
src/main/java/com/founder/model/card.java
+8
-0
src/main/java/com/founder/service/CardinfosServiceNew.java
+15
-0
src/main/java/com/founder/service/impl/CardinfosServiceNewImpl.java
+139
-0
src/main/resources/templates/form.html
+1
-1
No files found.
src/main/java/com/founder/controller/CardLiushuiController.java
View file @
c0932418
...
...
@@ -5,6 +5,7 @@ import com.founder.model.card;
import
com.founder.model.cardliushui
;
import
com.founder.model.thirdparty
;
import
com.founder.service.CardinfosService
;
import
com.founder.service.CardinfosServiceNew
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -19,6 +20,8 @@ public class CardLiushuiController {
@Autowired
private
CardinfosService
cardinfosService
;
@Autowired
private
CardinfosServiceNew
cardinfosServiceNew
;
@PostMapping
(
"/cardinfos"
)
...
...
@@ -31,6 +34,16 @@ public class CardLiushuiController {
card
.
setCurPage
(
card
.
getDraw
());
return
(
Map
<
String
,
Object
>)
cardinfosService
.
getCardliushui
(
card
).
getData
();
}
@PostMapping
(
"/cardinfosnew"
)
public
Map
<
String
,
Object
>
cardinfosnew
(
card
card
){
card
.
setCurPage
(
card
.
getDraw
());
return
(
Map
<
String
,
Object
>)
cardinfosServiceNew
.
getCardinfos
(
card
).
getData
();
}
@PostMapping
(
"/cardliushuinew"
)
public
Map
<
String
,
Object
>
cardliushuinew
(
card
card
){
card
.
setCurPage
(
card
.
getDraw
());
return
(
Map
<
String
,
Object
>)
cardinfosServiceNew
.
getCardliushui
(
card
).
getData
();
}
@PostMapping
(
"/thirdpartyinfos"
)
public
Map
<
String
,
Object
>
thirdpartyinfos
(
thirdparty
thirdparty
){
thirdparty
.
setCurPage
(
thirdparty
.
getDraw
());
...
...
src/main/java/com/founder/jsoup/JsoupCookieCrawNew.java
0 → 100644
View file @
c0932418
package
com
.
founder
.
jsoup
;
import
com.alibaba.fastjson.JSON
;
import
com.founder.model.card
;
import
com.founder.model.cardliushui
;
import
com.founder.model.thirdparty
;
import
org.jsoup.Connection
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.select.Elements
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.*
;
/**
* Created by changchao on 2019/5/27.
*/
@Component
public
class
JsoupCookieCrawNew
{
@Value
(
"${dzpt.login.url}"
)
private
String
loginurl
;
/**
* 模拟登录获取cookie和sessionid
*/
public
Map
<
String
,
String
>
login
()
throws
IOException
{
Map
<
String
,
String
>
cookies
=
null
;
Connection
connect
=
Jsoup
.
connect
(
loginurl
);
// 伪造请求头
connect
.
header
(
"Accept"
,
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
).
header
(
"Accept-Encoding"
,
"gzip, deflate"
);
connect
.
header
(
"Accept-Language"
,
"zh-CN,zh;q=0.9"
).
header
(
"Connection"
,
"keep-alive"
);
connect
.
header
(
"Content-Length"
,
"40"
).
header
(
"Content-Type"
,
"application/x-www-form-urlencoded; charset=UTF-8"
);
connect
.
header
(
"Host"
,
"68.89.99.2"
).
header
(
"Referer"
,
"http://68.89.99.2/dxzp/login_yh.jsp"
);
connect
.
header
(
"User-Agent"
,
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3510.2 Safari/537.36"
)
.
header
(
"X-Requested-With"
,
"XMLHttpRequest"
);
// 携带登陆信息
//yh.dwDm: 650000
//yh.dm: 003249
//yh.kl: 123456
connect
.
data
(
"yh.dwDm"
,
"650000"
).
data
(
"yh.dm"
,
"003249"
).
data
(
"yh.kl"
,
"123456"
);
//请求url获取响应信息
Connection
.
Response
res
=
connect
.
ignoreContentType
(
true
).
method
(
Connection
.
Method
.
POST
).
execute
();
// 执行请求
// 获取返回的cookie
cookies
=
res
.
cookies
();
return
cookies
;
}
/**
* 银行卡解析数据
*/
public
Map
<
String
,
Object
>
getCardInfo
(
Document
document
)
{
Map
<
String
,
Object
>
listmap
=
new
HashMap
<
String
,
Object
>();
JsoupCookieCrawNew
jsop
=
new
JsoupCookieCrawNew
();
List
<
card
>
cardList
=
new
ArrayList
<
card
>();
String
value
=
null
;
Elements
cards
=
document
.
getElementsByTag
(
"tr"
);
//System.out.println("获取的元数据列表==="+cards.toString());
//去除表头列数据
cards
.
remove
(
0
);
for
(
Element
cardinfos:
cards
){
card
card
=
new
card
();
Elements
cardxx
=
cardinfos
.
getElementsByTag
(
"td"
);
try
{
card
.
setXxzjbh
(
jsop
.
saveQueryLog
());
}
catch
(
Exception
e
)
{
}
card
.
setAccountName
(
cardxx
.
get
(
1
).
text
());
card
.
setAccount
(
cardxx
.
get
(
2
).
text
());
card
.
setApplicationNumber
(
cardxx
.
get
(
3
).
text
());
card
.
setBank
(
cardxx
.
get
(
4
).
text
());
card
.
setType
(
cardxx
.
get
(
5
).
text
());
card
.
setStatus
(
cardxx
.
get
(
6
).
text
());
card
.
setMomey
(
cardxx
.
get
(
7
).
text
());
card
.
setCardResults
(
cardxx
.
get
(
8
).
text
());
card
.
setLrr
(
cardxx
.
get
(
9
).
text
());
card
.
setLrsj
(
cardxx
.
get
(
10
).
text
());
card
.
setLrdw
(
cardxx
.
get
(
11
).
text
());
System
.
out
.
println
(
"数据card====="
+
JSON
.
toJSONString
(
card
));
cardList
.
add
(
card
);
}
//页数
Elements
pageinfos
=
document
.
getElementsByClass
(
"next-page"
).
select
(
"p"
);
Elements
page
=
pageinfos
.
get
(
0
).
select
(
"span"
);
//page.get(1).text();
//结果数据展示
/* JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(cardList));
System.out.println(jsonArray);*/
int
num
=
Integer
.
parseInt
(
page
.
get
(
1
).
text
())*
15
;
listmap
.
put
(
"data"
,
cardList
);
listmap
.
put
(
"rows"
,
cardList
);
listmap
.
put
(
"total"
,
num
);
listmap
.
put
(
"recordsTotal"
,
num
);
listmap
.
put
(
"recordsFiltered"
,
num
);
listmap
.
put
(
"draw"
,
""
);
return
listmap
;
}
/**
* 银行卡交易流水解析数据
*/
public
Map
<
String
,
Object
>
getCardLsInfo
(
Document
document
)
{
Map
<
String
,
Object
>
listmap
=
new
HashMap
<
String
,
Object
>();
JsoupCookieCrawNew
jsop
=
new
JsoupCookieCrawNew
();
List
<
cardliushui
>
cardList
=
new
ArrayList
<
cardliushui
>();
String
value
=
null
;
Elements
cardliushuixx
=
document
.
getElementsByClass
(
"table-two"
);
//System.out.println("获取的元数据列表1==="+cardliushuixx.toString());
Elements
cardliushuis
=
cardliushuixx
.
select
(
"tbody"
).
select
(
"tr"
);
//System.out.println("获取的元数据列表2==="+cardliushuis.toString());
//去除表头列数据
cardliushuis
.
remove
(
0
);
for
(
Element
cardinfos:
cardliushuis
){
cardliushui
cardliushui
=
new
cardliushui
();
Elements
cardliushuixxs
=
cardinfos
.
getElementsByTag
(
"td"
);
//System.out.println("获取的元数据列表3==="+cardliushuixxs.toString());
try
{
cardliushui
.
setXxzjbh
(
jsop
.
saveQueryLog
());
}
catch
(
Exception
e
)
{
}
cardliushui
.
setZh
(
cardliushuixxs
.
get
(
1
).
text
());
cardliushui
.
setAccountName
(
cardliushuixxs
.
get
(
2
).
text
());
cardliushui
.
setAccount
(
cardliushuixxs
.
get
(
3
).
text
());
cardliushui
.
setMomey
(
cardliushuixxs
.
get
(
4
).
text
());
cardliushui
.
setBalance
(
cardliushuixxs
.
get
(
5
).
text
());
cardliushui
.
setFlag
(
cardliushuixxs
.
get
(
6
).
text
());
cardliushui
.
setTransactiontpye
(
cardliushuixxs
.
get
(
7
).
text
());
cardliushui
.
setResults
(
cardliushuixxs
.
get
(
8
).
text
());
cardliushui
.
setSj
(
cardliushuixxs
.
get
(
9
).
text
());
System
.
out
.
println
(
"数据card====="
+
JSON
.
toJSONString
(
cardliushui
));
cardList
.
add
(
cardliushui
);
}
//页数
Elements
pageinfos
=
document
.
getElementsByClass
(
"next-page"
).
select
(
"p"
);
Elements
page
=
pageinfos
.
get
(
0
).
select
(
"span"
);
//page.get(1).text();
//结果数据展示
/* JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(cardList));
System.out.println(jsonArray);*/
int
num
=
Integer
.
parseInt
(
page
.
get
(
1
).
text
())*
15
;
listmap
.
put
(
"data"
,
cardList
);
listmap
.
put
(
"recordsTotal"
,
num
);
listmap
.
put
(
"rows"
,
cardList
);
listmap
.
put
(
"total"
,
num
);
listmap
.
put
(
"recordsFiltered"
,
num
);
listmap
.
put
(
"draw"
,
""
);
return
listmap
;
}
/**
* 第三方支付
*/
public
Map
<
String
,
Object
>
getThirdpartys
(
Document
document
)
{
Map
<
String
,
Object
>
listmap
=
new
HashMap
<
String
,
Object
>();
JsoupCookieCrawNew
jsop
=
new
JsoupCookieCrawNew
();
List
<
thirdparty
>
thirdpartyList
=
new
ArrayList
<
thirdparty
>();
String
value
=
null
;
Elements
cards
=
document
.
getElementsByTag
(
"tr"
);
//System.out.println("获取的元数据列表==="+cards.toString());
//去除表头列数据
cards
.
remove
(
0
);
for
(
Element
cardinfos:
cards
){
thirdparty
thirdparty
=
new
thirdparty
();
Elements
cardxx
=
cardinfos
.
getElementsByTag
(
"td"
);
try
{
thirdparty
.
setXxzjbh
(
jsop
.
saveQueryLog
());
}
catch
(
Exception
e
)
{
}
thirdparty
.
setZh
(
cardxx
.
get
(
1
).
text
());
thirdparty
.
setApplicationNumber
(
cardxx
.
get
(
2
).
text
());
thirdparty
.
setZfjg
(
cardxx
.
get
(
3
).
text
());
thirdparty
.
setType
(
cardxx
.
get
(
4
).
text
());
thirdparty
.
setStatus
(
cardxx
.
get
(
5
).
text
());
thirdparty
.
setMomey
(
cardxx
.
get
(
6
).
text
());
thirdparty
.
setThirdpartyResults
(
cardxx
.
get
(
7
).
text
());
thirdparty
.
setLrr
(
cardxx
.
get
(
8
).
text
());
thirdparty
.
setLrdw
(
cardxx
.
get
(
9
).
text
());
thirdparty
.
setLrsj
(
cardxx
.
get
(
10
).
text
());
System
.
out
.
println
(
"数据card====="
+
JSON
.
toJSONString
(
thirdparty
));
thirdpartyList
.
add
(
thirdparty
);
}
//页数
Elements
pageinfos
=
document
.
getElementsByClass
(
"next-page"
).
select
(
"p"
);
Elements
page
=
pageinfos
.
get
(
0
).
select
(
"span"
);
//page.get(1).text();
//结果数据展示
/* JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(cardList));
System.out.println(jsonArray);*/
int
num
=
Integer
.
parseInt
(
page
.
get
(
1
).
text
())*
15
;
listmap
.
put
(
"data"
,
thirdpartyList
);
listmap
.
put
(
"recordsTotal"
,
num
);
listmap
.
put
(
"recordsFiltered"
,
num
);
listmap
.
put
(
"draw"
,
""
);
return
listmap
;
}
public
String
saveQueryLog
()
throws
Exception
{
String
uuid
=
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
uuid
=
uuid
.
substring
(
0
,
uuid
.
length
()-
2
);
return
uuid
;
}
}
src/main/java/com/founder/model/card.java
View file @
c0932418
...
...
@@ -17,6 +17,7 @@ public class card extends page{
private
String
lrsj
;
//录入时间
private
String
lrdw
;
//录入单位
private
String
curPage
;
//当前页
private
String
page
;
//当前页
private
String
kssj
;
private
String
jzsj
;
...
...
@@ -139,4 +140,11 @@ public class card extends page{
public
void
setCurPage
(
String
curPage
)
{
this
.
curPage
=
curPage
;
}
public
String
getPage
()
{
return
page
;
}
public
void
setPage
(
String
page
)
{
this
.
page
=
page
;
}
}
src/main/java/com/founder/service/CardinfosServiceNew.java
0 → 100644
View file @
c0932418
package
com
.
founder
.
service
;
import
com.founder.model.XzxtRestResult
;
import
com.founder.model.card
;
import
com.founder.model.thirdparty
;
/**
* @author yutons
*/
public
interface
CardinfosServiceNew
{
public
XzxtRestResult
getCardinfos
(
card
card
)
;
public
XzxtRestResult
getCardliushui
(
card
card
)
;
public
XzxtRestResult
getThirdpartys
(
thirdparty
thirdparty
)
;
}
src/main/java/com/founder/service/impl/CardinfosServiceNewImpl.java
0 → 100644
View file @
c0932418
package
com
.
founder
.
service
.
impl
;
import
com.founder.jsoup.JsoupCookieCraw
;
import
com.founder.jsoup.JsoupCookieCrawNew
;
import
com.founder.model.XzxtRestResult
;
import
com.founder.model.card
;
import
com.founder.model.cardliushui
;
import
com.founder.model.thirdparty
;
import
com.founder.service.CardinfosService
;
import
com.founder.service.CardinfosServiceNew
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
CardinfosServiceNewImpl
implements
CardinfosServiceNew
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CardinfosServiceNewImpl
.
class
);
@Value
(
"${dzpt.card.url}"
)
private
String
cardurl
;
@Value
(
"${dzpt.cardliushui.url}"
)
private
String
cardliushuiurl
;
@Value
(
"${dzpt.thirdparty.url}"
)
private
String
thirdpartyurl
;
@Autowired
private
JsoupCookieCrawNew
jsoupCookieCrawNew
;
@Override
public
XzxtRestResult
getCardinfos
(
card
card
)
{
Map
<
String
,
String
>
cookies
=
null
;
Map
<
String
,
Object
>
cardlistmap
=
new
HashMap
<
String
,
Object
>();
try
{
//1、登录
cookies
=
jsoupCookieCrawNew
.
login
();
System
.
out
.
print
(
"登录反诈平台获取cookies==="
+
cookies
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 直接获取DOM树,带着cookies去获取
//pageList.curPage: 1 yhzh.kssj: 2019-05-27 yhzh.xfzt: all
Document
document
=
null
;
try
{
document
=
Jsoup
.
connect
(
cardurl
)
.
cookies
(
cookies
)
.
timeout
(
60000
)
.
data
(
"pageList.curPage"
,
card
.
getPage
())
.
data
(
"yhzh.zh"
,
card
.
getAccount
())
.
post
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
document
.
toString
());
List
<
card
>
cardList
=
new
ArrayList
<
card
>();
cardlistmap
=
jsoupCookieCrawNew
.
getCardInfo
(
document
);
if
(!
StringUtils
.
isEmpty
(
cardList
)){
return
XzxtRestResult
.
build
(
201
,
"成功获取"
,
cardlistmap
);
}
else
{
return
XzxtRestResult
.
build
(
201
,
"暂无数据"
,
cardlistmap
);
}
}
@Override
public
XzxtRestResult
getCardliushui
(
card
card
)
{
Map
<
String
,
String
>
cookies
=
null
;
Map
<
String
,
Object
>
cardlistmap
=
new
HashMap
<
String
,
Object
>();
try
{
//1、登录
cookies
=
jsoupCookieCrawNew
.
login
();
System
.
out
.
print
(
"登录反诈平台获取cookies==="
+
cookies
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 直接获取DOM树,带着cookies去获取
//pageList.curPage: 1 yhzh.kssj: 2019-05-27 yhzh.xfzt: all
Document
document
=
null
;
try
{
document
=
Jsoup
.
connect
(
cardliushuiurl
)
.
cookies
(
cookies
)
.
timeout
(
60000
)
.
data
(
"pageList.curPage"
,
card
.
getPage
())
.
data
(
"yhzh.zh"
,
card
.
getAccount
())
//账号
.
data
(
"yhzh.ywsqbh"
,
card
.
getApplicationNumber
())
//业务申请编号
.
post
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
document
.
toString
());
List
<
cardliushui
>
cardList
=
new
ArrayList
<
cardliushui
>();
cardlistmap
=
jsoupCookieCrawNew
.
getCardLsInfo
(
document
);
if
(!
StringUtils
.
isEmpty
(
cardList
)){
return
XzxtRestResult
.
build
(
201
,
"成功获取"
,
cardlistmap
);
}
else
{
return
XzxtRestResult
.
build
(
201
,
"暂无数据"
,
cardlistmap
);
}
}
@Override
public
XzxtRestResult
getThirdpartys
(
thirdparty
thirdparty
)
{
Map
<
String
,
String
>
cookies
=
null
;
Map
<
String
,
Object
>
cardlistmap
=
new
HashMap
<
String
,
Object
>();
try
{
//1、登录
cookies
=
jsoupCookieCrawNew
.
login
();
System
.
out
.
print
(
"登录反诈平台获取cookies==="
+
cookies
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// 直接获取DOM树,带着cookies去获取
//pageList.curPage: 1 yhzh.kssj: 2019-05-27 yhzh.xfzt: all
Document
document
=
null
;
try
{
document
=
Jsoup
.
connect
(
thirdpartyurl
)
.
cookies
(
cookies
)
.
timeout
(
60000
)
.
data
(
"pageList.curPage"
,
thirdparty
.
getCurPage
())
.
data
(
"sfzfQq.zh"
,
thirdparty
.
getZh
())
.
post
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
document
.
toString
());
List
<
thirdparty
>
thirdpartyList
=
new
ArrayList
<
thirdparty
>();
cardlistmap
=
jsoupCookieCrawNew
.
getThirdpartys
(
document
);
if
(!
StringUtils
.
isEmpty
(
thirdpartyList
)){
return
XzxtRestResult
.
build
(
201
,
"成功获取"
,
cardlistmap
);
}
else
{
return
XzxtRestResult
.
build
(
201
,
"暂无数据"
,
cardlistmap
);
}
}
}
src/main/resources/templates/form.html
View file @
c0932418
...
...
@@ -43,7 +43,7 @@
})
}
function
submit
()
{
var
data
=
{
"account"
:
"6217850800004919054"
,
"
curPage
"
:
"1"
}
var
data
=
{
"account"
:
"6217850800004919054"
,
"
draw
"
:
"1"
}
//console.info("2222222222"+JSON.stringify(data1));
$
.
ajax
({
method
:
'post'
,
...
...
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