pull/21/head
fengyuecanzhu 3 years ago
parent c84501c18e
commit ceaed6a5dc
  1. 36
      app/src/main/java/xyz/fycz/myreader/ui/activity/AboutActivity.java
  2. 114
      app/src/main/java/xyz/fycz/myreader/webapi/LanZouApi.kt
  3. 29
      app/src/main/res/layout/layout_about_content.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -3,9 +3,12 @@ package xyz.fycz.myreader.ui.activity;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -33,6 +36,7 @@ import xyz.fycz.myreader.util.utils.FileUtils;
import xyz.fycz.myreader.util.utils.ImageLoader; import xyz.fycz.myreader.util.utils.ImageLoader;
import xyz.fycz.myreader.util.utils.OkHttpUtils; import xyz.fycz.myreader.util.utils.OkHttpUtils;
import xyz.fycz.myreader.util.utils.RxUtils; import xyz.fycz.myreader.util.utils.RxUtils;
import xyz.fycz.myreader.webapi.LanZouApi;
/** /**
* @author fengyue * @author fengyue
@ -59,6 +63,7 @@ public class AboutActivity extends BaseActivity {
protected void initWidget() { protected void initWidget() {
super.initWidget(); super.initWidget();
binding.il.tvVersionName.setText(String.format("风月读书v%s", App.getStrVersionName())); binding.il.tvVersionName.setText(String.format("风月读书v%s", App.getStrVersionName()));
binding.il.rlLanZou.setVisibility(App.isDebug() ? View.VISIBLE : View.GONE);
} }
@Override @Override
@ -110,6 +115,37 @@ public class AboutActivity extends BaseActivity {
.showFullWebViewDia(this, "file:///android_asset/PrivacyPolicy.html", .showFullWebViewDia(this, "file:///android_asset/PrivacyPolicy.html",
false, null)); false, null));
binding.il.rlDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy")); binding.il.rlDisclaimer.setOnClickListener(v -> DialogCreator.createAssetTipDialog(this, "免责声明", "disclaimer.fy"));
binding.il.rlLanZou.setOnClickListener(v -> {
String[] str = new String[1];
MyAlertDialog.createInputDia(this, getString(R.string.lan_zou_parse),
"格式:链接+逗号+密码(没有密码就不用填)", "", true,
100, text -> str[0] = text, (dialog, which) -> {
String url, pwd = "";
if (str[0].contains(",") || str[0].contains(",")) {
String[] strs = str[0].split("[,,]");
url = strs[0];
pwd = strs[1];
} else {
url = str[0];
}
LanZouApi.INSTANCE.getUrl(url, pwd)
.compose(RxUtils::toSimpleSingle)
.subscribe(new MyObserver<String>() {
@Override
public void onNext(@NonNull String s) {
ToastUtils.showInfo(s);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(s));
startActivity(intent);
}
@Override
public void onError(Throwable e) {
ToastUtils.showError("" + e.getLocalizedMessage());
}
});
});
});
} }
void openIntent(String intentName, String address) { void openIntent(String intentName, String address) {

@ -0,0 +1,114 @@
package xyz.fycz.myreader.webapi
import io.reactivex.Observable
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import org.jsoup.Jsoup
import xyz.fycz.myreader.common.URLCONST
import xyz.fycz.myreader.util.help.StringHelper
import xyz.fycz.myreader.util.utils.OkHttpUtils
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
/**
* @author fengyue
* @date 2022/1/22 18:50
*/
object LanZouApi {
/**
* 通过api获取蓝奏云可下载直链
*
* @param url
* @param password
*/
fun getUrl(url: String, password: String = ""): Observable<String> {
return Observable.create {
val html = OkHttpUtils.getHtml(url)
val url2 = if (password.isEmpty()) {
val url1 = getUrl1(html)
val key = getKey(OkHttpUtils.getHtml(url1))
getUrl2(key, url1)
} else {
getUrl2(StringHelper.getSubString(html, "sign=", "&"), url, password)
}
it.onNext(getRedirectUrl(url2))
it.onComplete()
}
}
private fun getUrl1(html: String): String {
val doc = Jsoup.parse(html)
return URLCONST.LAN_ZOUS_URL + doc.getElementsByClass("ifr2").attr("src")
}
private fun getKey(html: String): String {
var lanzousKeyStart = "var pposturl = '"
val keyName = StringHelper.getSubString(html, "'sign':", ",")
lanzousKeyStart = if (keyName.endsWith("'")) {
"'sign':'"
} else {
"var $keyName = '"
}
return StringHelper.getSubString(html, lanzousKeyStart, "'")
}
private fun getUrl2(key: String, referer: String, password: String = ""): String {
val mediaType = "application/x-www-form-urlencoded".toMediaTypeOrNull()
val body = if (password.isEmpty()) {
"action=downprocess&sign=$key&ves=1"
} else {
"action=downprocess&sign=$key&p=$password"
}
val requestBody = body.toRequestBody(mediaType)
val headers = HashMap<String, String>()
headers["Referer"] = referer
val html = OkHttpUtils.getHtml(
URLCONST.LAN_ZOUS_URL + "/ajaxm.php", requestBody,
"UTF-8", headers
)
return getUrl2(html)
}
private fun getUrl2(o: String): String {
val info = o.split(",").toTypedArray()
val zt = info[0].substring(info[0].indexOf(":") + 1)
if (!"1".endsWith(zt)) {
return ""
}
var dom = info[1].substring(info[1].indexOf(":") + 2, info[1].lastIndexOf("\""))
var url = info[2].substring(info[2].indexOf(":") + 2, info[2].lastIndexOf("\""))
dom = dom.replace("\\", "")
url = url.replace("\\", "")
return "$dom/file/$url"
}
/**
* 获取重定向地址
*
* @param path
*/
private fun getRedirectUrl(path: String): String {
val conn = URL(path)
.openConnection() as HttpURLConnection
conn.instanceFollowRedirects = false
conn.connectTimeout = 5000
conn.setRequestProperty(
"User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
)
conn.setRequestProperty("Accept-Language", "zh-cn")
conn.setRequestProperty("Connection", "Keep-Alive")
conn.setRequestProperty(
"Accept",
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */*"
)
conn.connect()
val redirectUrl = conn.getHeaderField("Location")
conn.disconnect()
return redirectUrl
}
}

@ -333,6 +333,35 @@
app:srcCompat="@drawable/ic_right_arrow" app:srcCompat="@drawable/ic_right_arrow"
app:tint="@color/textSecondary" /> app:tint="@color/textSecondary" />
</RelativeLayout> </RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp" />
<RelativeLayout
android:id="@+id/rl_lan_zou"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/selector_common_bg"
android:gravity="center"
android:paddingStart="20dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/lan_zou_parse"
android:textColor="@color/textPrimary"
android:textSize="@dimen/text_normal_size" />
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_right_arrow"
app:tint="@color/textSecondary" />
</RelativeLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

@ -542,6 +542,7 @@
<string name="net_error_10002">网络连接超时</string> <string name="net_error_10002">网络连接超时</string>
<string name="net_error_10003">数据解析失败</string> <string name="net_error_10003">数据解析失败</string>
<string name="copy_source">拷贝书源</string> <string name="copy_source">拷贝书源</string>
<string name="lan_zou_parse">蓝奏云直链解析</string>
<!--error string end--> <!--error string end-->
<string-array name="reset_screen_time"> <string-array name="reset_screen_time">

Loading…
Cancel
Save