Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
toutiao
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
zhiwei
toutiao
Commits
1d1ff5f8
Commit
1d1ff5f8
authored
Dec 19, 2019
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交新的js加密参数
parent
061bc022
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
205 deletions
+201
-205
pom.xml
+1
-1
src/main/java/com/zhiwei/toutiao/bean/Signature.java
+200
-204
No files found.
pom.xml
View file @
1d1ff5f8
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<dependency>
<dependency>
<groupId>
com.zhiwei.crawler
</groupId>
<groupId>
com.zhiwei.crawler
</groupId>
<artifactId>
crawler-core
</artifactId>
<artifactId>
crawler-core
</artifactId>
<version>
0.5.
2-SNAPSHOT
</version>
<version>
0.5.
6.2-RELEASE
</version>
<scope>
provided
</scope>
<scope>
provided
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
...
...
src/main/java/com/zhiwei/toutiao/bean/Signature.java
View file @
1d1ff5f8
package
com
.
zhiwei
.
toutiao
.
bean
;
package
com
.
zhiwei
.
toutiao
.
bean
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Date
;
import
java.util.Date
;
import
javax.script.Invocable
;
import
javax.script.Invocable
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngineManager
;
import
javax.script.ScriptEngineManager
;
/**
/**
* 今日头条签名类
* 今日头条签名类
* @author bewiler hk
* @author bewiler hk
*
*
*/
*/
public
class
Signature
{
public
class
Signature
{
private
String
cp
;
private
String
cp
;
private
String
as
;
private
String
as
;
private
String
signature
;
private
String
signature
;
public
Signature
(
String
userId
,
String
max_behot_time
){
public
Signature
(
String
userId
,
String
max_behot_time
){
this
.
signature
=
this
.
getSign
(
userId
,
max_behot_time
);
this
.
signature
=
this
.
getSign
(
userId
,
max_behot_time
);
getASCP
();
getASCP
();
}
}
public
Signature
(){
public
Signature
(){
getASCP
();
getASCP
();
}
}
public
String
getCp
()
{
public
String
getCp
()
{
return
cp
;
return
cp
;
}
}
public
String
getAs
()
{
public
String
getAs
()
{
return
as
;
return
as
;
}
}
public
String
getSignature
()
{
public
String
getSignature
()
{
return
signature
;
return
signature
;
}
}
/**
/**
* 获取加密参数
* 获取加密参数
* @return
* @return
* @throws IOException
* @throws IOException
*/
*/
private
String
getSign
(
String
userId
,
String
max_behot_time
){
private
String
getSign
(
String
userId
,
String
maxBehotTime
){
ScriptEngineManager
manager
=
new
ScriptEngineManager
();
ScriptEngineManager
manager
=
new
ScriptEngineManager
();
ScriptEngine
engine
=
manager
.
getEngineByName
(
"javascript"
);
ScriptEngine
engine
=
manager
.
getEngineByName
(
"javascript"
);
String
jsText
=
getJSText
();
// 读取js文件
String
jsText
=
getJSText
();
// 读取js文件
String
str
=
"0"
;
String
str
=
"https://www.toutiao.com/toutiao/api/pc/feed/?category=pc_profile_ugc&utm_source=toutiao&visit_user_id="
+
userId
+
"&max_behot_time="
+
maxBehotTime
;
if
(
userId
!=
null
){
try
{
str
=
userId
+
max_behot_time
;
engine
.
eval
(
jsText
);
}
if
(
engine
instanceof
Invocable
)
{
try
{
Invocable
invoke
=
(
Invocable
)
engine
;
engine
.
eval
(
jsText
);
String
sign
=
invoke
.
invokeFunction
(
"merge"
,
str
).
toString
();
if
(
engine
instanceof
Invocable
)
{
return
sign
;
Invocable
invoke
=
(
Invocable
)
engine
;
}
String
sign
=
invoke
.
invokeFunction
(
"merge"
,
str
).
toString
();
}
catch
(
Exception
e
)
{
return
sign
;
e
.
printStackTrace
();
}
}
}
catch
(
Exception
e
)
{
return
null
;
e
.
printStackTrace
();
}
}
return
null
;
}
/**
* @Title: getAS
* @Description: TODO(获取今日头条加密值)
/**
* @param @return 设定文件
* @Title: getAS
* @return String 返回类型
* @Description: TODO(获取今日头条加密值)
*/
* @param @return 设定文件
private
void
getASCP
()
* @return String 返回类型
{
*/
long
i
=
(
long
)
Math
.
floor
(
new
Date
().
getTime
()/
1000L
);
private
void
getASCP
()
String
t
=
Long
.
toHexString
(
i
).
toUpperCase
();
{
char
[]
ts
=
t
.
toCharArray
();
long
i
=
(
long
)
Math
.
floor
(
new
Date
().
getTime
()/
1000L
);
String
e
=
parseStrToMd5L32
(
i
+
""
).
toString
().
toUpperCase
();
String
t
=
Long
.
toHexString
(
i
).
toUpperCase
();
char
[]
s
=
e
.
substring
(
0
,
5
).
toCharArray
();
char
[]
ts
=
t
.
toCharArray
();
char
[]
a
=
e
.
substring
(
e
.
length
()-
5
,
e
.
length
()).
toCharArray
();
String
e
=
parseStrToMd5L32
(
i
+
""
).
toString
().
toUpperCase
();
String
c
=
""
;
char
[]
s
=
e
.
substring
(
0
,
5
).
toCharArray
();
String
o
=
""
;
char
[]
a
=
e
.
substring
(
e
.
length
()-
5
,
e
.
length
()).
toCharArray
();
for
(
int
n
=
0
;
5
>
n
;
n
++)
String
c
=
""
;
{
String
o
=
""
;
o
+=
""
+
s
[
n
]
+
ts
[
n
];
for
(
int
n
=
0
;
5
>
n
;
n
++)
}
{
for
(
int
r
=
0
;
5
>
r
;
r
++)
o
+=
""
+
s
[
n
]
+
ts
[
n
];
{
}
c
+=
""
+
ts
[
r
+
3
]
+
a
[
r
];
for
(
int
r
=
0
;
5
>
r
;
r
++)
}
{
String
as
=
"A1"
+
o
+
t
.
substring
(
t
.
length
()-
3
,
t
.
length
());
c
+=
""
+
ts
[
r
+
3
]
+
a
[
r
];
String
cp
=
t
.
substring
(
0
,
3
)
+
c
+
"E1"
;
}
this
.
as
=
as
;
String
as
=
"A1"
+
o
+
t
.
substring
(
t
.
length
()-
3
,
t
.
length
());
this
.
cp
=
cp
;
String
cp
=
t
.
substring
(
0
,
3
)
+
c
+
"E1"
;
}
this
.
as
=
as
;
this
.
cp
=
cp
;
/**
}
* 计算字符串Md5
* @Title: md5
/**
* @param str
* 计算字符串Md5
* @return String
* @Title: md5
*/
* @param str
public
static
String
md5
(
String
str
)
{
* @return String
String
result
=
null
;
*/
try
{
public
static
String
md5
(
String
str
)
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
String
result
=
null
;
byte
[]
bytes
=
str
.
getBytes
(
"utf-8"
);
try
{
md
.
update
(
bytes
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
bytes
=
md
.
digest
();
byte
[]
bytes
=
str
.
getBytes
(
"utf-8"
);
result
=
bytesToHexString
(
bytes
);
md
.
update
(
bytes
);
}
catch
(
Exception
e
)
{}
bytes
=
md
.
digest
();
return
result
;
result
=
bytesToHexString
(
bytes
);
}
}
catch
(
Exception
e
)
{}
return
result
;
}
/**
* 将二进制转换成16进制字符串
* @Title bytesToHexString
/**
* @return String
* 将二进制转换成16进制字符串
*/
* @Title bytesToHexString
private
static
String
bytesToHexString
(
byte
bytes
[])
{
* @param buf
String
result
=
null
;
* @return String
if
(
bytes
!=
null
)
{
*/
if
(
bytes
.
length
>
0
)
{
private
static
String
bytesToHexString
(
byte
bytes
[])
{
StringBuffer
sb
=
new
StringBuffer
();
String
result
=
null
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
if
(
bytes
!=
null
)
{
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
0xFF
);
if
(
bytes
.
length
>
0
)
{
if
(
hex
.
length
()
==
1
)
{
StringBuffer
sb
=
new
StringBuffer
();
hex
=
'0'
+
hex
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
}
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
0xFF
);
sb
.
append
(
hex
);
if
(
hex
.
length
()
==
1
)
{
}
hex
=
'0'
+
hex
;
result
=
sb
.
toString
().
toLowerCase
();
}
}
sb
.
append
(
hex
);
}
}
return
result
;
result
=
sb
.
toString
().
toLowerCase
();
}
}
}
/**
return
result
;
* @param str
}
* @return
* @Date: 2013-9-6
/**
* @Author: lulei
* @param str
* @Description: 32位小写MD5
* @return
*/
* @Date: 2013-9-6
public
static
String
parseStrToMd5L32
(
String
str
){
* @Author: lulei
String
reStr
=
null
;
* @Description: 32位小写MD5
try
{
*/
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
public
static
String
parseStrToMd5L32
(
String
str
){
byte
[]
bytes
=
md5
.
digest
(
str
.
getBytes
());
String
reStr
=
null
;
StringBuffer
stringBuffer
=
new
StringBuffer
();
try
{
for
(
byte
b
:
bytes
){
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
int
bt
=
b
&
0xff
;
byte
[]
bytes
=
md5
.
digest
(
str
.
getBytes
());
if
(
bt
<
16
){
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
0
);
for
(
byte
b
:
bytes
){
}
int
bt
=
b
&
0xff
;
stringBuffer
.
append
(
Integer
.
toHexString
(
bt
));
if
(
bt
<
16
){
}
stringBuffer
.
append
(
0
);
reStr
=
stringBuffer
.
toString
();
}
}
catch
(
NoSuchAlgorithmException
e
)
{
stringBuffer
.
append
(
Integer
.
toHexString
(
bt
));
e
.
printStackTrace
();
}
}
reStr
=
stringBuffer
.
toString
();
return
reStr
;
}
catch
(
NoSuchAlgorithmException
e
)
{
}
e
.
printStackTrace
();
}
return
reStr
;
/**
}
* 读取js文件
* @return
*/
/**
private
String
getJSText
()
{
* 读取js文件
try
{
* @return
StringBuffer
sb
=
new
StringBuffer
();
*/
InputStream
is
=
Thread
.
currentThread
().
getContextClassLoader
()
private
String
getJSText
()
{
.
getResourceAsStream
(
"signature.js"
);
try
{
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
StringBuffer
sb
=
new
StringBuffer
();
String
line
=
""
;
InputStream
is
=
Thread
.
currentThread
().
getContextClassLoader
()
while
((
line
=
br
.
readLine
())!=
null
)
.
getResourceAsStream
(
"signature.js"
);
{
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
is
));
sb
.
append
(
line
);
String
line
=
""
;
}
while
((
line
=
br
.
readLine
())!=
null
)
br
.
close
();
{
return
sb
.
toString
();
sb
.
append
(
line
);
}
catch
(
IOException
e
)
{
}
return
null
;
br
.
close
();
}
return
sb
.
toString
();
}
}
catch
(
IOException
e
)
{
return
null
;
}
}
}
}
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