import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import com.ibm.wsdl.util.StringUtils;
import com.sms.impl.GSTEngineFactory;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class TestClient {
/*1000 操作成功
1001 用户不存在或密码出错
1002 用户被停用
1003 余额不足
1004 请求频繁
1005 内容超长
1006 非法手机号码
1007 关键字过滤
1008 接收号码数量过多
1009 帐户过期
1010 参数格式错误
1011 其它错误
1012 数据库繁忙
1013 非法发送时间
*/
//ws访问地址
public final static String
url ="XXX";
/**
* 得到用户信息,并且可以测试短信功能是否成功
* @param username * @param password 用户登录密码
* @return机构id:
* @throws Exception
*/
public static String getUserInfo(String username,String password) throws Exception{
String result = "";
try {
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(url,"getUserInfo"));
result = (String)call.invoke(new Object[]{username,password});
System.out.println(result);
} catch (Exception ex) {
ex.getMessage();
}
return result;
}
public static void main(String[] args) throws Exception {
String[] strArray = new String[]{"1","6","9","8"};
StringBuffer strbuf = new StringBuffer();
for(int i =0;i
strbuf.append(",").append(strArray[i]);
}
String str="";
if(strbuf.length()>0)
{
str = strbuf.deleteCharAt(0).toString();
}
System.out.println("str--"+str);
/*String message=parseXml(getUserInfo("XX","XX"),"code");
System.out.println("message:"+message);
Map m=new HashMap();
m.put("1000", "操作成功");
m.put("1001", "用户不存在或密码出错");
m.put("1002", "用户被停用");
m.put("1003", "余额不足");
m.put("1004", "请求繁忙");
m.put("1005", "内容超长");
m.put("1006", "非法手机号码");
m.put("1007", "关键字过滤");
m.put("1008", "接收号码数量过多");
m.put("1009", "帐户过期");
m.put("1010", "参数格式错误");
m.put("1011", "其它错误");
m.put("1012", "数据库繁忙");
m.put("1013", "非法发送时间");
*/
//String message2=parseXml(clusterSend("XX","XX","XX","XX","短信测试0"),"code");
//System.out.println("message:"+message2);
}
/**
* 发送短信
* @param username 用户名,由机构ID+:+用户登录名组成.如10001:admin
* @param password 用户登录密码
* @param from 发送手机号码
* @param to 接收手机号码,支持多个.号码间用,号分开.最大一次不能超过100个号码
* @param text 短信内容
* @param presendTime 短信发送时间,可为空.默认为系统当前时间
* @param isVoice 是否语音短信是否语音(0表示普通短信,1表示语音短信)|重听次数|重拨次数|是否回复(0表示不回复,1表示回复)如:isVoice=”1|1|2|0” 即:语音短信,重听次数1,重拨次数2,不回复
* @return xml字符串
* @throws Exception
*/
public static String clusterSend(String username,String password,String from,String to ,String text)throws Exception{
String result = "";
try {
if(null==to||"".equals(to.trim()))
{
return "1010
}
//return restult="";
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(url,"clusterSend"));
result = (String)call.invoke(new Object[]{username,password,from,to,text,"","0"});
System.out.println("result"+result);
} catch (Exception ex) {
ex.getMessage();
}
return result;
}
private static String parseXml(String xmlstr,String name)
{
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
InputStream inputStream = new ByteArrayInputStream(xmlstr.getBytes());
Document doc = builder.parse(inputStream);
Element root = doc.getDocumentElement();
return ((Element)root.getElementsByTagName(name).item(0)).getTextContent();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
}