From ec60e757d358636dcac1589c44a66f3e276fe58c Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 29 六月 2020 14:41:42 +0800 Subject: [PATCH] 拉新 --- fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java | 262 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 169 insertions(+), 93 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java index 1440d75..ca4f9b8 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/aitaoker/AitaokerApiUtil.java @@ -17,21 +17,16 @@ import com.yeshi.fanli.dto.aitaoker.QrcodeLoginDTO; import com.yeshi.fanli.dto.aitaoker.RobotInfoDTO; import com.yeshi.fanli.dto.aitaoker.WeiXinGroupDTO; -import com.yeshi.fanli.dto.suning.SuningGoodsInfo; import com.yeshi.fanli.util.StringUtil; import net.sf.json.JSONArray; 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) { @@ -54,9 +49,7 @@ baseMap.put(key, param.get(key)); } } - url+= "sign=" + getSign(baseMap); - return HttpUtil.post(url, param); } @@ -106,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) { @@ -121,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; - } - /** * 妫�鏌ユ槸鍚︾櫥闄嗭紙鐪熸鐨勭櫥褰曟帴鍙o級 @@ -167,7 +133,6 @@ return new Gson().fromJson(resultJson.toString(), type); } } - return null; } @@ -177,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("status"))) { - return true; + resultJson = resultJson.optJSONObject("data"); + if (resultJson != null) { + return resultJson.optBoolean("isOnline"); + } } return false; } @@ -210,24 +176,6 @@ /** - * 鎺夌嚎閲嶈繛 - * @param robotId 鏈哄櫒浜篿d - * @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; - } - - /** * 鍒涘缓鏈哄櫒浜� * @param month 鏈堟暟 * @param robotType 鏈哄櫒浜虹被鍨� 1 鍙戝崟鏈哄櫒浜� 2杞彂鏈哄櫒浜� 3 杩斿埄鏈哄櫒浜� 4鍏ㄨ兘鏈哄櫒浜� 5灏忓瀷鏈哄櫒浜� 6鍙戝湀鏈哄櫒浜� @@ -246,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); @@ -255,29 +230,6 @@ return null; } - - - /** - * 鏈哄櫒浜烘洿鎹㈠井淇″彿 - * @param robotId 鏈哄櫒浜篿d - * @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; - } /** @@ -293,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); @@ -315,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; @@ -327,7 +305,7 @@ * @param robotId * @return */ - public static List<WeiXinGroupDTO> getContract(int robotId) { + public static List<String> getContract(int robotId) { // 璇锋眰鍙傛暟 Map<String, String> map = new HashMap<>(); map.put("robot_id", robotId +""); @@ -337,12 +315,81 @@ 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<ArrayList<String>>() { + }.getType(); + List<String> list = new Gson().fromJson(groupArray.toString(), type); + return list; + } + } + return null; + } + + /** + * 鑾峰彇缇ゅ垪琛� + * @param robotId + * @param roomId + * @return + */ + public static WeiXinGroupDTO getGroupDetail(int robotId, String roomId) { + if (StringUtil.isNullOrEmpty(roomId)) { + return null; + } + + // 璇锋眰鍙傛暟 + Map<String, String> map = new HashMap<>(); + map.put("robot_id", robotId +""); + map.put("room_id", roomId +""); // 缇ょ殑id ,澶氫釜鐢ㄩ�楀彿闅斿紑 + // 璇锋眰缁撴灉 + String result = baseRequest("itaoke.robot.room.detail", map); + JSONObject resultJson = JSONObject.fromObject(result); + if ("0000".equals(resultJson.optString("status"))) { + JSONArray groupArray = resultJson.optJSONArray("data"); + if (groupArray != null && groupArray.size() > 0) { Type type = new TypeToken<ArrayList<WeiXinGroupDTO>>() { }.getType(); List<WeiXinGroupDTO> goodsList = new Gson().fromJson(groupArray.toString(), type); - + if (goodsList == null || goodsList.size() == 0) { + return null; + } else { + return goodsList.get(0); + } + } + } + return null; + } + + + /** + * 鑾峰彇缇ゅ垪琛� + * @param robotId + * @param roomId + * @return + */ + public static List<WeiXinGroupDTO> getGroupDetail(int robotId, List<String> listRoomId) { + if (listRoomId == null || listRoomId.size() ==0) { + return null; + } + + String roomIds = ""; + for (String roomID: listRoomId) { + roomIds += roomID + ","; + } + if(roomIds.endsWith(",")) + roomIds = roomIds.substring(0, roomIds.length()-1); + + // 璇锋眰鍙傛暟 + Map<String, String> map = new HashMap<>(); + map.put("robot_id", robotId +""); + map.put("room_id", roomIds); // 缇ょ殑id ,澶氫釜鐢ㄩ�楀彿闅斿紑 + // 璇锋眰缁撴灉 + String result = baseRequest("itaoke.robot.room.detail", map); + JSONObject resultJson = JSONObject.fromObject(result); + if ("0000".equals(resultJson.optString("status"))) { + JSONArray groupArray = resultJson.optJSONArray("data"); + if (groupArray != null && groupArray.size() > 0) { + Type type = new TypeToken<ArrayList<WeiXinGroupDTO>>() { + }.getType(); + List<WeiXinGroupDTO> goodsList = new Gson().fromJson(groupArray.toString(), type); return goodsList; } } @@ -364,12 +411,36 @@ map.put("pic_url", picUrl); map.put("content", content); // 璇锋眰缁撴灉 - String result = baseRequest("itaoke.robot.macsend.circle", map); + String result = baseRequest("itaoke.robot.circle.send", map); JSONObject resultJson = JSONObject.fromObject(result); if ("0000".equals(resultJson.optString("status"))) { resultJson = resultJson.optJSONObject("data"); - resultJson = resultJson.optJSONObject("object"); - return resultJson.optString("id"); + if (resultJson != null) { + resultJson = resultJson.optJSONObject("object"); + if (resultJson != null) { + return resultJson.optString("id"); + } + } + } + return null; + } + + /** + * 鍙戞湅鍙嬪湀 + * @param robotId + * @param content + * @param picUrl 鍥剧墖url锛屽涓鐢�;鍒嗛殧 + * @return + */ + public static String macsendUpload(int robotId, String picUrl) { + Map<String, String> map = new HashMap<>(); + map.put("robot_id", robotId +""); + map.put("pic_url", picUrl); + map.put("type", "2"); + String result = baseRequest("itaoke.robot.circle.upload", map); + JSONObject resultJson = JSONObject.fromObject(result); + if ("0000".equals(resultJson.optString("status"))) { + return resultJson.optString("data"); } return null; } @@ -391,9 +462,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; } @@ -465,7 +541,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; @@ -494,7 +570,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; -- Gitblit v1.8.0