修改包名

master
Z 4 years ago
parent 517ca3016e
commit 7c82e5dcfe
  1. 6
      app/src/main/java/com/novel/read/constant/AppConst.kt
  2. 26
      app/src/main/java/com/novel/read/data/model/CheckSumDTO.kt
  3. 13
      app/src/main/java/com/novel/read/network/ServiceCreator.kt
  4. 94
      app/src/main/java/com/novel/read/utils/CheckSumBuilder.java
  5. 11
      app/src/main/java/com/novel/read/utils/ext/GsonExtensions.kt

@ -8,13 +8,11 @@ import java.text.SimpleDateFormat
object AppConst {
const val APP_TAG = "TuZi"
const val AppId = "20210306161"
const val AppSecret = "c14f6a2b3dcah893a31b9i4f40f5cc08"
const val channelIdDownload = "channel_download"
const val channelIdReadAloud = "channel_read_aloud"
const val channelIdWeb = "channel_web"
const val UA_NAME = "User-Agent"
const val CONCEAL = "http://yijianda8.com/conceal/"
val timeFormat: SimpleDateFormat by lazy {
SimpleDateFormat("HH:mm")

@ -0,0 +1,26 @@
package com.novel.read.data.model
/**
* @description: 参数校验DTO
* @author: zlj
* @date: 2020/9/25 9:50
*/
class CheckSumDTO(
/**
* 对外接口接入方 appid
*/
private var appid: String,
/**
* 随机数最大128位
*/
private var nonce: String,
/**
* 当前UTC时间戳从1970年1月1日0点0 分0 秒开始到现在的秒数(String)接口调用有效期为该时间戳起5分钟内
*/
private var curtime: String,
/**
* SHA1(AppSecret+Nonce+curTime),三个参数拼接的字符串进行SHA1哈希计算
* 转化成16进制字符(String, 小写)其中AppSecret为平台分配的Appid对应的AppSecret密钥
*/
private var checksum: String
)

@ -1,7 +1,11 @@
package com.novel.read.network
import android.util.Log
import com.novel.read.constant.AppConst
import com.novel.read.data.model.CheckSumDTO
import com.novel.read.network.api.BookService
import com.novel.read.utils.CheckSumBuilder
import com.novel.read.utils.ext.MYGSON
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
@ -131,8 +135,17 @@ object ServiceCreator {
class HeaderInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val original = chain.request()
val time = System.currentTimeMillis().toString()
val nonce = CheckSumBuilder.getRandomString(8)
val checkSum = CheckSumBuilder.getCheckSum(
AppConst.AppSecret,
nonce,
time
)
val checkSha = MYGSON.toJson(CheckSumDTO(AppConst.AppId,nonce,time,checkSum))
val request = original.newBuilder().apply {
header("model", "Android")
// header("checkSumDTO", checkSha)
header("If-Modified-Since", URLEncoder.encode("${Date()}", "utf-8"))
header("User-Agent", System.getProperty("http.agent") ?: "unknown")
}.build()

@ -0,0 +1,94 @@
package com.novel.read.utils;
import java.security.MessageDigest;
import java.util.Random;
/**
* 功能说明验证码生成工具类
* 修改说明
* @author hu
* @date 2021年4月6日 下午1:33:26
* @version 0.1
*/
public class CheckSumBuilder {
/**
* 功能说明计算并获取CheckSum
* 修改说明
* @author hu
* @date 2021年4月6日 下午1:33:26
* @param appSecret 密码
* @param nonce 随机串
* @param curTime 当前时间戳
* @return 返回生成的验证码
*/
public static String getCheckSum(String appSecret, String nonce, String curTime) {
return encode("sha1", appSecret + nonce + curTime);
}
/**
* 功能说明对参数进行MD5加密
* 修改说明
* @author hu
* @date 2021年4月6日 下午1:33:26
* @param requestBody 要加密的内容
* @return 返回MD5加密后的字符串
*/
public static String getMD5(String requestBody) {
return encode("md5", requestBody);
}
/**
* 功能说明使用指定加密算法对字符串进行加密
* 修改说明
* @author hu
* @date 2021年4月6日 下午1:33:26
* @param algorithm 加密算法
* @param value 要加密的字符串
* @return 返回加密后的字符串
*/
private static String encode(String algorithm, String value) {
if (value == null) {
return null;
}
try {
MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
messageDigest.update(value.getBytes());
return getFormattedText(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 功能说明把字节数组格式化为16进制字符串
* 修改说明
* @author hu
* @date 2021年4月6日 下午1:33:26
* @param bytes 字节数组
* @return 返回格式化后的字符串
*/
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
public static String getRandomString(int length){
String str="abcdefghijklmnopqrstuvwxyz0123456789";
Random random=new Random();
StringBuilder sb=new StringBuilder();
for(int i=0;i<length;i++){
int number=random.nextInt(36);
sb.append(str.charAt(number));
}
return sb.toString();
}
}

@ -22,6 +22,17 @@ val GSON: Gson by lazy {
.create()
}
val MYGSON: Gson by lazy {
GsonBuilder()
.registerTypeAdapter(
object : TypeToken<Map<String?, Any?>?>() {}.type,
MapDeserializerDoubleAsIntFix()
)
.registerTypeAdapter(Int::class.java, IntJsonDeserializer())
.disableHtmlEscaping()
.create()
}
inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type
inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型

Loading…
Cancel
Save