108 lines
4.0 KiB
Java
108 lines
4.0 KiB
Java
package com.diyidan.game.network.util;
|
|
|
|
import android.net.http.Headers;
|
|
import android.webkit.CookieManager;
|
|
import android.webkit.CookieSyncManager;
|
|
import com.android.volley.AuthFailureError;
|
|
import com.android.volley.NetworkResponse;
|
|
import com.android.volley.Response;
|
|
import com.android.volley.toolbox.StringRequest;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.security.InvalidKeyException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import javax.crypto.Mac;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
import org.apache.http.auth.AUTH;
|
|
import org.apache.http.cookie.SM;
|
|
|
|
/* JADX INFO: loaded from: C:\Users\11789\Documents\Projects\Codex_ws\myrzx_fang\analysis\base_classes.dex */
|
|
public class DydStringRequest extends StringRequest {
|
|
private static long APP_ID;
|
|
private static String AUTH_RESULT;
|
|
private static String DEV_ID;
|
|
private CookieManager cookieManager;
|
|
private Map<String, String> mParams;
|
|
private String url;
|
|
|
|
public DydStringRequest(int i, String str, Map<String, String> map, Response.Listener<String> listener, Response.ErrorListener errorListener) {
|
|
super(i, str, listener, errorListener);
|
|
this.mParams = map;
|
|
this.url = str;
|
|
CookieManager cookieManager = CookieManager.getInstance();
|
|
this.cookieManager = cookieManager;
|
|
cookieManager.setAcceptCookie(true);
|
|
}
|
|
|
|
@Override // com.android.volley.Request
|
|
public Map<String, String> getParams() throws AuthFailureError {
|
|
return this.mParams;
|
|
}
|
|
|
|
@Override // com.android.volley.toolbox.StringRequest, com.android.volley.Request
|
|
protected Response<String> parseNetworkResponse(NetworkResponse networkResponse) {
|
|
Map<String, String> map = networkResponse.headers;
|
|
boolean z = false;
|
|
for (int i = 0; i < networkResponse.allHeaders.size(); i++) {
|
|
String name = networkResponse.allHeaders.get(i).getName();
|
|
String value = networkResponse.allHeaders.get(i).getValue();
|
|
if (name.equalsIgnoreCase(Headers.SET_COOKIE)) {
|
|
this.cookieManager.setCookie(this.url, value);
|
|
z = true;
|
|
}
|
|
}
|
|
if (z) {
|
|
CookieSyncManager.getInstance().sync();
|
|
}
|
|
return super.parseNetworkResponse(networkResponse);
|
|
}
|
|
|
|
@Override // com.android.volley.Request
|
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
HashMap map = new HashMap();
|
|
String cookie = this.cookieManager.getCookie(this.url);
|
|
if (cookie != null) {
|
|
map.put(SM.COOKIE, cookie);
|
|
}
|
|
map.put("deviceId", "" + DEV_ID);
|
|
map.put("AppID", "" + APP_ID);
|
|
map.put(AUTH.WWW_AUTH_RESP, "" + AUTH_RESULT);
|
|
return map;
|
|
}
|
|
|
|
public static void setAuthInfo(String str, long j, String str2) {
|
|
DEV_ID = str;
|
|
APP_ID = j;
|
|
AUTH_RESULT = encode(str2, "" + j);
|
|
}
|
|
|
|
public static String encode(String str, String str2) {
|
|
try {
|
|
Mac mac = Mac.getInstance("HmacSHA256");
|
|
mac.init(new SecretKeySpec(str.getBytes("UTF-8"), "HmacSHA256"));
|
|
byte[] bArrDoFinal = mac.doFinal(str2.getBytes("UTF-8"));
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
for (byte b : bArrDoFinal) {
|
|
String hexString = Integer.toHexString(b & 255);
|
|
if (hexString.length() == 1) {
|
|
stringBuffer.append('0');
|
|
}
|
|
stringBuffer.append(hexString);
|
|
}
|
|
return stringBuffer.toString();
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
} catch (InvalidKeyException e2) {
|
|
e2.printStackTrace();
|
|
return null;
|
|
} catch (NoSuchAlgorithmException e3) {
|
|
e3.printStackTrace();
|
|
return null;
|
|
} catch (Exception e4) {
|
|
e4.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
} |