5713932ef01e78e65bbf944d057d8d3983582061.svn-base 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package com.chinacreator.videoalliance.order.util;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.Date;
  4. import net.sf.json.JSONObject;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.apache.commons.lang.time.DateUtils;
  7. import com.chinacreator.common.exception.BusinessException;
  8. import com.chinacreator.common.util.AESUtil;
  9. import com.chinacreator.common.util.URLUtil;
  10. public class ExternalUtil {
  11. private static final String USERMOB_REG = ".*(1\\d{10}).*";
  12. private static final String BLACK_CHAR_REG = "[\\s-]";
  13. /**
  14. * 获取json对象
  15. * @param json
  16. * @param key
  17. * @param message
  18. * @return
  19. * @throws BusinessException
  20. */
  21. public static String getValue(JSONObject json, String key, String message) throws BusinessException {
  22. if(json.containsKey(key)) {
  23. String value = json.getString(key);
  24. if("null".equals(value)) {
  25. value = null;
  26. }
  27. if(StringUtils.isEmpty(value) && message != null) {
  28. throw new BusinessException("8002",message + "参数无效");
  29. }
  30. return value;
  31. } else if(message != null){
  32. throw new BusinessException("8002", message + "参数无效");
  33. }
  34. return null;
  35. }
  36. /**
  37. * 获取日期格式json对象
  38. * @param json
  39. * @param key
  40. * @param message
  41. * @return
  42. * @throws Exception
  43. */
  44. public static Date getDateValue(JSONObject json, String key, String message) throws Exception {
  45. String value = getValue(json, key, message);
  46. if(StringUtils.isNotEmpty(value)) {
  47. return DateUtils.parseDate(value, new String[]{"yyyyMMddHHmmss"});
  48. }
  49. return null;
  50. }
  51. /**
  52. * 判断手机号码合法性
  53. * @param usermob
  54. * @return
  55. */
  56. public static boolean isValid(String usermob) {
  57. if(usermob == null) {
  58. return false;
  59. }
  60. usermob = usermob.replaceAll(BLACK_CHAR_REG, "");
  61. return usermob.matches(USERMOB_REG);
  62. }
  63. /**
  64. * 格式发手机号码,过滤掉手机号码的多余的前缀和后缀
  65. * @param usermob
  66. * @return
  67. */
  68. public static String format(String usermob) {
  69. usermob = usermob.replaceAll(BLACK_CHAR_REG, "");
  70. return usermob.replaceFirst(USERMOB_REG, "$1");
  71. }
  72. public static void main(String[] args) {
  73. String data="{\"channelcode\":\"hlj\",\"order\":\"82EEA4B644555BFF465B272605953340A5342302043FCCAE8DCDCB3F2E8F44CE474375D92054AFCCFB925E197542E21601E49DBCE7BA27A837FA9C0E6DD5F99A\"}";
  74. String data1="{\"productid\":\"8000610700\",\"userid\":\"18600000000\",\"imsi\":\"460030912121001\",\"expiredate\":\"20370101000000\",\"updatetype\":\"1\",\"effectivedate\":\"20140305010101\"}";
  75. String data2="{\"userid\":\"CEE5E65A96BF9F1BD089B71EF8588808\",\"channelcode\":\"hlj\"}";
  76. try {
  77. System.out.println(URLUtil.post("http://localhost:8080/videoalliance/orderex.do", data));
  78. //System.out.println(AESUtil.encrypt("{\"productid\":\"8000610900\",\"userid\":\"18603663462\"}", "90b94c66ac614d0d"));
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. }