JAVA api command

作者在 2016-12-06 10:42:57 发布以下内容
package fuck;

import java.net.URL;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import com.alibaba.fastjson.JSONObject;
import com.hanshows.eslworking.session.python.epd.Duration;
import com.hanshows.eslworking.util.Utils;

public class TestXmlRpcClient 
{

	public static void main(String[] args) throws Exception 
	{
		//rpc(setCmd());
		//rpc(apInfo());
//		rpc(apQuery());
		rpc(bind());
	}
	public static Object[] bind() throws Exception
	{
		JSONObject b = new JSONObject();
		
		b.put("eslid","54-76-EA-99");
		b.put("salesno","1");
		b.put("apid","1)1");
		//(~!@#¥%……&*()<>? "" ' / \)
		return new Object[] {"BIND",new Object[]{b}};
	}
	public static Object[] apInfo() throws Exception 
	{
		// "AP_INFO", [{"apid":"9"}]
		JSONObject j = new JSONObject();   //新建一个类
		j.put("apid", "1");					//input apid 1
		return new Object[] { "AP_INFO", new Object[] { j } };   //返回
	}
	
	public static Object[] apQuery() 
	{
		JSONObject j1 = new JSONObject();
		j1.put("apid", "1");

		JSONObject j2 = new JSONObject();
		j2.put("apid", "2");
		return new Object[] { "AP_QUERY", new Object[] { j1, j2 } };
	}

	public static Object[] setCmd() 
	{
		JSONObject j1 = new JSONObject();
		j1.put("setid", "50-80-00-66");
		j1.put("setcmd", "CMD_LED_CONFIG");
		j1.put("setargs", "1");
		return new Object[] { "SET_CMD", new Object[] { j1 } };
	}

	private static void rpc(Object[] params) throws Exception 
	{
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setServerURL(new URL("http://127.0.0.1:9000/RPC2"));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);

		Duration duration = new Duration();
		for (int i = 0; i < 1; ++i) 
		{
			Object[] result = (Object[]) client.execute("send_cmd", params);
			for (int j = 0; j < result.length; j++) 
				{
					System.out.println(Utils.obj2json(result[j]));
				}
			System.out.println();
			System.out.println(result);
		}
		System.out.println("spent=" + duration.getDuration());
	}

}
JAVA | 阅读 1730 次
文章评论,共0条
游客请输入验证码
浏览2343224次