-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
72 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/kunfei/bookshelf/help/JsExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.kunfei.bookshelf.help; | ||
|
||
import com.kunfei.bookshelf.base.BaseModelImpl; | ||
import com.kunfei.bookshelf.model.analyzeRule.AnalyzeUrl; | ||
import com.kunfei.bookshelf.utils.StringUtils; | ||
|
||
import org.jsoup.Connection; | ||
import org.jsoup.Jsoup; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import retrofit2.Response; | ||
|
||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
public class JsExtensions { | ||
|
||
/** | ||
* js实现跨域访问,不能删 | ||
*/ | ||
public String ajax(String urlStr) { | ||
try { | ||
AnalyzeUrl analyzeUrl = new AnalyzeUrl(urlStr); | ||
Response<String> response = BaseModelImpl.getInstance().getResponseO(analyzeUrl) | ||
.blockingFirst(); | ||
return response.body(); | ||
} catch (Exception e) { | ||
return e.getLocalizedMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* js实现解码,不能删 | ||
*/ | ||
public String base64Decoder(String base64) { | ||
return StringUtils.base64Decode(base64); | ||
} | ||
|
||
/** | ||
* 章节数转数字 | ||
*/ | ||
public String toNumChapter(String s) { | ||
if (s == null) { | ||
return null; | ||
} | ||
Pattern pattern = Pattern.compile("(第)(.+?)(章)"); | ||
Matcher matcher = pattern.matcher(s); | ||
if (matcher.find()) { | ||
return matcher.group(1) + StringUtils.stringToInt(matcher.group(2)) + matcher.group(3); | ||
} | ||
return s; | ||
} | ||
|
||
/** | ||
* js实现重定向拦截,不能删 | ||
*/ | ||
public Connection.Response get(String urlStr, Map<String, String> headers) throws IOException { | ||
return Jsoup.connect(urlStr) | ||
.sslSocketFactory(SSLSocketClient.getSSLSocketFactory()) | ||
.ignoreContentType(true) | ||
.followRedirects(false) | ||
.headers(headers) | ||
.method(Connection.Method.GET) | ||
.execute(); | ||
} | ||
|
||
/** | ||
* js实现重定向拦截,不能删 | ||
*/ | ||
public Connection.Response post(String urlStr, String body, Map<String, String> headers) throws IOException { | ||
return Jsoup.connect(urlStr) | ||
.sslSocketFactory(SSLSocketClient.getSSLSocketFactory()) | ||
.ignoreContentType(true) | ||
.followRedirects(false) | ||
.requestBody(body) | ||
.headers(headers) | ||
.method(Connection.Method.POST) | ||
.execute(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters