配置文件: messageConfig.properties
SN=SDK-BBX-010-22482
PWD=SDK-BBX-010-22482c5@e520@
SIGN=\u3010\u4E2D\u79FB\u6D41\u91CF\u52A0\u6CB9\u7AD9\u3011�
package com.cmcc.flow.common.message;
/**
* Created by kok on 15/4/30.
*/
public class MessagePOJO {
//软件序列号 格式XXX-XXX-XXX-XXXXX SDK-BBX-010-22482
//SDK-WSS-010-08434
private final static String SN =MessageConfig.get("SN");
//密码 md5(sn+password) 32位大写密文 c5@e520@ 17E8468AB863EB0C63950D05A009C158
// 6C58D25EF6BB0CD207B555EBDA1AA0E8
private final static String PWD=MessageConfig.get("PWD");
//手机号 必填(支持10000个手机号,建议<=5000)多个英文逗号隔开
private String [] mobile;
//内容 支持长短信(详细请看长短信扣费说明),URLUTF8编码
private String content;
//扩展码 例如:123(默认置空)
private String ext;
//定时时间 例如:2010-12-29 16:27:03(置空表示立即发送)
private String stime;
//唯一标识 最长18位,支持数字。
private Long rid;
//内容编码 0:ASCII串。3:短信写卡操作。4:二进制信息。空或15:含GB汉字
private int msgfmt;
public static String SIGN=MessageConfig.get("SIGN");
public void setMobile(String[] mobile) {
this.mobile = mobile;
}
public void setContent(String content) {
this.content = content;
}
public void setExt(String ext) {
this.ext = ext;
}
public void setStime(String stime) {
this.stime = stime;
}
public void setRid(Long rid) {
this.rid = rid;
}
public void setMsgfmt(int msgfmt) {
this.msgfmt = msgfmt;
}
public static String getSN() {
return SN;
}
public static String getPWD() {
return PWD;
}
public String[] getMobile() {
return mobile;
}
public String getContent() {
return content;
}
public String getExt() {
return ext;
}
public String getStime() {
return stime;
}
public Long getRid() {
return rid;
}
public int getMsgfmt() {
return msgfmt;
}
}
package com.cmcc.flow.common.message;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
/**
* Created by kok on 15/5/4.
*/
public class MessageConfig {
private static Properties prop = new Properties();
/**
* 加载配置文件
*/
static {
InputStream in = MessageConfig.class.getResourceAsStream("/messageConfig.properties");
try {
prop.load(in);
} catch (IOException e) {
}
}
/**
* 从配置文件里面读取配置信息
*
* @param key
* @return
*/
public static String get(String key) {
String value = "";
if (key != null && key.trim().length() > 0) {
value = prop.get(key).toString();
// value = URLEncoder.encode(value,"utf-8");
if (value != null && value.trim().length() > 0) {
if (key.equals("PWD")) {
return transformation(value);
}
}
}
return value;
}
/**
* 对密码进行MD5转换
*
* @param pwd
* @return
*/
public static String transformation(String pwd) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(pwd.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
return buf.toString().toUpperCase();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}