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. Send the relevant code
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 { //Send SMS interface address private static String sOpenUrl = SmsConfig.getString("sms.OpenUrl"); //Get the information interface address private static String sDataUrl = SmsConfig.getString("sms.DataUrl"); // interface account private static final String account = SmsConfig.getString("sms.account"); // interface key private static final String authkey = SmsConfig.getString("sms.authkey"); // channel group number: 52, 184, 185 private static final int cgid = SmsConfig.getInt("sms.cgid"); // Signature number used by default (pass this value to the server when the signature number is not specified) private static final int csid = SmsConfig.getInt("sms.csid"); private static final String WRITER = "xxxx"; //签名 static { // System.out.println(sOpenUrl + "," + account + "," + authkey + "," + cgid + "," + csid); // send parameters OpenApi.initialzeAccount(sOpenUrl, account, authkey, cgid, csid); // status and reply parameters DataApi.initialzeAccount(sDataUrl, account, authkey); } public static List<SendResultBean> sendOnce(String mobile, String content) throws Exception { // send messages return OpenApi.sendOnce(mobile, content, 0, 0, null); //return OpenApi.sendOnce(new String[]{"18297974783","15102110086"}, "Test content", 0, 0, null); //return OpenApi.sendBatch("18297974783,15102110086", "Test content{|}Test content", 0, 0, null); //return OpenApi.sendBatch(new String[]{"18297974783","15102110086"}, new String[]{"Test content","Test content"}, 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 { // send messages 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", "Send Content"); } } import java.io.File; import java.io.FileInputStream; import java.util.Properties; /** * @author xxx * @desc read configuration file information * */ 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()) { // Read the configuration file in the working directory first 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. Introduce the corresponding jar package
FYOpenApi.jar