package com.xiaoxm.util;
import java.io.BufferedReader;
import com.jasson.im.api.APIClient;
/**
* ApiTestDemo
*/
public class ApiSendMobile
{
private long smId = 1;
private int smType = 0;
private String host = "mas地址";
private String dbName = "mas";
private String apiId = "用户apid";
private String name = "用户名";
private String pwd = "密码";
private APIClient handler = new APIClient();
BufferedReader in = null;
public ApiSendMobile()
{
}
public void init()
{
int connectRe = handler.init(host, name, pwd, apiId,dbName);
if(connectRe == APIClient.IMAPI_SUCC)
info("初始化成功");
else if(connectRe == APIClient.IMAPI_CONN_ERR)
info("连接失败");
else if(connectRe == APIClient.IMAPI_API_ERR)
info("apiID不存在");
if(connectRe != APIClient.IMAPI_SUCC)
{
System.exit(-1);
}
}
public void release()
{
handler.release();
Thread.currentThread().interrupt();
}
public String sendSM(String mobile,String sendContent)
{
init(); //初始化 相关参数
String msg = "";
int result = 0;
result = handler.sendSM(mobile, sendContent, smId );
if(result == APIClient.IMAPI_SUCC)
{
msg = "发送成功";
}
else if(result == APIClient.IMAPI_INIT_ERR)
msg = "未初始化";
else if(result == APIClient.IMAPI_CONN_ERR)
msg = "数据库连接失败";
else if(result == APIClient.IMAPI_DATA_ERR)
msg = "参数错误";
else if(result == APIClient.IMAPI_DATA_TOOLONG)
msg = "消息内容太长";
else if(result == APIClient.IMAPI_INS_ERR)
msg = "数据库插入错误";
else
msg = "出现其他错误";
release(); //释放资源
return msg;
}
public void error(Object obj , Throwable thr)
{
info(obj);
thr.printStackTrace();
}
public void info(Object obj)
{
System.out.println(obj);
}
public void quit()
{
release();
System.exit(0);
}
}