Package com.ecar.eoc.content.platform.utils;
Import java.io.IOException;
Import Java.util.HashMap;
Import Java.util.Map;
Import Org.apache.log4j.Logger;
Import Com.ecar.commons.cmf.util.PropertiesUtil;
Import Com.ecar.rtplt.component.web.HttpRequester;
Import Com.ecar.rtplt.component.web.HttpResponser;
public class Restutil
{
private static Logger Logger = Logger.getlogger (Restutil.class);
/**
*
* @Title: Getrestcontent
* @Description: TODO (Get content returned by rest)
* @param URL
* @param map
* @return
* @throws IOException
* @author Yuqidi
* @date 2015-4-27 07:30:03
* @version V1.0
*/
public static string getrestcontent (string url, map<string, string> Map) throws IOException
{
Httprequester request = new Httprequester ();
Request.setdefaultcontentencoding ("Utf-8");
Map<string, string> properties = new hashmap<string, string> ();
Properties.put ("Content-type", "application/x-www-form-urlencoded; Charset=utf-8 ");
if (logger.isinfoenabled ())
{
Logger.info (New StringBuffer ("Url="). Append (URL). Append (new Org.json.JSONObject (map));
}
Httpresponser responser = request.sendpost (URL, map, properties);
return Responser.getcontent ();
}
/**
* Base MD5 encryption algorithm
* @Title: Judgetoken
* @Description: TODO (here is a word describing the effect of this method)
* @param: @param map
* @param: @param appKey
* @param: @param nonce
* @param: @param timestamp
* @param: @param sign
* @param: @return
* @return: Boolean
* @throws
* @author Ecar
* @Date 2016-5-20 11:10:46
*/
public static Boolean Judgetoken (Map<object, object> Map, String AppKey, String nonce, Long timestamp, string sign)
{
String appsrect = propertiesutil.getvaluestring ("Ep023_secret_key", "d90c8b17fb4fbd6442fdec51c735e91c");
Return Authsighelpter.authsig (AppKey, Appsrect, timestamp, nonce, map, sign);
}
/**
* GET Request
* @Title: Getrestcontent_get
* @Description: TODO (here is a word describing the effect of this method)
* @param: @param URL
* @param: @param map
* @param: @return
* @param: @throws IOException
* @return: String
* @throws
* @author Ecar
* @Date 2016-7-11 07:32:02
*/
public static string Getrestcontent_get (string url) throws IOException
{
Httprequester request = new Httprequester ();
Request.setdefaultcontentencoding ("Utf-8");
Map<string, string> properties = new hashmap<string, string> ();
Properties.put ("Content-type", "application/x-www-form-urlencoded; Charset=utf-8 ");
if (logger.isinfoenabled ())
{
Logger.info (New StringBuffer ("Url="). Append (URL));
}
Httpresponser responser = request.sendget (URL);
return Responser.getcontent ();
}
}
Package Java-get-post Request Method