天天看點

java調用php的api

public static void main(String[] args) {

String client_id = "100001";

String sign = "D8C37B7EDD896C3DDFDC156E5ABE95A8";

String endpoint = "http://dev.vtaoshop.net:80/index.php/Api/wsdl/ws/1";

// String endpoint = "http://testweb.dev.php/testWebService/testWebService.php";//該段就是上面剛将的位址

Service service = new Service();

Call call;

try {

call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName("get_system_time");

// String param = new String("安迪".getBytes(),"ISO-8859-1");//如果沒有加這段,中文參數将會亂碼

Map map = new HashMap<String, String>();

map.put("client_id", client_id);

map.put("sign", sign);

String s = (String) call.invoke(new Object[] { map });

s = new String(s.getBytes("ISO-8859-1"));// 如果沒有轉換編碼,中文也會亂碼

System.out.println(s);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}