【初学求助】这段代码的sig参数算法是怎样的?

红单软件 2015-06-03 12:49:01
package com.anjuke.android.app.common.util;

import com.anjuke.android.app.AnjukeApp;
import com.anjuke.mobile.pushclient.http.Config;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

public class AnjukeApiUtil
{
private static AnjukeApiUtil _instance;

public static String getAPIKey()
{
return "eb8cd4ef60fde7580260cf9cf4250a24";
}

public static String getAPP()
{
return "anjuke";
}

public static String getApiHostNew()
{
return Config.getApiHost() + "/mobile/1.3/";
}

public static String getExtraParams(Boolean paramBoolean)
{
return getExtraParams(paramBoolean, null);
}

public static String getExtraParams(Boolean paramBoolean, HashMap<String, String> paramHashMap)
{
if (paramHashMap == null)
{
if (paramBoolean.booleanValue());
for (String str3 = "?"; ; str3 = "&")
return str3 + "i=" + AnjukeApp.getInstance().device + "&m=" + AnjukeApp.getInstance().mobile + "&o=" + AnjukeApp.getInstance().system + "&cv=" + AnjukeApp.getInstance().ver + "&app=" + AnjukeApp.getInstance().app + "&pm=" + AnjukeApp.getInstance().promotion;
}
if (paramBoolean.booleanValue());
ArrayList localArrayList;
for (String str1 = "?"; ; str1 = "&")
{
Iterator localIterator = paramHashMap.keySet().iterator();
localArrayList = new ArrayList();
localArrayList.add("i");
localArrayList.add("m");
localArrayList.add("o");
localArrayList.add("cv");
localArrayList.add("app");
localArrayList.add("pm");
while (localIterator.hasNext())
{
String str2 = (String)localIterator.next();
((String)paramHashMap.get(str2));
if (localArrayList.contains(str2))
localArrayList.remove(str2);
}
}
int i = 0;
if (i < localArrayList.size())
{
if (i != 0)
str1 = str1 + "&";
if (((String)localArrayList.get(i)).equals("i"))
str1 = str1 + "i=" + AnjukeApp.getInstance().device;
while (true)
{
i++;
break;
if (((String)localArrayList.get(i)).equals("m"))
str1 = str1 + "m=" + AnjukeApp.getInstance().mobile;
else if (((String)localArrayList.get(i)).equals("o"))
str1 = str1 + "o=" + AnjukeApp.getInstance().system;
else if (((String)localArrayList.get(i)).equals("cv"))
str1 = str1 + "cv=" + AnjukeApp.getInstance().ver;
else if (((String)localArrayList.get(i)).equals("app"))
str1 = str1 + "app=" + AnjukeApp.getInstance().app;
else if (((String)localArrayList.get(i)).equals("pm"))
str1 = str1 + "pm=" + AnjukeApp.getInstance().promotion;
}
}
return str1;
}

public static String getOS()
{
return "android";
}

public static String getPirvateKeyCode(HashMap<String, String> paramHashMap)
{
String str1 = obtainParameterList(paramHashMap);
String str2 = str1 + getPivateKey();
new MD5();
return MD5.Md5(str2);
}

public static String getPivateKey()
{
return "5d41a9e970273bca";
}

public static void initialize()
{
if (_instance == null)
_instance = new AnjukeApiUtil();
}

public static String obtainParameterList(HashMap<String, String> paramHashMap)
{
ArrayList localArrayList = new ArrayList();
Iterator localIterator1 = paramHashMap.entrySet().iterator();
while (localIterator1.hasNext())
{
Map.Entry localEntry = (Map.Entry)localIterator1.next();
Object localObject1 = localEntry.getKey();
Object localObject2 = localEntry.getValue();
localArrayList.add(localObject1 + "=" + localObject2);
}
localArrayList.add("api_key=" + getAPIKey());
Collections.sort(localArrayList);
StringBuffer localStringBuffer = new StringBuffer();
Iterator localIterator2 = localArrayList.iterator();
while (localIterator2.hasNext())
{
String str = (String)localIterator2.next();
if (localStringBuffer.toString().length() == 0)
localStringBuffer.append(str);
else
localStringBuffer.append("&" + str);
}
return localStringBuffer.toString();
}

public static String obtainParameterListUseUrlEncode(HashMap<String, String> paramHashMap)
{
ArrayList localArrayList = new ArrayList();
Iterator localIterator1 = paramHashMap.entrySet().iterator();
while (localIterator1.hasNext())
{
Map.Entry localEntry = (Map.Entry)localIterator1.next();
String str2 = (String)localEntry.getKey();
String str3 = (String)localEntry.getValue();
localArrayList.add(str2 + "=" + URLEncoder.encode(str3));
}
localArrayList.add("api_key=" + getAPIKey());
Collections.sort(localArrayList);
StringBuffer localStringBuffer = new StringBuffer();
Iterator localIterator2 = localArrayList.iterator();
while (localIterator2.hasNext())
{
String str1 = (String)localIterator2.next();
if (localStringBuffer.toString().length() == 0)
localStringBuffer.append(str1);
else
localStringBuffer.append("&" + str1);
}
return localStringBuffer.toString();
}

public static HashMap<String, String> sort_Encryption_For_Post(String paramString, HashMap<String, String> paramHashMap)
{
paramHashMap.put("sig", getPirvateKeyCode(paramHashMap));
paramHashMap.put("api_key", getAPIKey());
return paramHashMap;
}
}



由于是新手,只能看懂部分代码。我分析的是:
1.分别获取i m o cv app pm 参数
2.文本数组从小到大排序,参数与参数用“&”连接
3.文本后加上密匙“5d41a9e970273bca”
4.取文本MD5.

但是我这样算出来的sig参数和抓包得到的sig参数并不一样。一下是抓包的原数据:

GET api.anjuke.com/xinfang/m/android/1.3/loupan/addLove/?loupan_id=249730&dianping_id=159398&api_key=androidkey&sig=555f0a223e8974b0075d4a3c97339b0d&macid=62317749972a9d40c02a4184b7a85e6a&app=a-ajk&_pid=3760&o=hlteuc-user+4.4.2+KOT49H+N900AUCUCMLG+release-keys&from=mobile&m=Android-SAMSUNG-SM-N900A&cv=8.7.2&cid=52&i=955499446298719&v=4.4.2&qtime=20150602231908&pm=b200&uuid=d091dbca-fbc3-4e6c-b215-292015060223&_chat_id=0 HTTP/1.1
Connection: close
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; SAMSUNG-SM-N900A Build/KOT49H)
Host: api.anjuke.com
Accept-Encoding: gzip

求助一下大家,这样的算法正确不正确?原代码的算法究竟是什么?
...全文
244 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,600

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧