Commit b29be75d by java-李谡

短信发送

parent 362dad5d
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package com.ejweb.core.conf; package com.ejweb.core.conf;
import com.ejweb.core.security.DES3Utils; import com.ejweb.core.security.DES3Utils;
import com.ejweb.core.util.Util;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
...@@ -78,9 +79,9 @@ public class SecurityPropertyPlaceholderConfigurer extends PropertyPlaceholderCo ...@@ -78,9 +79,9 @@ public class SecurityPropertyPlaceholderConfigurer extends PropertyPlaceholderCo
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(DES3Utils.encrypt("foctest", CONF_DESC_KEY)); // System.out.println(DES3Utils.encrypt("foctest", CONF_DESC_KEY));
System.out.println(DES3Utils.decrypt("dc6788486fc8fa46bdc79e88019874d2dba29c9323df0d41d422c89b73b481946acb4985946fc04c9e83784b79a27bf935e0dbe240259eb88daa2a68d7c26b3c05ef21acf1ec90e77072592f9207bf97", CONF_DESC_KEY)); // System.out.println(DES3Utils.decrypt("dc6788486fc8fa46bdc79e88019874d2dba29c9323df0d41d422c89b73b481946acb4985946fc04c9e83784b79a27bf935e0dbe240259eb88daa2a68d7c26b3c05ef21acf1ec90e77072592f9207bf97", CONF_DESC_KEY));
System.out.println(DES3Utils.decrypt("776b3d2f912b12f8", CONF_DESC_KEY)); // System.out.println(DES3Utils.decrypt("776b3d2f912b12f8", CONF_DESC_KEY));
System.out.println(DES3Utils.decrypt("6f2237c231b1464c6474030c906ec914", CONF_DESC_KEY)); System.out.println(DES3Utils.decrypt("f5c9d35c1df1eb31c0f15d23ee5af33d15ee14d1133b16ae580893ec603fc77c0057d3cccb34407d0505fc99a849cd7ee060d2c605d68b21ea7fea2a325dd4026e7f13e65e216d967bc7696f608fe56ef11ae4801b727c51d09bc4beb44b24f0", CONF_DESC_KEY));
} }
} }
...@@ -20,14 +20,19 @@ import java.io.Writer; ...@@ -20,14 +20,19 @@ import java.io.Writer;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Util { public class Util {
static Pattern p = Pattern.compile("^1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([0125689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[89]\\d)\\d{7}$");
public static String phoneNumberFormat(String phone) { public static String phoneNumberFormat(String phone) {
if (phone == null) if (phone == null) {
return null; return null;
}
int len = phone.length(); int len = phone.length();
if (len >= 8) { if (len >= 8) {
// return phone.replaceAll("(\\d{3})\\d{4}(\\d+)","$1****$2");// 正则匹配
return phone.substring(0, 3) + "****" + phone.substring(7, len);// 字符串拼接 return phone.substring(0, 3) + "****" + phone.substring(7, len);// 字符串拼接
} }
return phone; return phone;
...@@ -42,16 +47,21 @@ public class Util { ...@@ -42,16 +47,21 @@ public class Util {
* @time 2017年3月24日 * @time 2017年3月24日
*/ */
public static String getShowPhone(String phone) { public static String getShowPhone(String phone) {
if (StringUtils.isEmpty(phone))// 未知 if (StringUtils.isEmpty(phone)) {
return ""; return "";
if (phone.startsWith("1") && phone.length() == 11)// 手机号 }
if (phone.startsWith("1") && phone.length() == 11) {
return phone; return phone;
if (phone.startsWith("01") && phone.length() == 12)// 手机号 }
if (phone.startsWith("01") && phone.length() == 12) {
return phone.substring(1); return phone.substring(1);
if (phone.startsWith("001") && phone.length() == 13)// 手机号 }
if (phone.startsWith("001") && phone.length() == 13) {
return phone.substring(2); return phone.substring(2);
if (phone.startsWith("5") && phone.length() == 4)// 座机号 }
if (phone.startsWith("5") && phone.length() == 4) {
return "6961" + phone; return "6961" + phone;
}
return phone;// 座机 return phone;// 座机
} }
...@@ -64,16 +74,22 @@ public class Util { ...@@ -64,16 +74,22 @@ public class Util {
* @time 2017年3月19日 * @time 2017年3月19日
*/ */
public static String getPhoneType(String phone) { public static String getPhoneType(String phone) {
if (StringUtils.isEmpty(phone))// 未知 // 未知
if (StringUtils.isEmpty(phone)) {
return "UNKNOWN"; return "UNKNOWN";
if (phone.startsWith("1") && phone.length() == 11)// 手机号 }
if (phone.startsWith("1") && phone.length() == 11) {
return "MOBILE"; return "MOBILE";
if (phone.startsWith("01") && phone.length() == 12)// 手机号 }
if (phone.startsWith("01") && phone.length() == 12) {
return "MOBILE"; return "MOBILE";
if (phone.startsWith("001") && phone.length() == 13)// 手机号 }
if (phone.startsWith("001") && phone.length() == 13) {
return "MOBILE"; return "MOBILE";
if (phone.startsWith("6") && phone.length() == 4)// 华为短号 }
if (phone.startsWith("6") && phone.length() == 4) {
return "HWNUBMER"; return "HWNUBMER";
}
return "PHONE";// 座机 return "PHONE";// 座机
} }
...@@ -117,8 +133,9 @@ public class Util { ...@@ -117,8 +133,9 @@ public class Util {
} }
public static int parseInt(String val, int want) { public static int parseInt(String val, int want) {
if (StringUtils.isEmpty(val)) if (StringUtils.isEmpty(val)) {
return want; return want;
}
try { try {
return Integer.parseInt(val); return Integer.parseInt(val);
} catch (Exception e) { } catch (Exception e) {
...@@ -243,8 +260,9 @@ public class Util { ...@@ -243,8 +260,9 @@ public class Util {
* @time 2016年12月12日 * @time 2016年12月12日
*/ */
public static String formatedMobile(String mobile) { public static String formatedMobile(String mobile) {
if (mobile == null || mobile.length() == 0) if (mobile == null || mobile.length() == 0) {
return mobile; return mobile;
}
try { try {
String[] species = mobile.split("\\s+");// 只使用第一个手机号 String[] species = mobile.split("\\s+");// 只使用第一个手机号
if (species.length > 1 && species[0].matches("1\\d+") && species[1].matches("1\\d+")) { if (species.length > 1 && species[0].matches("1\\d+") && species[1].matches("1\\d+")) {
...@@ -291,8 +309,9 @@ public class Util { ...@@ -291,8 +309,9 @@ public class Util {
* @time 2016年12月12日 * @time 2016年12月12日
*/ */
public static String formatedWorkPhone(String workPhone) { public static String formatedWorkPhone(String workPhone) {
if (workPhone == null || workPhone.length() == 0) if (workPhone == null || workPhone.length() == 0) {
return workPhone; return workPhone;
}
try { try {
workPhone = workPhone.replaceAll("[^\\d|+]+", ""); workPhone = workPhone.replaceAll("[^\\d|+]+", "");
if (workPhone.matches("0+")) { // 非座机号设置为空 if (workPhone.matches("0+")) { // 非座机号设置为空
...@@ -357,7 +376,6 @@ public class Util { ...@@ -357,7 +376,6 @@ public class Util {
errors.close(); errors.close();
} catch (Exception e1) { } catch (Exception e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
// e1.printStackTrace();
} }
return error; return error;
} }
...@@ -372,12 +390,15 @@ public class Util { ...@@ -372,12 +390,15 @@ public class Util {
* @time 2016年12月11日 * @time 2016年12月11日
*/ */
public static String getAbsoluteUrl(String url, String want) { public static String getAbsoluteUrl(String url, String want) {
if (StringUtils.isBlank(url)) if (StringUtils.isBlank(url)) {
return getAbsoluteUrl(want); return getAbsoluteUrl(want);
if (url.startsWith("http://") || url.startsWith("https://"))// 绝对路径 }
if (url.startsWith("http://") || url.startsWith("https://")) {
return url; return url;
if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径 }
if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/")) {
return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", ""); return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", "");
}
return GConstants.FILE_PREFIX_URL + url; return GConstants.FILE_PREFIX_URL + url;
} }
...@@ -390,12 +411,17 @@ public class Util { ...@@ -390,12 +411,17 @@ public class Util {
* @time 2016年9月1日 * @time 2016年9月1日
*/ */
public static String getAbsoluteUrl(String url) { public static String getAbsoluteUrl(String url) {
if (StringUtils.isBlank(url)) if (StringUtils.isBlank(url)) {
return ""; return "";
if (url.startsWith("http://") || url.startsWith("https://"))// 绝对路径 }
// 绝对路径
if (url.startsWith("http://") || url.startsWith("https://")) {
return url; return url;
if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/"))// 相对路径 }
// 相对路径
if (GConstants.FILE_PREFIX_URL.endsWith("/") && url.startsWith("/")) {
return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", ""); return GConstants.FILE_PREFIX_URL + url.replaceAll("^/+", "");
}
return GConstants.FILE_PREFIX_URL + url; return GConstants.FILE_PREFIX_URL + url;
} }
...@@ -408,10 +434,10 @@ public class Util { ...@@ -408,10 +434,10 @@ public class Util {
* @time 2017年1月13日 * @time 2017年1月13日
*/ */
public static String getRelativePath(String url) { public static String getRelativePath(String url) {
if (StringUtils.isBlank(url)) if (StringUtils.isBlank(url)) {
return ""; return "";
}
return url.replaceAll(GConstants.FILE_PREFIX_URL, ""); return url.replaceAll(GConstants.FILE_PREFIX_URL, "");
// return url;
} }
/** /**
...@@ -421,16 +447,9 @@ public class Util { ...@@ -421,16 +447,9 @@ public class Util {
* @return * @return
*/ */
public static String getExtensionName(String filename) { public static String getExtensionName(String filename) {
// if(filename == null || filename.length() == 0) if (filename == null || filename.length() == 0) {
// return null;
// if(filename.contains(".")){
// String[] species = filename.split("\\.");
// return "."+species[species.length-1].toLowerCase();
// }
// return null;
if (filename == null || filename.length() == 0)
return ""; return "";
}
int startIndex = filename.lastIndexOf(".") + 1; int startIndex = filename.lastIndexOf(".") + 1;
int length = filename.length(); int length = filename.length();
if (startIndex > 0 && startIndex < length) { if (startIndex > 0 && startIndex < length) {
...@@ -449,8 +468,9 @@ public class Util { ...@@ -449,8 +468,9 @@ public class Util {
* @time 2017年2月10日 * @time 2017年2月10日
*/ */
public static String getFileExtensionName(String filename) { public static String getFileExtensionName(String filename) {
if (filename == null || filename.length() == 0) if (filename == null || filename.length() == 0) {
return ""; return "";
}
int startIndex = filename.lastIndexOf(".") + 1; int startIndex = filename.lastIndexOf(".") + 1;
int length = filename.length(); int length = filename.length();
if (startIndex > 0 && startIndex < length) { if (startIndex > 0 && startIndex < length) {
...@@ -479,10 +499,11 @@ public class Util { ...@@ -479,10 +499,11 @@ public class Util {
for (int i = 0; i < maxlength; i++) { for (int i = 0; i < maxlength; i++) {
// if the checked version is too short // if the checked version is too short
if (checkVersion.length <= i if (checkVersion.length <= i
&& originalVersion[i].equals(0)) && originalVersion[i].equals(0)) {
return true; return true;
else if (checkVersion.length <= i) } else if (checkVersion.length <= i) {
return false; return false;
}
// if the original version is long enough // if the original version is long enough
if (originalVersion.length > i) { if (originalVersion.length > i) {
...@@ -552,7 +573,6 @@ public class Util { ...@@ -552,7 +573,6 @@ public class Util {
public static String getGenericCode() { public static String getGenericCode() {
try { try {
return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase(); return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase();
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
...@@ -561,8 +581,9 @@ public class Util { ...@@ -561,8 +581,9 @@ public class Util {
} }
public static boolean isrContainValues(JSONArray data, String... values) { public static boolean isrContainValues(JSONArray data, String... values) {
if (data == null || values == null) if (data == null || values == null) {
return false; return false;
}
int count = 0; int count = 0;
int len = data.size(); int len = data.size();
for (String val : values) { for (String val : values) {
...@@ -579,8 +600,9 @@ public class Util { ...@@ -579,8 +600,9 @@ public class Util {
} }
public static boolean isPraramerValue(JSONObject data, String... colums) { public static boolean isPraramerValue(JSONObject data, String... colums) {
if (data == null || colums == null) if (data == null || colums == null) {
return false; return false;
}
for (String colum : colums) { for (String colum : colums) {
if (data.containsKey(colum) == false) { if (data.containsKey(colum) == false) {
return false; return false;
...@@ -590,8 +612,9 @@ public class Util { ...@@ -590,8 +612,9 @@ public class Util {
} }
public static boolean isInValue(String val, String... vals) { public static boolean isInValue(String val, String... vals) {
if (val == null || vals == null) if (val == null || vals == null) {
return false; return false;
}
for (String v : vals) { for (String v : vals) {
if (val.equals(v)) { if (val.equals(v)) {
return true; return true;
...@@ -607,19 +630,11 @@ public class Util { ...@@ -607,19 +630,11 @@ public class Util {
* @param max * @param max
* @return * @return
*/ */
// public static int getRandom(int min, int max) {
//
// int randomNumber = (int)(Math.random()*(max-min+3)+min);
// while (randomNumber == min || randomNumber == max+2) {
// randomNumber = (int)(Math.random()*(max-min+3)+min);
// }
// return randomNumber-1;
// }
public static int getRandom(int min, int max) { public static int getRandom(int min, int max) {
int randomNumber; int randomNumber;
try { try {
SecureRandom number = SecureRandom.getInstance("SHA1PRNG"); SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
randomNumber = (number.nextInt(max - min + 3) + min);//(int)(Math.random()*(max-min+3)+min); randomNumber = (number.nextInt(max - min + 3) + min);
while (randomNumber == min || randomNumber == max + 2) { while (randomNumber == min || randomNumber == max + 2) {
randomNumber = (number.nextInt(max - min + 3) + min); randomNumber = (number.nextInt(max - min + 3) + min);
} }
...@@ -643,8 +658,9 @@ public class Util { ...@@ -643,8 +658,9 @@ public class Util {
*/ */
public static String getOnlineIP(HttpServletRequest request) { public static String getOnlineIP(HttpServletRequest request) {
//获取X-Forwarded-For //获取X-Forwarded-For
if (request == null) if (request == null) {
return "Unknown"; return "Unknown";
}
String ip = request.getHeader("X-Real-IP"); String ip = request.getHeader("X-Real-IP");
if (StringUtils.isBlank(ip) || "Unknown".equalsIgnoreCase(ip)) { if (StringUtils.isBlank(ip) || "Unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("x-forwarded-for"); ip = request.getHeader("x-forwarded-for");
...@@ -660,8 +676,9 @@ public class Util { ...@@ -660,8 +676,9 @@ public class Util {
} }
} }
} }
if (StringUtils.isBlank(ip)) if (StringUtils.isBlank(ip)) {
return "Unknown"; return "Unknown";
}
return ip.split(",")[0]; return ip.split(",")[0];
} }
...@@ -696,34 +713,6 @@ public class Util { ...@@ -696,34 +713,6 @@ public class Util {
} }
/** /**
* 固话修改规则
* @param workPhone
* @return
*/
// public static String formatPhone(String workPhone) {
// if (StringUtils.isBlank(workPhone)) {
// return workPhone;
// }
// if(workPhone.startsWith("+")){// 外国号码前面加拨3个000
// workPhone = workPhone.replace("+", "000");
// }
// if(workPhone.startsWith("0106961")){// 1、010 6961 xxxx -> xxxx 内部号码,直接拨短号
//
// workPhone = workPhone.replace("0106961", "");
// } else if(workPhone.startsWith("6961")){// 2、6961 xxxx -> xxxx 内部号码,直接拨短号
//
// workPhone = workPhone.replace("6961", "");
// } else if(workPhone.startsWith("010")){// 3、010 xxxx xxxx -> 0 xxxx xxxx 北京号码,去掉区号,加拨0
//
// workPhone = workPhone.replace("010", "0");
// } else {// 4、xxx xxxx xxxx -> 0 xxx xxxx xxxx 国内非北京号码,加拨0
//
// workPhone = "0"+workPhone;
// }
// return workPhone;
// }
/**
* 得到Uc账号,判断规则,如果同时满足前缀,后缀,直接返回该账号。否则按照前缀,后缀规则,添加后返回账号 * 得到Uc账号,判断规则,如果同时满足前缀,后缀,直接返回该账号。否则按照前缀,后缀规则,添加后返回账号
* *
* @return * @return
...@@ -745,32 +734,17 @@ public class Util { ...@@ -745,32 +734,17 @@ public class Util {
return str; return str;
} }
// public static void main(String[] args){ public static boolean phoneReg(String mobile) {
// Map<Integer, Integer> counter = new HashMap<>(); Matcher m = p.matcher(mobile);
// for(int i=0;i<100000;i++){ boolean isMatch = m.matches();
// int a = getRandom(0,200); return isMatch;
// if(counter.get(a) == null){ }
// counter.put(a, 1);
// } else{
//
// counter.put(a, counter.get(a)+1);
// }
// }
// for(Entry<Integer, Integer> a:counter.entrySet()){
//
// System.out.println(a.getKey()+"=>"+a.getValue());
// }
// String email = "renmb@bbdtek.com";
// System.out.println(email.substring(0, email.indexOf("@")));
// System.out.println(phoneNumberFormat("13357826761"));
//// System.out.println(Util.getExtensionName("照片 320.JPG"));
//// System.out.println("结果:"+GConstants.FILE_FILTERS.get(Util.getExtensionName("照片 320.JPG").toLowerCase()) == null);
//// System.out.println(JSON.toJSONString(Util.updateGroupAvatar("4169", "792280723629314048")));
//// System.out.println(Util.getFileExtensionName("a.ah"));
//// System.out.println(Util.formatedWorkPhone("089888693785"));
//// System.out.println(Util.getRelativePath("https://ifos.jdair.net/foc/static/2017/01/13/actuals/images/user/jpg/23198d70826ac171ee03ed5cd3d14c27.jpg"));
// }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(Util.validatePassword("Hjwx#1234", "247fd14c5d908a8312dc23e175e86c4f2e011fb76e08827cd65c962b")); System.out.println(Util.validatePassword("Hjwx#1234", "247fd14c5d908a8312dc23e175e86c4f2e011fb76e08827cd65c962b"));
System.out.println(phoneReg("18501501226"));
System.out.println(phoneReg("018501501226"));
System.out.println(phoneReg("0018501501226"));
System.out.println(phoneReg("51018501501226"));
} }
} }
...@@ -11,6 +11,7 @@ import com.ejweb.core.conf.GConstants; ...@@ -11,6 +11,7 @@ import com.ejweb.core.conf.GConstants;
import com.ejweb.core.fetcher.FetchEntity; import com.ejweb.core.fetcher.FetchEntity;
import com.ejweb.core.fetcher.HCFetcher; import com.ejweb.core.fetcher.HCFetcher;
import com.ejweb.core.util.IdWorker; import com.ejweb.core.util.IdWorker;
import com.ejweb.core.util.Util;
import com.ejweb.modules.message.bean.ShortMsgBean; import com.ejweb.modules.message.bean.ShortMsgBean;
import com.ejweb.modules.message.bean.ShortMsgListBean; import com.ejweb.modules.message.bean.ShortMsgListBean;
import com.ejweb.modules.message.bean.ShortMsgUserListBean; import com.ejweb.modules.message.bean.ShortMsgUserListBean;
...@@ -57,20 +58,34 @@ public class ShortMessageService extends BaseService<ShortMessageDao> { ...@@ -57,20 +58,34 @@ public class ShortMessageService extends BaseService<ShortMessageDao> {
} }
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
String[] phones = phone.split(",|,"); String[] phones = phone.split(",|,");
boolean abroadPhone = false;
for (int i = 0, len = phones.length; i < len; i++) { for (int i = 0, len = phones.length; i < len; i++) {
if (i > 0) { if (i > 0) {
builder.append(","); builder.append(",");
} }
builder.append(phones[i].replaceAll("^0+", "")); //判断号码去掉开头的0之后是否是国内号码
String phone1 = phones[i].replaceAll("^0+", "");
if (Util.phoneReg(phone1)) {
builder.append(phone1);
} else {
builder.append(phones[i]);
abroadPhone = true;
}
} }
//电话号码去除空格,否则导致发送失败 //电话号码去除空格,否则导致发送失败
phone = builder.toString().trim(); phone = builder.toString().trim();
if (StringUtils.isEmpty(phone)) { if (StringUtils.isEmpty(phone)) {
return false; return false;
} }
String url = "";
if (abroadPhone) {
url = GConstants.JDAIR_SMS_API + "&mobile=" + phone + "&msg=" + URLEncoder.encode(bean.getMessage(), "UTF-8") + "&isInternetPhone=1";
} else {
url = GConstants.JDAIR_SMS_API + "&mobile=" + phone + "&msg=" + URLEncoder.encode(bean.getMessage(), "UTF-8");
}
logger.info("短信地址:" + url);
HCFetcher fetcher = HCFetcher.getInstance(); HCFetcher fetcher = HCFetcher.getInstance();
FetchEntity entity = fetcher.post(GConstants.JDAIR_SMS_API + "&mobile=" + phone + "&msg=" + URLEncoder.encode(bean.getMessage(), "UTF-8"), null); FetchEntity entity = fetcher.post(url, null);
if (entity != null && entity.isSuccess()) { if (entity != null && entity.isSuccess()) {
String resultStr = entity.getContent("utf-8"); String resultStr = entity.getContent("utf-8");
// 成功获取数据 // 成功获取数据
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment