| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import java.net.URLEncoder;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.methods.GetMethod;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | public class OpenfireUtil {
|
| | | public final static String HOST = "http://193.112.35.168:9090";
|
| | |
|
| | | public final static String KEY = "linestoken2016bigbig";
|
| | |
|
| | | public final static int PRESENSE_UNKOWN = -1;
|
| | | public final static int PRESENSE_UNREGISTER = 0;
|
| | | public final static int PRESENSE_ONLINE = 1;
|
| | | public final static int PRESENSE_OFFLINE = 2;
|
| | |
|
| | | public static String pushMessage(String to, String msg) {
|
| | | try {
|
| | | String url = String.format(HOST + "/plugins/systemManager?type=pushMessage&to=%s&body=%s&sign=%s", to,
|
| | | URLEncoder.encode(StringUtil.getBase64String(msg), "UTF-8"), StringUtil.Md5(to + KEY));
|
| | | String result = get(url);
|
| | | System.out.println(result);
|
| | | return result;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | |
|
| | | public static int getPresenseState(String node) {
|
| | | int state = -1;
|
| | | String url = String.format(HOST + "/plugins/systemManager?type=getPresence&from=%s&sign=%s", node,
|
| | | StringUtil.Md5(node + KEY));
|
| | | String result = get(url);
|
| | | try {
|
| | | JSONObject object = JSONObject.fromObject(result);
|
| | | if (object.optInt("state") == 0) {
|
| | | state = object.optJSONObject("data").optInt("state");
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | return state;
|
| | | }
|
| | |
|
| | | public static boolean addWXFriendByPhone(String from, String phone, String welcometext) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "add_friend_by_search_mobile_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("mobile", phone);
|
| | | data.put("validation_message", welcometext);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | package com.yeshi.fanli.util; |
| | | |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.methods.GetMethod; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | public class OpenfireUtil { |
| | | public final static String HOST = "http://193.112.35.168:9090"; |
| | | |
| | | public final static String KEY = "linestoken2016bigbig"; |
| | | |
| | | public final static int PRESENSE_UNKOWN = -1; |
| | | public final static int PRESENSE_UNREGISTER = 0; |
| | | public final static int PRESENSE_ONLINE = 1; |
| | | public final static int PRESENSE_OFFLINE = 2; |
| | | |
| | | public static String pushMessage(String to, String msg) { |
| | | try { |
| | | String url = String.format(HOST + "/plugins/systemManager?type=pushMessage&to=%s&body=%s&sign=%s", to, |
| | | URLEncoder.encode(StringUtil.getBase64String(msg), "UTF-8"), StringUtil.Md5(to + KEY)); |
| | | String result = get(url); |
| | | System.out.println(result); |
| | | return result; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | public static int getPresenseState(String node) { |
| | | int state = -1; |
| | | String url = String.format(HOST + "/plugins/systemManager?type=getPresence&from=%s&sign=%s", node, |
| | | StringUtil.Md5(node + KEY)); |
| | | String result = get(url); |
| | | try { |
| | | JSONObject object = JSONObject.fromObject(result); |
| | | if (object.optInt("state") == 0) { |
| | | state = object.optJSONObject("data").optInt("state"); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | return state; |
| | | } |
| | | |
| | | public static boolean addWXFriendByPhone(String from, String phone, String welcometext) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "add_friend_by_search_mobile_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("mobile", phone); |
| | | data.put("validation_message", welcometext); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | // ������? |
| | | public static boolean addWXGroup(String from, String ownerName, String adName, int numberCount, String groupName) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "create_group_chat_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("group_chat_ad_member", adName);
|
| | | data.put("group_chat_room_owner", ownerName);
|
| | | data.put("group_chat_member_count", numberCount);
|
| | | data.put("group_chat_room_name", groupName);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | // ת��С��Ƶ
|
| | | public static boolean forwardSightJob(String from, String fromRoom, String toRoom) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "forward_sight_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("room_name_for_forward_sight_from", fromRoom);
|
| | | data.put("room_name_for_forward_sight_to", toRoom);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | // ��ȡȺ��ά��
|
| | | public static boolean getRoomQrCode(String from, String to) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "get_room_qr_code_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("room_name_for_forward_sight_from", from);
|
| | | data.put("room_name_for_forward_sight_to", to);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | // ������Ȧ
|
| | | public static boolean sendWXCircle(String from, String text) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "create_moment_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("moment_text", text);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | // ������Ȧ
|
| | | public static boolean sendWXCircle(String from, String text, List<String> imgUrlList) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "create_moment_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("moment_text", text);
|
| | | JSONArray array = new JSONArray();
|
| | | for (String url : imgUrlList)
|
| | | array.add(url);
|
| | | data.put("moment_photos", array);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * �ĸ�����Ϣ
|
| | | * |
| | | * @param from
|
| | | * @param portrait
|
| | | * ͷ��
|
| | | * @param name
|
| | | * �dz�
|
| | | * @param sex
|
| | | * �Ա�
|
| | | * @param sign
|
| | | * ǩ��
|
| | | * @return
|
| | | */
|
| | | public static boolean uploadPerinfo(String from, String portrait, String name, String sex, String sign) {
|
| | | JSONObject root = new JSONObject();
|
| | | root.put("job", "modify_account_info_job");
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("account_avatar", portrait);
|
| | | data.put("account_name", name);
|
| | | data.put("account_gender", sex);
|
| | | data.put("account_sign", sign);
|
| | | root.put("data", data);
|
| | | String result = pushMessage(from, root.toString());
|
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ�
|
| | | return true;
|
| | | } else
|
| | | return false;
|
| | | }
|
| | |
|
| | | private static String get(String url) {
|
| | | HttpClient client = new HttpClient();
|
| | | GetMethod gm = new GetMethod(url);
|
| | | try {
|
| | | client.executeMethod(gm);
|
| | | return gm.getResponseBodyAsString();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return "";
|
| | | }
|
| | | }
|
| | | public static boolean addWXGroup(String from, String ownerName, String adName, int numberCount, String groupName) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "create_group_chat_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("group_chat_ad_member", adName); |
| | | data.put("group_chat_room_owner", ownerName); |
| | | data.put("group_chat_member_count", numberCount); |
| | | data.put("group_chat_room_name", groupName); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | // ת��С��Ƶ |
| | | public static boolean forwardSightJob(String from, String fromRoom, String toRoom) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "forward_sight_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("room_name_for_forward_sight_from", fromRoom); |
| | | data.put("room_name_for_forward_sight_to", toRoom); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | // ��ȡȺ��ά�� |
| | | public static boolean getRoomQrCode(String from, String to) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "get_room_qr_code_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("room_name_for_forward_sight_from", from); |
| | | data.put("room_name_for_forward_sight_to", to); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | // ������Ȧ |
| | | public static boolean sendWXCircle(String from, String text) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "create_moment_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("moment_text", text); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | // ������Ȧ |
| | | public static boolean sendWXCircle(String from, String text, List<String> imgUrlList) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "create_moment_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("moment_text", text); |
| | | JSONArray array = new JSONArray(); |
| | | for (String url : imgUrlList) |
| | | array.add(url); |
| | | data.put("moment_photos", array); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * �ĸ�����Ϣ |
| | | * |
| | | * @param from |
| | | * @param portrait |
| | | * ͷ�� |
| | | * @param name |
| | | * �dz� |
| | | * @param sex |
| | | * �Ա� |
| | | * @param sign |
| | | * ǩ�� |
| | | * @return |
| | | */ |
| | | public static boolean uploadPerinfo(String from, String portrait, String name, String sex, String sign) { |
| | | JSONObject root = new JSONObject(); |
| | | root.put("job", "modify_account_info_job"); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("account_avatar", portrait); |
| | | data.put("account_name", name); |
| | | data.put("account_gender", sex); |
| | | data.put("account_sign", sign); |
| | | root.put("data", data); |
| | | String result = pushMessage(from, root.toString()); |
| | | if (JSONObject.fromObject(result).optInt("state") == 0) {// �ɹ� |
| | | return true; |
| | | } else |
| | | return false; |
| | | } |
| | | |
| | | private static String get(String url) { |
| | | HttpClient client = new HttpClient(); |
| | | GetMethod gm = new GetMethod(url); |
| | | try { |
| | | client.executeMethod(gm); |
| | | return gm.getResponseBodyAsString(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return ""; |
| | | } |
| | | } |