| | |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.JsonParser; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.mm.android.deviceaddmodule.LCDeviceEngine; |
| | | import com.mm.android.deviceaddmodule.mobilecommon.utils.LogUtil; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | |
| | | |
| | | public class HttpClient { |
| | | private static final String TAG=HttpClient.class.getSimpleName(); |
| | | |
| | | private static boolean showErrorInfo = false; |
| | | |
| | | public static void SetShowErrorInfo(boolean isShow){ |
| | | showErrorInfo = isShow; |
| | | } |
| | | |
| | | /** |
| | | * post |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | public static String post(String urlStr, String paramStr, String contentType, String debugTag,int timeOut) throws IOException { |
| | | LogUtil.debugLog(TAG,urlStr+"..."+paramStr); |
| | | LogUtil.debugLog(TAG,urlStr+"..debuglogHdlkaede.."+paramStr); |
| | | HttpsURLConnection conn = null; |
| | | String resultData = ""; |
| | | OutputStream outputStream = null; |
| | |
| | | conn.setUseCaches(false); |
| | | conn.setInstanceFollowRedirects(true); |
| | | conn.setRequestProperty("Content-Type", contentType); |
| | | conn.setRequestProperty("Authorization","Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJqdGkiOiI5MWFjM2FlOWVlMDY0MDY4OWU2NmQzMjQ3MzkxZmQ3MiIsImNvbXBhbnlJZCI6IjIwMiIsInJvbGUiOiIiLCJoZWFkZXJQcmVmaXgiOiJCZWFyZXIgIiwidXNlckFjY291bnQiOiJ3eHIiLCJ0ZW5hbnRJZCI6IjIwIiwidXNlclR5cGUiOiJVU0VSX0IiLCJ0b2tlblR5cGUiOiJhY2Nlc3NfdG9rZW4iLCJ1c2VyTmFtZSI6Ind4ciIsIm9wZW5BcHBsaWNhdGlvbklkIjoiMCIsInVzZXJJZCI6IjEzOTIwMzU1NjgyMDQ0MjMxNjkiLCJleHAiOjE2NjkxMDE2NTEsIm5iZiI6MTY2OTA5NDQ1MX0.BhY5cZDds87lpCOVscCjiH-EnvFSuOFjgXvVkWvGr4elUHFwFTNumhtvfCcQY4Nbu0MNTaPbb36ydNPtXHLAZrXVPdijk_WvnhoTBvA_RUOZOrQ1G4Iep3ZjgHuHam1bsCmgATQqDJR66q3ZiLwe5o_Snce2rAK4aI2Das9uN_M"); |
| | | conn.setRequestProperty("Authorization","Bearer "+ LCDeviceEngine.newInstance().accessToken); |
| | | conn.connect(); |
| | | outputStream = conn.getOutputStream(); |
| | | outputStream.write(paramStr.getBytes()); |
| | |
| | | baos.flush(); |
| | | if (debugTag != null) |
| | | LogUtil.debugLog(debugTag, "request data " + resultData); |
| | | } else |
| | | throw new IOException(String.format("http_get failed: status=%d", responseCode)); |
| | | } else { |
| | | if(showErrorInfo) { |
| | | throw new IOException(String.format("http_get failed: status=%d : url=%d", responseCode,urlStr)); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | throw e; |
| | | } catch (Throwable e) { |
| | |
| | | */ |
| | | public static JsonObject encrypt(Map<String,Object> map ) { |
| | | final String timestamp = String.valueOf(System.currentTimeMillis()); |
| | | final String appKey ="HDL-HOME-APP-TEST"; |
| | | final String appSecret ="WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss"; |
| | | final JsonObject json = getBodyJson(map); |
| | | if (json != null) { |
| | | json.addProperty("appKey", appKey); |
| | | json.addProperty("appKey", CONST.APPID); |
| | | json.addProperty("timestamp", timestamp); |
| | | json.addProperty("sign", getSign(json, appSecret)); |
| | | json.addProperty("sign", getSign(json, CONST.SECRET)); |
| | | } |
| | | return json; |
| | | } |