Commit a1ed8f19 by YKai

feat:加密代码优化

parent 585a0570
package com.yidianling.user.http;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import com.ydl.burypointlib.MD5Util;
import com.ydl.ydlcommon.base.BaseApp;
import com.ydl.ydlcommon.base.config.HttpConfig;
import com.yidianling.common.tools.RxAppTool;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by Ykai on 2021/1/11.
*
* 获取加密参数类
*/
public class EncryptionParams {
@RequiresApi(api = Build.VERSION_CODES.N)
public static Map<String,String> getParams(String path){
String timestamp = String.valueOf(System.currentTimeMillis()); //值应该为毫秒数的字符串形式
Map<String,String> map = new HashMap<>();
map.put("timestamp",timestamp);
map.put("path",path);
map.put("version", "1.0.0");
List<String> storedKeys = Arrays.stream(map.keySet()
.toArray(new String[]{}))
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
String sign = storedKeys.stream()
// .map(key -> String.join("", key, map.get(key)))
.map(key -> key+map.get(key))
.collect(Collectors.joining()).trim()
.concat("ABA88F2FF7E64A688D2213B20A9B3A3E");
Log.e("sign",sign);
sign = MD5Util.md5(sign).toUpperCase();
// sign = MD5.md5(sign).toUpperCase();
Log.e("sign",sign);
Map<String,String> headersMap = new HashMap<>();
headersMap.put("appKey","20BB42485BD448DE888DD745899C457D");
headersMap.put("sign",sign);
// headersMap.put("sign","2410C6CDC7235DC6318F5CF0FFFAA0B7");
headersMap.put("timestamp",timestamp);
// headersMap.put("timestamp","1610352010360");
return headersMap;
}
}
......@@ -31,7 +31,6 @@ import com.yidianling.user.UserConstants;
import com.yidianling.user.UserHelper;
import com.yidianling.user.api.event.RefreshRecentContactListEvent;
import com.yidianling.user.event.UpdateBindStatusEvent;
import com.yidianling.user.http.EncryptionParams;
import com.yidianling.user.http.LoginApiRequestUtil;
import com.yidianling.user.http.UserHttp;
import com.yidianling.user.http.UserHttpImpl;
......
......@@ -44,7 +44,6 @@ import com.yidianling.user.UserHelper
import com.yidianling.user.api.bean.UserResponseBean
import com.yidianling.user.bean.AliAuthBean
import com.yidianling.user.constants.UserBIConstants
import com.yidianling.user.http.EncryptionParams
import com.yidianling.user.http.request.BindPhoneJavaParam
import com.yidianling.user.http.request.PhoneLoginAutoParam
import com.yidianling.user.http.response.ChcekPhoneResponeBean
......
......@@ -20,24 +20,23 @@ import java.util.stream.Collectors;
*/
public class EncryptionParams {
@RequiresApi(api = Build.VERSION_CODES.N)
public static String getSign(String path,String timestamp){
Map<String,String> map = new HashMap<>();
map.put("timestamp",timestamp);
map.put("path",path);
map.put("version", "1.0.0");
List<String> storedKeys = Arrays.stream(map.keySet()
.toArray(new String[]{}))
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
String sign = storedKeys.stream()
.map(key -> key+map.get(key))
.collect(Collectors.joining()).trim()
.concat(HttpConfig.Companion.getENCRYPTION_APP_SECRET());
// Map<String,String> map = new HashMap<>();
// map.put("timestamp",timestamp);
// map.put("path",path);
// map.put("version", "1.0.0");
//
// List<String> storedKeys = Arrays.stream(map.keySet()
// .toArray(new String[]{}))
// .sorted(Comparator.naturalOrder())
// .collect(Collectors.toList());
// String sign = storedKeys.stream()
// .map(key -> key+map.get(key))
// .collect(Collectors.joining()).trim()
// .concat();
String sign = ("path"+path+"timestamp"+timestamp+"version1.0.0").concat(HttpConfig.Companion.getENCRYPTION_APP_SECRET());
LogUtil.e("sign",sign);
sign = MD5Util.md5(sign).toUpperCase();
LogUtil.e("sign",sign);
return sign;
}
}
......@@ -173,7 +173,6 @@ class HttpConfig {
path+it.request().url().encodedPath()
}
}
LogUtil.e("path",it.request().url().toString())
val sign = EncryptionParams.getSign(path, timestamp)
val request = it.request().newBuilder()
.addHeader("appKey", ENCRYPTION_APP_KEY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment