| | |
| | | package com.mm.android.deviceaddmodule.openapi;
|
| | |
|
| | | import android.text.TextUtils;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.JsonElement;
|
| | | import com.google.gson.JsonObject;
|
| | | import com.google.gson.JsonParser;
|
| | | import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
| | |
| | | import java.io.IOException;
|
| | | import java.net.SocketException;
|
| | | import java.net.SocketTimeoutException;
|
| | | import java.net.URLDecoder;
|
| | | import java.net.UnknownHostException;
|
| | | import java.net.UnknownServiceException;
|
| | | import java.util.HashMap;
|
| | |
| | | Map<String, Object> map = paramsInit(paramsMap);
|
| | | // 返回json
|
| | | JsonObject jsonObj = doPost(CONST.HOST + "/openapi/" + method, map,timeOut);
|
| | | // JsonObject jsonObj = doPost(CONST.HOST + "/home-wisdom/imou/openapi/" + method, map,timeOut);
|
| | | LogUtil.debugLog(TAG, "url::"+method+"\n"+"response result:" + jsonObj.toString());
|
| | | if (jsonObj == null) {
|
| | | throw new BusinessException("openApi response is null");
|
| | |
| | |
|
| | | private static JsonObject doPost(String url, Map<String, Object> map, int timeOut) throws BusinessException {
|
| | | Gson gson = new Gson();
|
| | | // map.put("homeId","15626203746");
|
| | | String json = gson.toJson(map);
|
| | | JsonObject jsonObject = new JsonObject();
|
| | |
|
| | | // JsonElement parseString = JsonParser.parseString(json);
|
| | | // jsonObject = parseString.getAsJsonObject();
|
| | | // jsonObject = HttpClient.encrypt(map);
|
| | | // json = gson.toJson(jsonObject);
|
| | |
|
| | | try {
|
| | | LogUtil.debugLog(TAG, "reqest: " + url + " data:" + json.toString());
|
| | | String openApi = HttpClient.post(url, json, "application/json", "OpenApi",timeOut);
|
| | |
| | | map.put("id", id);
|
| | | return map;
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 基本类型加密
|
| | | * <p>
|
| | | * 判断当前值是否需要参与签名,保持跟云端一致
|
| | | * 空字符串不参与
|
| | | * 数组,集合不参与
|
| | | *
|
| | | * @return ture 需要加密
|
| | | */
|
| | | private static boolean valueNeedSign(String valueStr) {
|
| | | try {
|
| | | if (TextUtils.isEmpty(valueStr)) return false;
|
| | | final char[] strChar = URLDecoder.decode(valueStr, "utf-8")
|
| | | .substring(0, 1).toCharArray();
|
| | | final char firstChar = strChar[0];
|
| | | return firstChar != '{' && firstChar != '[';
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|