| | |
| | | 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) {
|
| | |
| | | baseMap.put(key, param.get(key));
|
| | | }
|
| | | }
|
| | | |
| | | url+= "sign=" + getSign(baseMap);
|
| | | |
| | | return HttpUtil.post(url, param);
|
| | | }
|
| | |
|
| | |
| | | * @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) {
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 检查是否登陆(真正的登录接口)
|
| | |
| | | return new Gson().fromJson(resultJson.toString(), type);
|
| | | }
|
| | | }
|
| | | |
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | * @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;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建机器人
|
| | |
| | | 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<WeiXinGroupDTO>>() {
|
| | | }.getType();
|
| | | List<WeiXinGroupDTO> goodsList = new Gson().fromJson(groupArray.toString(), type);
|
| | | |
| | | return goodsList;
|
| | | }
|
| | | }
|
| | |
| | | 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;
|
| | | }
|