sms.OpenUrl = http://smsapi.c123.cn/OpenPlatform/OpenApi sms.DataUrl = http://smsapi.c123.cn/DataPlatform/DataApi sms.account= 111 sms.authkey = 222 sms.cgid = 52 sms.csid = 0
2.发送相关代码
import com.shcm.bean.SendResultBean; import com.shcm.bean.SendStateBean; import com.shcm.send.DataApi; import com.shcm.send.OpenApi; import java.util.List; public class SmsSender { //发送短信接口地址 private static String sOpenUrl = SmsConfig.getString("sms.OpenUrl"); //获取信息接口地址 private static String sDataUrl = SmsConfig.getString("sms.DataUrl"); // 接口帐号 private static final String account = SmsConfig.getString("sms.account"); // 接口密钥 private static final String authkey = SmsConfig.getString("sms.authkey"); // 通道组编号: 52, 184, 185 private static final int cgid = SmsConfig.getInt("sms.cgid"); // 默认使用的签名编号(未指定签名编号时传此值到服务器) private static final int csid = SmsConfig.getInt("sms.csid"); private static final String WRITER = "xxxx"; //签名 static { // System.out.println(sOpenUrl + "," + account + "," + authkey + "," + cgid + "," + csid); // 发送参数 OpenApi.initialzeAccount(sOpenUrl, account, authkey, cgid, csid); // 状态及回复参数 DataApi.initialzeAccount(sDataUrl, account, authkey); } public static List<SendResultBean> sendOnce(String mobile, String content) throws Exception { // 发送短信 return OpenApi.sendOnce(mobile, content, 0, 0, null); //return OpenApi.sendOnce(new String[]{"18297974783","15102110086"}, "测试内容", 0, 0, null); //return OpenApi.sendBatch("18297974783,15102110086", "测试内容{|}测试内容", 0, 0, null); //return OpenApi.sendBatch(new String[]{"18297974783","15102110086"}, new String[]{"测试内容","测试内容"}, 0, 0, null); //return OpenApi.sendParam("18297974783,15102110086", "测试内容{p1}", new String[]{"a{|}b"}, 0, 0, null); //return OpenApi.sendParam(new String[]{"18297974783","15102110086"}, "测试内容{p1}", new String[]{"a{|}b"}, 0, 0, null); } public static List<SendResultBean> sendBatch(String[] mobiles, String content) throws Exception { // 发送短信 return OpenApi.sendOnce(mobiles, content, 0, 0, null); } public static List<SendStateBean> getSendState() { return DataApi.getSendState(); } public static void main(String[] args) throws Exception { sendOnce("13655203020", "发送内容"); } } import java.io.File; import java.io.FileInputStream; import java.util.Properties; /** * @author xxx * @desc 读取配置文件信息 * */ public class SmsConfig { static final Properties prop; static String workdir = System.getProperty("user.dir"); static { String PROPERTIES_FILE_SYSTEM_VAR = "application.properties"; String propertiesFile = System.getProperty(PROPERTIES_FILE_SYSTEM_VAR); if (propertiesFile == null) { propertiesFile = "/properties/application.properties"; } System.out.println("work dir : " + workdir); prop = loadFile(propertiesFile); } public static Properties loadFile(String propertiesFile) { Properties proper = new Properties(); try { File f = new File(workdir + propertiesFile); if (f.exists() && f.isFile()) { // 优先读取工作目录下的配置文件 proper.load(new FileInputStream(f)); } else { proper.load(SmsConfig.class.getResourceAsStream(propertiesFile)); } } catch (Exception e) { e.printStackTrace(); } return proper; } public static String getString(String key, String defaultValue) { return prop.getProperty(key, defaultValue); } public static String getString(String key) { return prop.getProperty(key); } public static int getInt(String key) { return getInt(key, 100); } public static int getInt(String key, int defaultValue) { try { return Integer.parseInt(prop.getProperty(key, String.valueOf(defaultValue))); } catch (Exception e) { return defaultValue; } } }
3.引入相应jar包
FYOpenApi.jar