Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat
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
chenweiyang
wechat
Commits
50a50f32
Commit
50a50f32
authored
Oct 29, 2019
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加根据链接及cookie获取真实链接
parent
8877f8ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
26 deletions
+34
-26
src/main/java/com/zhiwei/wechat/search/WechatAritcleSearch.java
+34
-26
No files found.
src/main/java/com/zhiwei/wechat/search/WechatAritcleSearch.java
View file @
50a50f32
...
@@ -2,12 +2,17 @@ package com.zhiwei.wechat.search;
...
@@ -2,12 +2,17 @@ package com.zhiwei.wechat.search;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.InetSocketAddress
;
import
java.net.Proxy
;
import
java.net.Proxy
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.security.MessageDigest
;
import
java.util.*
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
okhttp3.Headers
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -434,13 +439,10 @@ public class WechatAritcleSearch {
...
@@ -434,13 +439,10 @@ public class WechatAritcleSearch {
/**
/**
* 获取真实链接
* 获取真实链接
* @param originalUrl
* @param originalUrl
* @param searchUrl
* @return
* @return
* @throws IOException
* @throws IOException
*/
*/
public
static
String
getRealLink
(
String
originalUrl
,
String
searchUrl
)
throws
Exception
{
public
static
String
getRealLink
(
String
originalUrl
,
String
cookie
)
throws
Exception
{
originalUrl
=
originalUrl
;
int
b
=
(
int
)
(
Math
.
floor
(
100
*
Math
.
random
())
+
1
);
int
b
=
(
int
)
(
Math
.
floor
(
100
*
Math
.
random
())
+
1
);
int
a
=
originalUrl
.
indexOf
(
"url="
);
int
a
=
originalUrl
.
indexOf
(
"url="
);
int
c
=
originalUrl
.
indexOf
(
"&k="
);
int
c
=
originalUrl
.
indexOf
(
"&k="
);
...
@@ -449,43 +451,49 @@ public class WechatAritcleSearch {
...
@@ -449,43 +451,49 @@ public class WechatAritcleSearch {
d
=
originalUrl
.
substring
(
a
+
25
+
b
,
a
+
26
+
b
);
d
=
originalUrl
.
substring
(
a
+
25
+
b
,
a
+
26
+
b
);
}
}
originalUrl
+=
"&k="
+
b
+
"&h="
+
d
;
originalUrl
+=
"&k="
+
b
+
"&h="
+
d
;
String
realUrl
=
getFinalUrl
(
originalUrl
,
cookie
);
originalUrl
=
getFinalUrl
(
originalUrl
,
searchUrl
);
return
realUrl
;
return
originalUrl
;
}
}
/**
/**
* 获取真实链接
* 获取真实链接
* @param originalUrl
* @param originalUrl
* @param rerferer
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
static
String
getFinalUrl
(
String
originalUrl
,
String
rerferer
)
throws
Exception
{
private
static
String
getFinalUrl
(
String
originalUrl
,
String
cookie
)
throws
Exception
{
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
String
word
=
originalUrl
.
split
(
"query="
)[
1
];
headerMap
.
put
(
"Sec-Fetch-Mode"
,
"navigate"
);
String
searchUrl
=
"https://weixin.sogou.com/weixin?query="
+
word
;
headerMap
.
put
(
"Sec-Fetch-User"
,
"?1"
);
if
(
StringUtils
.
isNotBlank
(
cookie
)){
headerMap
.
put
(
"Accept"
,
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
);
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
headerMap
.
put
(
"Sec-Fetch-Site"
,
"same-origin"
);
headerMap
.
put
(
"Sec-Fetch-Mode"
,
"navigate"
);
headerMap
.
put
(
"Referer"
,
rerferer
);
headerMap
.
put
(
"Sec-Fetch-User"
,
"?1"
);
headerMap
.
put
(
"Cookie"
,
"SUID=EAD6E7733765860A5AEAE09C000ACA78; SUV=00C351E873E7D6EA5AEBCB68E5B81671; wuid=AAGyrPzuHwAAAAqLFD3eFgAAGwY=; pgv_pvi=5713931264; GOTO=; ssuid=5316643370; pex=C864C03270DED3DD8A06887A372DA219231FFAC25A9D64AE09E82AED12E416AC; weixinIndexVisited=1; ABTEST=8|1572271712|v1; SNUID=C5F9D7432F2ABAD638CB0A7A30803056; sct=917; JSESSIONID=aaaR-8KOdPrlZ_KSPKs4w; PHPSESSID=oc296ck54mc3jbgvnu2mar6r40; IPLOC=CN3302"
);
headerMap
.
put
(
"Accept"
,
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
);
headerMap
.
put
(
"Sec-Fetch-Site"
,
"same-origin"
);
headerMap
.
put
(
"Upgrade-Insecure-Requests"
,
"1"
);
headerMap
.
put
(
"Connection"
,
"keep-alive"
);
headerMap
.
put
(
"Host"
,
"weixin.sogou.com"
);
headerMap
.
put
(
"Accept-Encoding"
,
"gzip, deflate, br"
);
headerMap
.
put
(
"Accept-Language"
,
"zh-CN,zh;q=0.9"
);
headerMap
.
put
(
"Cache-Control"
,
"no-cache"
);
headerMap
.
put
(
"Referer"
,
searchUrl
);
headerMap
.
put
(
"Cookie"
,
cookie
);
String
htmlBody
=
httpBoot
.
syncCall
(
RequestUtils
.
wrapGet
(
originalUrl
,
headerMap
),
ProxyHolder
.
NAT_HEAVY_PROXY
).
body
().
string
();
String
htmlBody
=
httpBoot
.
syncCall
(
RequestUtils
.
wrapGet
(
originalUrl
,
headerMap
)).
body
().
string
();
if
(
StringUtils
.
isNotBlank
(
htmlBody
)
){
if
(
StringUtils
.
isNotBlank
(
htmlBody
)
){
StringBuilder
furl
=
new
StringBuilder
();
StringBuilder
furl
=
new
StringBuilder
();
Pattern
pa1
=
Pattern
.
compile
(
"url \\+= \'(.*?)\';"
);
Pattern
pa1
=
Pattern
.
compile
(
"url \\+= \'(.*?)\';"
);
Matcher
ma1
=
pa1
.
matcher
(
htmlBody
);
Matcher
ma1
=
pa1
.
matcher
(
htmlBody
);
while
(
ma1
.
find
())
{
while
(
ma1
.
find
())
{
furl
.
append
(
ma1
.
group
(
1
));
furl
.
append
(
ma1
.
group
(
1
));
}
return
furl
.
toString
();
}
}
return
furl
.
toString
();
}
}
return
null
;
return
null
;
}
}
/**
/**
* @Title: getOpenId
* @Title: getOpenId
* @Description: 获取微信wxID
* @Description: 获取微信wxID
...
...
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