admin
2020-06-16 5f13dcc8eaac7cd26c0ec41bd1b3efbb70a08180
fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java
@@ -23,14 +23,10 @@
import net.sf.json.JSONObject;
public class AitaokerApiUtil {
   public static String APP_KEY = "1077080250";
   public static String SECRET_KEY = "7c6118bd-7aa5-65b8-c6d4-058728e9446f";
   // 请求连接
   private static String SERVER_URL = "http://router.itaoke.org/api";
   
   
   private static String baseRequest(String method, Map<String, String> param) {
@@ -53,9 +49,7 @@
            baseMap.put(key, param.get(key));
         }
      }
      url+= "sign=" + getSign(baseMap);
      return HttpUtil.post(url, param);
   }
   
@@ -105,12 +99,9 @@
    * @return
    */
   public static QrcodeLoginDTO getQrcodeMaclogin(int robotId) {
      // 请求参数
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.qrcode.maclogin", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      resultJson = resultJson.optJSONObject("data");
      if (resultJson != null) {
@@ -120,30 +111,6 @@
      return null;
   }
   
   /**
    *  检查是否扫码
    * @param robotId
    * @return
    */
   public static Boolean getQrcodeStatus(int robotId) {
      // 请求参数
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.qrcode.status", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      resultJson = resultJson.optJSONObject("data");
      if (resultJson != null && !StringUtil.isNullOrEmpty(resultJson.optString("status"))) {
         int optInt = resultJson.optInt("status");
         if (optInt == 1) {
            return true;
         } else {
            return false;
         }
      }
      return null;
   }
   
   /**
    *   检查是否登陆(真正的登录接口)
@@ -157,12 +124,14 @@
      map.put("robot_id", robotId +"");
      map.put("uuid", wId);
      // 请求结果
      String result = baseRequest("itaoke.robot.check.maclogin", map);
      String result = baseRequest("itaoke.robot.async.mlogin", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      resultJson = resultJson.optJSONObject("data");
      if (resultJson != null && !StringUtil.isNullOrEmpty(resultJson.optString("wcId"))) {
         Type type = new TypeToken<QrcodeLoginDTO>() {}.getType();
         return new Gson().fromJson(resultJson.toString(), type);
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         if (resultJson != null) {
            Type type = new TypeToken<QrcodeLoginDTO>() {}.getType();
            return new Gson().fromJson(resultJson.toString(), type);
         }
      }
      return null;
   }
@@ -173,14 +142,15 @@
    * @return
    */
   public static boolean onlineCheck(int robotId) {
      // 请求参数
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.check.online", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
         return true;
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         if (resultJson != null) {
            return resultJson.optBoolean("isOnline");
         }
      }
      return false;
   }
@@ -198,30 +168,12 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.force.offline", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;
   }
   
   /**
    *  掉线重连
    * @param robotId 机器人id
    * @return
    */
   public static boolean loseReconnet(int robotId) {
      // 请求参数
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.lose.reconnet", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
         return true;
      }
      return false;
   }
   
   /**
    * 创建机器人
@@ -242,8 +194,35 @@
      
      // 请求结果
      String result = baseRequest("itaoke.robot.create.get", map);
//      String result = "{\r\n" +
//            "    \"status\":\"0000\",\r\n" +
//            "    \"msg\":\"亲,添加成功\",\r\n" +
//            "    \"data\":{\r\n" +
//            "        \"id\":11770,\r\n" +
//            "        \"uid\":1625,\r\n" +
//            "        \"wechatrobot\":\"wechatrobot\",\r\n" +
//            "        \"wx_id\":\"\",\r\n" +
//            "        \"amount_used\":0,\r\n" +
//            "        \"group_num\":20,\r\n" +
//            "        \"passwd\":\"\",\r\n" +
//            "        \"nickname\":\"\",\r\n" +
//            "        \"c_uid\":1625,\r\n" +
//            "        \"login_status\":0,\r\n" +
//            "        \"end_time\":1594785534,\r\n" +
//            "        \"remark\":null,\r\n" +
//            "        \"wc_id\":\"\",\r\n" +
//            "        \"agent_uid\":null,\r\n" +
//            "        \"is_enabled\":0,\r\n" +
//            "        \"robot_type\":4,\r\n" +
//            "        \"ip\":\"http://49.234.36.129:10002/\",\r\n" +
//            "        \"is_new\":1\r\n" +
//            "    }\r\n" +
//            "}\r\n" +
//            "";
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         Type type = new TypeToken<RobotInfoDTO>() {}.getType();
         return new Gson().fromJson(resultJson.toString(), type);
@@ -251,29 +230,6 @@
      return null;
   }
   
   /**
    * 机器人更换微信号
    * @param robotId 机器人id
    * @param wxid 微信号
    * @return
    */
   public static RobotInfoDTO robotChangeWeiXin(int robotId, String wxid) {
      // 请求参数
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      map.put("wechatrobot", wxid);
      // 请求结果
      String result = baseRequest("itaoke.robot.change.get", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
         resultJson = resultJson.optJSONObject("data");
         Type type = new TypeToken<RobotInfoDTO>() {}.getType();
         return new Gson().fromJson(resultJson.toString(), type);
      }
      return null;
   }
   
   
   /**
@@ -289,8 +245,34 @@
      map.put("month", month +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.change.get", map);
//      String result = "{\r\n" +
//            "    \"status\":\"0000\",\r\n" +
//            "    \"msg\":\"\\u4eb2,\\u6dfb\\u52a0\\u6210\\u529f\",\r\n" +
//            "    \"data\":{\r\n" +
//            "        \"id\":11770,\r\n" +
//            "        \"uid\":1625,\r\n" +
//            "        \"wechatrobot\":\"fxdaka\",\r\n" +
//            "        \"wx_id\":\"wxid_vm6eb5i0in0622\",\r\n" +
//            "        \"amount_used\":0,\r\n" +
//            "        \"group_num\":20,\r\n" +
//            "        \"passwd\":\"\",\r\n" +
//            "        \"nickname\":\"\\u5206\\u4eab\\u5927\\u5496??\",\r\n" +
//            "        \"c_uid\":1625,\r\n" +
//            "        \"login_status\":1,\r\n" +
//            "        \"end_time\":1597377534,\r\n" +
//            "        \"remark\":null,\r\n" +
//            "        \"wc_id\":\"246124e9-9a8c-4da6-a77e-7f7f88049731\",\r\n" +
//            "        \"agent_uid\":null,\r\n" +
//            "        \"is_enabled\":0,\r\n" +
//            "        \"robot_type\":4,\r\n" +
//            "        \"ip\":\"http:\\/\\/49.234.36.129:10002\\/\",\r\n" +
//            "        \"is_new\":1\r\n" +
//            "    }\r\n" +
//            "}";
//
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         Type type = new TypeToken<RobotInfoDTO>() {}.getType();
         return new Gson().fromJson(resultJson.toString(), type);
@@ -311,7 +293,7 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.delete.get", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;
@@ -319,7 +301,7 @@
   
   
   /**
    * 获取好友-群列表
    * 获取群列表
    * @param robotId
    * @return
    */
@@ -328,25 +310,15 @@
      Map<String, String> map = new HashMap<>();
      map.put("robot_id", robotId +"");
      // 请求结果
      String result = baseRequest("itaoke.robot.get.contract", map);
      String result = baseRequest("itaoke.robot.room.list", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("0000".equals(resultJson.optString("code"))) {
         resultJson = resultJson.optJSONObject("data");
         // 订阅号
         //JSONArray publicArray = resultJson.optJSONArray("public");
         // 好友列表
         //JSONArray friendArray = resultJson.optJSONArray("friend");
         // 群列表
         JSONArray groupArray = resultJson.optJSONArray("group");
      if ("0000".equals(resultJson.optString("status"))) {
         JSONArray groupArray = resultJson.optJSONArray("data");
         if (groupArray != null && groupArray.size() > 0) {
            List<WeiXinGroupDTO> listGroup = new ArrayList<>();
            Type type = new TypeToken<RobotInfoDTO>() {}.getType();
            Gson gson = new Gson();
            for (int i = 0 ;i < groupArray.size(); i ++) {
               listGroup.add(gson.fromJson(groupArray.get(i).toString(), type));
            }
            Type type = new TypeToken<ArrayList<WeiXinGroupDTO>>() {
            }.getType();
            List<WeiXinGroupDTO> goodsList = new Gson().fromJson(groupArray.toString(), type);
            return goodsList;
         }
      }
      return null;
@@ -369,9 +341,14 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.circle", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("1000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         return resultJson.optString("id");
         if (resultJson != null) {
            resultJson = resultJson.optJSONObject("object");
            if (resultJson != null) {
               return resultJson.optString("id");
            }
         }
      }
      return null;
   }
@@ -393,9 +370,14 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.videocircle", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("1000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         resultJson = resultJson.optJSONObject("data");
         return resultJson.optString("id");
         if (resultJson != null) {
            resultJson = resultJson.optJSONObject("object");
            if (resultJson != null) {
               return resultJson.optString("id");
            }
         }
      }
      return null;
   }
@@ -415,10 +397,11 @@
      map.put("wx_id", wxId);
      map.put("msg_id", msgId);
      map.put("content", content);
      map.put("comment_id", "0");
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.circlecomment", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if ("1000".equals(resultJson.optString("code"))) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;
@@ -442,7 +425,7 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.text", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if (resultJson.optInt("code") == 1000) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;
@@ -466,7 +449,7 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.base64", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if (resultJson.optInt("code") == 1000) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;
@@ -495,7 +478,7 @@
      // 请求结果
      String result = baseRequest("itaoke.robot.macsend.card", map);
      JSONObject resultJson = JSONObject.fromObject(result);
      if (resultJson.optInt("code") == 1000) {
      if ("0000".equals(resultJson.optString("status"))) {
         return true;
      }
      return false;