Browse Source

短信接口

蔡德晨 5 years ago
parent
commit
d3430e192e
19 changed files with 3154 additions and 190 deletions
  1. 93 70
      src/main/java/com/jeeplus/common/sms/SMSUtils.java
  2. 1801 0
      src/main/java/com/jeeplus/common/sms/sdk/CCPRestSDK.java
  3. 67 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/CcopHttpClient.java
  4. 78 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/DateUtil.java
  5. 59 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/EncryptUtil.java
  6. 65 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/LoggerUtil.java
  7. 45 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/PropertiesUtil.java
  8. 160 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/BASE64Decoder.java
  9. 115 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/BASE64Encoder.java
  10. 11 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CEFormatException.java
  11. 8 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CEStreamExhausted.java
  12. 244 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CharacterDecoder.java
  13. 389 0
      src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CharacterEncoder.java
  14. 3 37
      src/main/java/com/jeeplus/modules/API/sys/RegisterMobileController.java
  15. 1 1
      src/main/java/com/jeeplus/modules/sys/utils/UserUtils.java
  16. 4 35
      src/main/java/com/jeeplus/modules/sys/web/LoginController.java
  17. 3 26
      src/main/java/com/jeeplus/modules/sys/web/RegisterController.java
  18. 4 17
      src/main/java/com/jeeplus/modules/syswarning/service/SysWarningService.java
  19. 4 4
      src/main/resources/jeeplus.properties

+ 93 - 70
src/main/java/com/jeeplus/common/sms/SMSUtils.java

@@ -11,11 +11,13 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import com.jeeplus.common.config.Global;
 import com.jeeplus.common.security.Digests;
+import com.jeeplus.common.sms.sdk.CCPRestSDK;
 import com.jeeplus.modules.esignature.utils.MD5;
 import net.sf.json.JSONObject;
 import org.apache.http.HttpEntity;
@@ -106,86 +108,107 @@ public class SMSUtils {
             return result;
         }
     }
+//    //容联云通讯(160040--超过同模板同号码上限)
+//    public static String sends(String mobile,String randomCode) throws IOException {
+//        BufferedReader reader = null;
+//        StringBuffer result = new StringBuffer("");
+//        try {
+//            StringBuffer sb = new StringBuffer("https://app.cloopen.com:8883/2013-12-26/Accounts/"+Global.getRongUserid()+"/SMS/TemplateSMS?");
+//            StringBuffer sbr = new StringBuffer();
+//            String aid = Global.getRongUserid();
+//            String atoken = Global.getRongToken();
+//            SimpleDateFormat sdf =   new SimpleDateFormat( "yyyyMMddHHmmss" );
+//            String time =sdf.format(new Date());
+//            sbr.append(aid).append(atoken).append(time);
+//            //模板指定参数
+//            String [] s = new String[]{randomCode,"60"};
+//            //sig
+//            sb.append("sig="+ MD5.toMD5(sbr.toString()));
+//
+//            // 创建url对象
+//            URL url = new URL(sb.toString());
+//
+//            // 打开url连接
+//            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+//
+//            // 设置url请求方式 ‘get’ 或者 ‘post’
+//            connection.setRequestMethod("POST");
+//            connection.setRequestProperty("Accept","application/json");
+//            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+//            String an = Global.getRongUserid()+":"+time;
+//            BASE64Encoder encoder = new BASE64Encoder();
+//            an = encoder.encode(an.getBytes("UTF-8"));
+//            connection.setRequestProperty("Authorization", an);
+//            connection.setRequestProperty("Content-Length", "256");
+//            connection.setDoOutput(true);
+//            connection.connect();
+//            //post请求
+//            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
+//            JSONObject obj = new JSONObject();
+//            obj.element("to", mobile);
+//            obj.element("appId", Global.getAppId());
+//            obj.element("templateId", Global.getTemplateId());
+//            obj.element("datas", s);
+//
+//            out.writeBytes(obj.toString());
+//            out.flush();
+//            out.close();
+//            // 发送
+//            reader = new BufferedReader(new InputStreamReader(
+//                    connection.getInputStream()));
+//            String lines;
+//            while ((lines = reader.readLine()) != null) {
+//                lines = new String(lines.getBytes(), "utf-8");
+//                result.append(lines);
+//            }
+//            System.out.println(result);
+//            // 断开连接
+//            connection.disconnect();
+//        }catch (Exception e) {
+//            System.out.println("发送 POST 请求出现异常!"+e);
+//            e.printStackTrace();
+//        }
+//        //使用finally块来关闭输出流、输入流
+//        finally{
+//            try{
+//                if(reader!=null){
+//                    reader.close();
+//                }
+//            }
+//            catch(IOException ex){
+//                ex.printStackTrace();
+//            }
+//            return result.toString();
+//        }
+//    }
+
+
     //容联云通讯(160040--超过同模板同号码上限)
-    public static String sends(String mobile,String randomCode) throws IOException {
-        BufferedReader reader = null;
-        StringBuffer result = new StringBuffer("");
+    public static HashMap<String,Object> sends(String mobile,String randomCode) throws IOException {
+        HashMap<String, Object> result = null;
+        CCPRestSDK restAPI = new CCPRestSDK();
         try {
-            StringBuffer sb = new StringBuffer("https://app.cloopen.com:8883/2013-12-26/Accounts/"+Global.getRongUserid()+"/SMS/TemplateSMS?");
-            StringBuffer sbr = new StringBuffer();
             String aid = Global.getRongUserid();
             String atoken = Global.getRongToken();
-            SimpleDateFormat sdf =   new SimpleDateFormat( "yyyyMMddHHmmss" );
-            String time =sdf.format(new Date());
-            sbr.append(aid).append(atoken).append(time);
-            //模板指定参数
-            String [] s = new String[]{randomCode,"10"};
-            //sig
-            sb.append("sig="+ MD5.toMD5(sbr.toString()));
-
-            // 创建url对象
-            URL url = new URL(sb.toString());
-
-            // 打开url连接
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-
-            // 设置url请求方式 ‘get’ 或者 ‘post’
-            connection.setRequestMethod("POST");
-            connection.setRequestProperty("Accept","application/json");
-            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
-            String an = Global.getRongUserid()+":"+time;
-            BASE64Encoder encoder = new BASE64Encoder();
-            an = encoder.encode(an.getBytes("UTF-8"));
-            connection.setRequestProperty("Authorization", an);
-            connection.setRequestProperty("Content-Length", "256");
-            connection.setDoOutput(true);
-            connection.connect();
-            //post请求
-            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
-            JSONObject obj = new JSONObject();
-            obj.element("to", mobile);
-            obj.element("appId", Global.getAppId());
-            obj.element("templateId", Global.getTemplateId());
-            obj.element("datas", s);
-
-            out.writeBytes(obj.toString());
-            out.flush();
-            out.close();
-            // 发送
-            reader = new BufferedReader(new InputStreamReader(
-                    connection.getInputStream()));
-            String lines;
-            while ((lines = reader.readLine()) != null) {
-                lines = new String(lines.getBytes(), "utf-8");
-                result.append(lines);
-            }
-            System.out.println(result);
-            // 断开连接
-            connection.disconnect();
+            String appId = Global.getAppId();
+            String templateId = Global.getTemplateId();
+            restAPI.init("app.cloopen.com", "8883");
+            restAPI.setAccount(aid, atoken);
+            restAPI.setAppId(appId);
+            result = restAPI.sendTemplateSMS(mobile,templateId,new String[]{randomCode,"60"});
         }catch (Exception e) {
             System.out.println("发送 POST 请求出现异常!"+e);
             e.printStackTrace();
         }
-        //使用finally块来关闭输出流、输入流
-        finally{
-            try{
-                if(reader!=null){
-                    reader.close();
-                }
-            }
-            catch(IOException ex){
-                ex.printStackTrace();
-            }
-            return result.toString();
-        }
+        return result;
     }
 
-    public static void main(String[] args) throws Exception {
-        String inputline =sends("15201428039","系统预警");
-        System.out.println(inputline);
-        long sys = System.currentTimeMillis();
-        System.out.println(sys);
-    }
+//    public static void main(String[] args) throws Exception {
+//        String inputline =sends("15201428039","系统预警");
+//        System.out.println(inputline);
+//        long sys = System.currentTimeMillis();
+//        System.out.println(sys);
+//    }
 
 
 

File diff suppressed because it is too large
+ 1801 - 0
src/main/java/com/jeeplus/common/sms/sdk/CCPRestSDK.java


+ 67 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/CcopHttpClient.java

@@ -0,0 +1,67 @@
+package com.jeeplus.common.sms.sdk.utils;
+
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+public class CcopHttpClient
+{
+  public DefaultHttpClient registerSSL(String hostname, String protocol, int port, String scheme)
+    throws NoSuchAlgorithmException, KeyManagementException
+  {
+    DefaultHttpClient httpclient = new DefaultHttpClient();
+
+    SSLContext ctx = SSLContext.getInstance(protocol);
+
+   X509TrustManager tm = new X509TrustManager()
+    {
+      public void checkClientTrusted(X509Certificate[] chain,String authType)
+			 throws CertificateException {
+      }
+
+      public void checkServerTrusted(X509Certificate[] chain,String authType)
+ 			 throws CertificateException {
+        if ((chain == null) || (chain.length == 0))
+          throw new IllegalArgumentException("null or zero-length certificate chain");
+        if ((authType == null) || (authType.length() == 0))
+          throw new IllegalArgumentException("null or zero-length authentication type");
+
+        boolean br = false;
+        Principal principal = null;
+       for (X509Certificate x509Certificate : chain) {   
+          principal = x509Certificate.getSubjectX500Principal();
+          if (principal != null) {
+            br = true;
+            return;
+          }
+        }
+        if (!(br))
+          throw new CertificateException("服务端证书验证失败!");
+      }
+
+      public X509Certificate[] getAcceptedIssuers()
+      {
+        return new X509Certificate[0];
+      }
+
+    };
+    ctx.init(null, new TrustManager[] { tm }, new SecureRandom());
+
+    SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+    Scheme sch = new Scheme(scheme, port, socketFactory);
+
+    httpclient.getConnectionManager().getSchemeRegistry().register(sch);
+    return httpclient;
+  }
+}

+ 78 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/DateUtil.java

@@ -0,0 +1,78 @@
+/*
+ *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.yuntongxun.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.common.sms.sdk.utils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class DateUtil
+{
+  public static final int DEFAULT = 0;
+  public static final int YM = 1;
+  public static final int YMR_SLASH = 11;
+  public static final int NO_SLASH = 2;
+  public static final int YM_NO_SLASH = 3;
+  public static final int DATE_TIME = 4;
+  public static final int DATE_TIME_NO_SLASH = 5;
+  public static final int DATE_HM = 6;
+  public static final int TIME = 7;
+  public static final int HM = 8;
+  public static final int LONG_TIME = 9;
+  public static final int SHORT_TIME = 10;
+  public static final int DATE_TIME_LINE = 12;
+
+  public static String dateToStr(Date date, String pattern)
+  {
+    if ((date == null) || (date.equals("")))
+      return null;
+    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
+    return formatter.format(date);
+  }
+
+  public static String dateToStr(Date date) {
+    return dateToStr(date, "yyyy/MM/dd");
+  }
+
+  public static String dateToStr(Date date, int type) {
+    switch (type)
+    {
+    case 0:
+      return dateToStr(date);
+    case 1:
+      return dateToStr(date, "yyyy/MM");
+    case 2:
+      return dateToStr(date, "yyyyMMdd");
+    case 11:
+      return dateToStr(date, "yyyy-MM-dd");
+    case 3:
+      return dateToStr(date, "yyyyMM");
+    case 4:
+      return dateToStr(date, "yyyy/MM/dd HH:mm:ss");
+    case 5:
+      return dateToStr(date, "yyyyMMddHHmmss");
+    case 6:
+      return dateToStr(date, "yyyy/MM/dd HH:mm");
+    case 7:
+      return dateToStr(date, "HH:mm:ss");
+    case 8:
+      return dateToStr(date, "HH:mm");
+    case 9:
+      return dateToStr(date, "HHmmss");
+    case 10:
+      return dateToStr(date, "HHmm");
+    case 12:
+      return dateToStr(date, "yyyy-MM-dd HH:mm:ss");
+    }
+    throw new IllegalArgumentException("Type undefined : " + type);
+  }
+}

+ 59 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/EncryptUtil.java

@@ -0,0 +1,59 @@
+/*
+ *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.yuntongxun.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.common.sms.sdk.utils;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import com.jeeplus.common.sms.sdk.utils.encoder.BASE64Decoder;
+import com.jeeplus.common.sms.sdk.utils.encoder.BASE64Encoder;
+
+public class EncryptUtil
+{
+  private static final String UTF8 = "utf-8";
+
+  public String md5Digest(String src) throws NoSuchAlgorithmException, UnsupportedEncodingException
+  {
+    MessageDigest md = MessageDigest.getInstance("MD5");
+    byte[] b = md.digest(src.getBytes("utf-8"));
+    return byte2HexStr(b);
+  }
+
+  public String base64Encoder(String src) throws UnsupportedEncodingException
+  {
+    BASE64Encoder encoder = new BASE64Encoder();
+    return encoder.encode(src.getBytes("utf-8"));
+  }
+
+  public String base64Decoder(String dest)
+    throws NoSuchAlgorithmException, IOException
+  {
+    BASE64Decoder decoder = new BASE64Decoder();
+    return new String(decoder.decodeBuffer(dest), "utf-8");
+  }
+
+  private String byte2HexStr(byte[] b)
+  {
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < b.length; ++i) {
+      String s = Integer.toHexString(b[i] & 0xFF);
+      if (s.length() == 1)
+        sb.append("0");
+
+      sb.append(s.toUpperCase());
+    }
+    return sb.toString();
+  }
+}

+ 65 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/LoggerUtil.java

@@ -0,0 +1,65 @@
+package com.jeeplus.common.sms.sdk.utils;
+
+import java.util.Date;
+import java.util.Properties;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import com.jeeplus.common.sms.sdk.CCPRestSDK;
+
+
+public class LoggerUtil {
+	private static boolean isLog = true;
+	private static Logger logger;
+	static {
+		if (logger == null) {
+			logger = Logger.getLogger(CCPRestSDK.class);
+			
+		}
+	}
+	 
+	public static void setLogger(boolean isLog) {
+		LoggerUtil.isLog = isLog;
+	}
+	public static void setLog(Logger logger) {
+		LoggerUtil.logger = logger;
+	}
+	
+	public static void setLogLevel(int level) {
+		if (logger == null) {
+			logger = Logger.getLogger(CCPRestSDK.class);
+		}
+		PropertyConfigurator.configure(PropertiesUtil.getPropertie(level));
+		 
+
+
+	}
+
+	public static void debug(Object msg) {
+		if (isLog)
+			logger.debug(new Date()+" "+msg);
+	}
+
+	public static void info(Object msg) {
+		if (isLog)
+			logger.info(new Date()+" "+msg);
+	}
+
+	public static void warn(Object msg) {
+		if (isLog)
+			logger.warn(msg);
+	}
+
+	public static void error(Object msg) {
+		if (isLog)
+			logger.error(msg);
+	}
+
+	public static void fatal(Object msg) {
+		if (isLog)
+			logger.fatal(msg);
+	}
+	  
+}

+ 45 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/PropertiesUtil.java

@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2013 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.cloopen.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+package com.jeeplus.common.sms.sdk.utils;
+import java.util.Properties;
+
+public class PropertiesUtil {
+	
+	
+	public static Properties getPropertie(int level) {
+			String loggerLever="all";
+			if(level==1){
+				loggerLever="info";
+			}else if(level==2){
+				loggerLever="warn";
+			}else if(level==3){
+				loggerLever="error";
+			}else if(level==4){
+				loggerLever="fatal";
+			}
+			Properties props = new Properties();
+			
+			props.setProperty("log4j.rootLogger", loggerLever+",A,R");
+			props.setProperty("log4j.appender.A", "org.apache.log4j.ConsoleAppender");
+			props.setProperty("log4j.appender.A.layout", "org.apache.log4j.PatternLayout");
+			props.setProperty("log4j.appender.R", "org.apache.log4j.RollingFileAppender");
+			props.setProperty("log4j.appender.R.File", "log.txt");
+			props.setProperty("log4j.appender.R.MaxFileSize", "100KB");
+			props.setProperty("log4j.appender.R.MaxBackupIndex", "1");
+			props.setProperty("log4j.appender.R.layout", "org.apache.log4j.PatternLayout");
+			props.setProperty("log4j.appender.R.layout.ConversionPattern", "%p %t %c - %m%n");
+			
+			return props;
+	}
+	
+}

+ 160 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/BASE64Decoder.java

@@ -0,0 +1,160 @@
+  /*
+    2    * Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
+    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+    4    *
+    5    * This code is free software; you can redistribute it and/or modify it
+    6    * under the terms of the GNU General Public License version 2 only, as
+    7    * published by the Free Software Foundation.  Oracle designates this
+    8    * particular file as subject to the "Classpath" exception as provided
+    9    * by Oracle in the LICENSE file that accompanied this code.
+   10    *
+   11    * This code is distributed in the hope that it will be useful, but WITHOUT
+   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   14    * version 2 for more details (a copy is included in the LICENSE file that
+   15    * accompanied this code).
+   16    *
+   17    * You should have received a copy of the GNU General Public License version
+   18    * 2 along with this work; if not, write to the Free Software Foundation,
+   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+   20    *
+   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+   22    * or visit www.oracle.com if you need additional information or have any
+   23    * questions.
+   24    */
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+ import java.io.OutputStream;
+import java.io.PushbackInputStream;
+ import java.io.PrintStream;
+
+ /**
+   32    * This class implements a BASE64 Character decoder as specified in RFC1521.
+   33    *
+   34    * This RFC is part of the MIME specification which is published by the
+   35    * Internet Engineering Task Force (IETF). Unlike some other encoding
+   36    * schemes there is nothing in this encoding that tells the decoder
+   37    * where a buffer starts or stops, so to use it you will need to isolate
+   38    * your encoded data into a single chunk and then feed them this decoder.
+   39    * The simplest way to do that is to read all of the encoded data into a
+   40    * string and then use:
+   41    * <pre>
+   42    *      byte    mydata[];
+   43    *      BASE64Decoder base64 = new BASE64Decoder();
+   44    *
+   45    *      mydata = base64.decodeBuffer(bufferString);
+   46    * </pre>
+   47    * This will decode the String in <i>bufferString</i> and give you an array
+   48    * of bytes in the array <i>myData</i>.
+   49    *
+   50    * On errors, this class throws a CEFormatException with the following detail
+   51    * strings:
+   52    * <pre>
+   53    *    "BASE64Decoder: Not enough bytes for an atom."
+   54    * </pre>
+   55    *
+   56    * @author      Chuck McManis
+   57    * @see         CharacterEncoder
+   58    * @see         BASE64Decoder
+   59    */
+ 
+  public class BASE64Decoder extends CharacterDecoder {
+ 
+/** This class has 4 bytes per atom */
+ protected int bytesPerAtom() {
+      return (4);
+    }
+ 
+    /** Any multiple of 4 will do, 72 might be common */
+  protected int bytesPerLine() {
+      return (72);
+    }
+
+   /**
+   74        * This character array provides the character to value map
+   75        * based on RFC1521.
+   76        */
+      private final static char pem_array[] = {
+         //       0   1   2   3   4   5   6   7
+                    'A','B','C','D','E','F','G','H', // 0
+                  'I','J','K','L','M','N','O','P', // 1
+                'Q','R','S','T','U','V','W','X', // 2
+                 'Y','Z','a','b','c','d','e','f', // 3
+                'g','h','i','j','k','l','m','n', // 4
+               'o','p','q','r','s','t','u','v', // 5
+                  'w','x','y','z','0','1','2','3', // 6
+                '4','5','6','7','8','9','+','/'  // 7
+        };
+ 
+    private final static byte pem_convert_array[] = new byte[256];
+
+    static {
+     for (int i = 0; i < 255; i++) {
+          pem_convert_array[i] = -1;
+      }
+       for (int i = 0; i < pem_array.length; i++) {
+          pem_convert_array[pem_array[i]] = (byte) i;
+     }
+     }
+   byte decode_buffer[] = new byte[4];
+   /**
+  103        * Decode one BASE64 atom into 1, 2, or 3 bytes of data.
+  104        */
+  protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
+     throws java.io.IOException
+   {
+        int     i;
+      byte    a = -1, b = -1, c = -1, d = -1;
+
+     if (rem < 2) {
+           throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
+       }
+        do {
+          i = inStream.read();
+           if (i == -1) {
+              throw new CEStreamExhausted();
+              }
+        } while (i == '\n' || i == '\r');
+        decode_buffer[0] = (byte) i;
+
+     i = readFully(inStream, decode_buffer, 1, rem-1);
+     if (i == -1) {
+       throw new CEStreamExhausted();
+      }
+
+        if (rem > 3 && decode_buffer[3] == '=') {
+            rem = 3;
+         }
+        if (rem > 2 && decode_buffer[2] == '=') {
+            rem = 2;
+       }
+      switch (rem) {
+       case 4:
+          d = pem_convert_array[decode_buffer[3] & 0xff];
+         // NOBREAK
+      case 3:
+           c = pem_convert_array[decode_buffer[2] & 0xff];
+       // NOBREAK
+    case 2:
+        b = pem_convert_array[decode_buffer[1] & 0xff];
+       a = pem_convert_array[decode_buffer[0] & 0xff];
+            break;
+       }
+
+       switch (rem) {
+        case 2:
+          outStream.write( (byte)(((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
+          break;
+      case 3:
+             outStream.write( (byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
+            outStream.write( (byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)) );
+            break;
+        case 4:
+           outStream.write( (byte) (((a << 2) & 0xfc) | ((b >>> 4) & 3)) );
+            outStream.write( (byte) (((b << 4) & 0xf0) | ((c >>> 2) & 0xf)) );
+         outStream.write( (byte) (((c << 6) & 0xc0) | (d  & 0x3f)) );
+       break;
+ }
+      return;
+   }
+ }

+ 115 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/BASE64Encoder.java

@@ -0,0 +1,115 @@
+/*
+   2    * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
+   3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+   4    *
+   5    * This code is free software; you can redistribute it and/or modify it
+   6    * under the terms of the GNU General Public License version 2 only, as
+   7    * published by the Free Software Foundation.  Oracle designates this
+   8    * particular file as subject to the "Classpath" exception as provided
+   9    * by Oracle in the LICENSE file that accompanied this code.
+  10    *
+  11    * This code is distributed in the hope that it will be useful, but WITHOUT
+  12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+  14    * version 2 for more details (a copy is included in the LICENSE file that
+  15    * accompanied this code).
+  16    *
+  17    * You should have received a copy of the GNU General Public License version
+  18    * 2 along with this work; if not, write to the Free Software Foundation,
+  19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+  20    *
+  21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+  22    * or visit www.oracle.com if you need additional information or have any
+  23    * questions.
+  24    */
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.IOException;
+
+/**
+ * This class implements a BASE64 Character encoder as specified in RFC1521.
+ * This RFC is part of the MIME specification as published by the Internet
+ * Engineering Task Force (IETF). Unlike some other encoding schemes there is
+ * nothing in this encoding that indicates where a buffer starts or ends.
+ * 
+ * This means that the encoded text will simply start with the first line of
+ * encoded text and end with the last line of encoded text.
+ * 
+ * @author Chuck McManis
+ * @see CharacterEncoder
+ * @see BASE64Decoder
+ */
+public class BASE64Encoder extends CharacterEncoder
+{
+
+	/** this class encodes three bytes per atom. */
+	protected int bytesPerAtom()
+	{
+		return (3);
+	}
+
+	/**
+	 * this class encodes 57 bytes per line. This results in a maximum of 57/3 *
+	 * 4 or 76 characters per output line. Not counting the line termination.
+	 */
+	protected int bytesPerLine()
+	{
+		return (57);
+	}
+
+	/** This array maps the characters to their 6 bit values */
+	private final static char pem_array[] =
+	{
+			// 0 1 2 3 4 5 6 7
+			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0
+			'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 1
+			'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 2
+			'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 3
+			'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 4
+			'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 5
+			'w', 'x', 'y', 'z', '0', '1', '2', '3', // 6
+			'4', '5', '6', '7', '8', '9', '+', '/' // 7
+	};
+
+	/**
+	 * encodeAtom - Take three bytes of input and encode it as 4 printable
+	 * characters. Note that if the length in len is less than three is encodes
+	 * either one or two '=' signs to indicate padding characters.
+	 */
+	protected void encodeAtom(OutputStream outStream, byte data[], int offset,
+			int len) throws IOException
+	{
+		byte a, b, c;
+		if (len == 1)
+		{
+			a = data[offset];
+			b = 0;
+			c = 0;
+			outStream.write(pem_array[(a >>> 2) & 0x3F]);
+			outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
+			outStream.write('=');
+			outStream.write('=');
+		} else if (len == 2)
+		{
+			a = data[offset];
+			b = data[offset + 1];
+			c = 0;
+			outStream.write(pem_array[(a >>> 2) & 0x3F]);
+			outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
+			outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
+			outStream.write('=');
+		} else
+		{
+			a = data[offset];
+			b = data[offset + 1];
+			c = data[offset + 2];
+			outStream.write(pem_array[(a >>> 2) & 0x3F]);
+			outStream.write(pem_array[((a << 4) & 0x30) + ((b >>> 4) & 0xf)]);
+			outStream.write(pem_array[((b << 2) & 0x3c) + ((c >>> 6) & 0x3)]);
+			outStream.write(pem_array[c & 0x3F]);
+		}
+	}
+}

+ 11 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CEFormatException.java

@@ -0,0 +1,11 @@
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+import java.io.IOException;
+
+public class CEFormatException extends IOException
+{
+	public CEFormatException(String s)
+	{
+		super(s);
+	}
+}

+ 8 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CEStreamExhausted.java

@@ -0,0 +1,8 @@
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+import java.io.IOException;
+
+public class CEStreamExhausted extends IOException
+{
+
+}

+ 244 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CharacterDecoder.java

@@ -0,0 +1,244 @@
+/*
+    2    * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
+    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+    4    *
+    5    * This code is free software; you can redistribute it and/or modify it
+    6    * under the terms of the GNU General Public License version 2 only, as
+    7    * published by the Free Software Foundation.  Oracle designates this
+    8    * particular file as subject to the "Classpath" exception as provided
+    9    * by Oracle in the LICENSE file that accompanied this code.
+   10    *
+   11    * This code is distributed in the hope that it will be useful, but WITHOUT
+   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   14    * version 2 for more details (a copy is included in the LICENSE file that
+   15    * accompanied this code).
+   16    *
+   17    * You should have received a copy of the GNU General Public License version
+   18    * 2 along with this work; if not, write to the Free Software Foundation,
+   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+   20    *
+   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+   22    * or visit www.oracle.com if you need additional information or have any
+   23    * questions.
+   24    */
+
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * 37 * This class defines the decoding half of character encoders. 38 * A
+ * character decoder is an algorithim for transforming 8 bit 39 * binary data
+ * that has been encoded into text by a character 40 * encoder, back into
+ * original binary form. 41 * 42 * The character encoders, in general, have been
+ * structured 43 * around a central theme that binary data can be encoded into
+ * 44 * text that has the form: 45 * 46 *
+ * 
+ * <pre>
+ *    47    *      [Buffer Prefix]
+ *    48    *      [Line Prefix][encoded data atoms][Line Suffix]
+ *    49    *      [Buffer Suffix]
+ *    50    *
+ * </pre>
+ * 
+ * 51 * 52 * Of course in the simplest encoding schemes, the buffer has no 53 *
+ * distinct prefix of suffix, however all have some fixed relationship 54 *
+ * between the text in an 'atom' and the binary data itself. 55 * 56 * In the
+ * CharacterEncoder and CharacterDecoder classes, one complete 57 * chunk of
+ * data is referred to as a <i>buffer</i>. Encoded buffers 58 * are all text,
+ * and decoded buffers (sometimes just referred to as 59 * buffers) are binary
+ * octets. 60 * 61 * To create a custom decoder, you must, at a minimum, overide
+ * three 62 * abstract methods in this class. 63 *
+ * <DL>
+ * 64 *
+ * <DD>bytesPerAtom which tells the decoder how many bytes to 65 * expect from
+ * decodeAtom 66 *
+ * <DD>decodeAtom which decodes the bytes sent to it as text. 67 *
+ * <DD>bytesPerLine which tells the encoder the maximum number of 68 * bytes per
+ * line. 69 *
+ * </DL>
+ * 70 * 71 * In general, the character decoders return error in the form of a 72
+ * * CEFormatException. The syntax of the detail string is 73 *
+ * 
+ * <pre>
+ *    74    *      DecoderClassName: Error message.
+ *    75    *
+ * </pre>
+ * 
+ * 76 * 77 * Several useful decoders have already been written and are 78 *
+ * referenced in the See Also list below. 79 * 80 * @author Chuck McManis 81 * @see
+ * CEFormatException 82 * @see CharacterEncoder 83 * @see UCDecoder 84 * @see
+ * UUDecoder 85 * @see BASE64Decoder 86
+ */
+
+public abstract class CharacterDecoder
+{
+
+	/** Return the number of bytes per atom of decoding */
+	abstract protected int bytesPerAtom();
+
+	/** Return the maximum number of bytes that can be encoded per line */
+	abstract protected int bytesPerLine();
+
+	/** decode the beginning of the buffer, by default this is a NOP. */
+	protected void decodeBufferPrefix(PushbackInputStream aStream,
+			OutputStream bStream) throws IOException
+	{
+	}
+
+	/** decode the buffer suffix, again by default it is a NOP. */
+	protected void decodeBufferSuffix(PushbackInputStream aStream,
+			OutputStream bStream) throws IOException
+	{
+	}
+
+	/**
+	 * 103 * This method should return, if it knows, the number of bytes 104 *
+	 * that will be decoded. Many formats such as uuencoding provide 105 * this
+	 * information. By default we return the maximum bytes that 106 * could have
+	 * been encoded on the line. 107
+	 */
+	protected int decodeLinePrefix(PushbackInputStream aStream,
+			OutputStream bStream) throws IOException
+	{
+		return (bytesPerLine());
+	}
+
+	/**
+	 * 113 * This method post processes the line, if there are error detection
+	 * 114 * or correction codes in a line, they are generally processed by 115
+	 * * this method. The simplest version of this method looks for the 116 *
+	 * (newline) character. 117
+	 */
+	protected void decodeLineSuffix(PushbackInputStream aStream,
+			OutputStream bStream) throws IOException
+	{
+	}
+
+	/**
+	 * 121 * This method does an actual decode. It takes the decoded bytes and
+	 * 122 * writes them to the OutputStream. The integer <i>l</i> tells the 123
+	 * * method how many bytes are required. This is always <= bytesPerAtom().
+	 * 124
+	 */
+	protected void decodeAtom(PushbackInputStream aStream,
+			OutputStream bStream, int l) throws IOException
+	{
+		throw new CEStreamExhausted();
+	}
+
+	/**
+	 * 130 * This method works around the bizarre semantics of
+	 * BufferedInputStream's 131 * read method. 132
+	 */
+	protected int readFully(InputStream in, byte buffer[], int offset, int len)
+			throws IOException
+	{
+		for (int i = 0; i < len; i++)
+		{
+			int q = in.read();
+			if (q == -1)
+				return ((i == 0) ? -1 : i);
+			buffer[i + offset] = (byte) q;
+		}
+		return len;
+	}
+
+	/**
+	 * 145 * Decode the text from the InputStream and write the decoded 146 *
+	 * octets to the OutputStream. This method runs until the stream 147 * is
+	 * exhausted. 148 * @exception CEFormatException An error has occured while
+	 * decoding 149 * @exception CEStreamExhausted The input stream is
+	 * unexpectedly out of data 150
+	 */
+	public void decodeBuffer(InputStream aStream, OutputStream bStream)
+			throws IOException
+	{
+		int i;
+		int totalBytes = 0;
+
+		PushbackInputStream ps = new PushbackInputStream(aStream);
+		decodeBufferPrefix(ps, bStream);
+		while (true)
+		{
+			int length;
+
+			try
+			{
+				length = decodeLinePrefix(ps, bStream);
+				for (i = 0; (i + bytesPerAtom()) < length; i += bytesPerAtom())
+				{
+					decodeAtom(ps, bStream, bytesPerAtom());
+					totalBytes += bytesPerAtom();
+				}
+				if ((i + bytesPerAtom()) == length)
+				{
+					decodeAtom(ps, bStream, bytesPerAtom());
+					totalBytes += bytesPerAtom();
+				} else
+				{
+					decodeAtom(ps, bStream, length - i);
+					totalBytes += (length - i);
+				}
+				decodeLineSuffix(ps, bStream);
+			} catch (CEStreamExhausted e)
+			{
+				break;
+			}
+		}
+		decodeBufferSuffix(ps, bStream);
+	}
+
+	/**
+	 * 182 * Alternate decode interface that takes a String containing the
+	 * encoded 183 * buffer and returns a byte array containing the data. 184 * @exception
+	 * CEFormatException An error has occured while decoding 185
+	 */
+	public byte decodeBuffer(String inputString)[] throws IOException
+	{
+		byte inputBuffer[] = new byte[inputString.length()];
+		ByteArrayInputStream inStream;
+		ByteArrayOutputStream outStream;
+
+		inputString.getBytes(0, inputString.length(), inputBuffer, 0);
+		inStream = new ByteArrayInputStream(inputBuffer);
+		outStream = new ByteArrayOutputStream();
+		decodeBuffer(inStream, outStream);
+		return (outStream.toByteArray());
+	}
+
+	/**
+	 * 199 * Decode the contents of the inputstream into a buffer. 200
+	 */
+	public byte decodeBuffer(InputStream in)[] throws IOException
+	{
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		decodeBuffer(in, outStream);
+		return (outStream.toByteArray());
+	}
+
+	/**
+	 * 208 * Decode the contents of the String into a ByteBuffer. 209
+	 */
+	public ByteBuffer decodeBufferToByteBuffer(String inputString)
+			throws IOException
+	{
+		return ByteBuffer.wrap(decodeBuffer(inputString));
+	}
+
+	/**
+	 * 216 * Decode the contents of the inputStream into a ByteBuffer. 217
+	 */
+	public ByteBuffer decodeBufferToByteBuffer(InputStream in)
+			throws IOException
+	{
+		return ByteBuffer.wrap(decodeBuffer(in));
+	}
+}

+ 389 - 0
src/main/java/com/jeeplus/common/sms/sdk/utils/encoder/CharacterEncoder.java

@@ -0,0 +1,389 @@
+/*
+    2    * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.
+    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+    4    *
+    5    * This code is free software; you can redistribute it and/or modify it
+    6    * under the terms of the GNU General Public License version 2 only, as
+    7    * published by the Free Software Foundation.  Oracle designates this
+    8    * particular file as subject to the "Classpath" exception as provided
+    9    * by Oracle in the LICENSE file that accompanied this code.
+   10    *
+   11    * This code is distributed in the hope that it will be useful, but WITHOUT
+   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   14    * version 2 for more details (a copy is included in the LICENSE file that
+   15    * accompanied this code).
+   16    *
+   17    * You should have received a copy of the GNU General Public License version
+   18    * 2 along with this work; if not, write to the Free Software Foundation,
+   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+   20    *
+   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+   22    * or visit www.oracle.com if you need additional information or have any
+   23    * questions.
+   24    */
+
+package com.jeeplus.common.sms.sdk.utils.encoder;
+
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * 38 * This class defines the encoding half of character encoders. 39 * A
+ * character encoder is an algorithim for transforming 8 bit binary 40 * data
+ * into text (generally 7 bit ASCII or 8 bit ISO-Latin-1 text) 41 * for
+ * transmition over text channels such as e-mail and network news. 42 * 43 * The
+ * character encoders have been structured around a central theme 44 * that, in
+ * general, the encoded text has the form: 45 * 46 *
+ * 
+ * <pre>
+ *    47    *      [Buffer Prefix]
+ *    48    *      [Line Prefix][encoded data atoms][Line Suffix]
+ *    49    *      [Buffer Suffix]
+ *    50    *
+ * </pre>
+ * 
+ * 51 * 52 * In the CharacterEncoder and CharacterDecoder classes, one complete
+ * 53 * chunk of data is referred to as a <i>buffer</i>. Encoded buffers 54 *
+ * are all text, and decoded buffers (sometimes just referred to as 55 *
+ * buffers) are binary octets. 56 * 57 * To create a custom encoder, you must,
+ * at a minimum, overide three 58 * abstract methods in this class. 59 *
+ * <DL>
+ * 60 *
+ * <DD>bytesPerAtom which tells the encoder how many bytes to 61 * send to
+ * encodeAtom 62 *
+ * <DD>encodeAtom which encodes the bytes sent to it as text. 63 *
+ * <DD>bytesPerLine which tells the encoder the maximum number of 64 * bytes per
+ * line. 65 *
+ * </DL>
+ * 66 * 67 * Several useful encoders have already been written and are 68 *
+ * referenced in the See Also list below. 69 * 70 * @author Chuck McManis 71 * @see
+ * CharacterDecoder; 72 * @see UCEncoder 73 * @see UUEncoder 74 * @see
+ * BASE64Encoder 75
+ */
+public abstract class CharacterEncoder
+{
+	/** Stream that understands "printing" */
+	protected PrintStream pStream;
+
+	/** Return the number of bytes per atom of encoding */
+	abstract protected int bytesPerAtom();
+
+	/** Return the number of bytes that can be encoded per line */
+	abstract protected int bytesPerLine();
+
+	/**
+	 * 88 * Encode the prefix for the entire buffer. By default is simply 89 *
+	 * opens the PrintStream for use by the other functions. 90
+	 */
+	protected void encodeBufferPrefix(OutputStream aStream) throws IOException
+	{
+		pStream = new PrintStream(aStream);
+	}
+
+	/**
+	 * 96 * Encode the suffix for the entire buffer. 97
+	 */
+	protected void encodeBufferSuffix(OutputStream aStream) throws IOException
+	{
+	}
+
+	/**
+	 * 102 * Encode the prefix that starts every output line. 103
+	 */
+	protected void encodeLinePrefix(OutputStream aStream, int aLength)
+			throws IOException
+	{
+	}
+
+	/**
+	 * 109 * Encode the suffix that ends every output line. By default 110 *
+	 * this method just prints a <newline> into the output stream. 111
+	 */
+	protected void encodeLineSuffix(OutputStream aStream) throws IOException
+	{
+		pStream.println();
+	}
+
+	/** Encode one "atom" of information into characters. */
+	abstract protected void encodeAtom(OutputStream aStream, byte someBytes[],
+			int anOffset, int aLength) throws IOException;
+
+	/**
+	 * 121 * This method works around the bizarre semantics of
+	 * BufferedInputStream's 122 * read method. 123
+	 */
+	protected int readFully(InputStream in, byte buffer[])
+			throws IOException
+	{
+		for (int i = 0; i < buffer.length; i++)
+		{
+			int q = in.read();
+			if (q == -1)
+				return i;
+			buffer[i] = (byte) q;
+		}
+		return buffer.length;
+	}
+
+	/**
+	 * 136 * Encode bytes from the input stream, and write them as text
+	 * characters 137 * to the output stream. This method will run until it
+	 * exhausts the 138 * input stream, but does not print the line suffix for a
+	 * final 139 * line that is shorter than bytesPerLine(). 140
+	 */
+	public void encode(InputStream inStream, OutputStream outStream)
+			throws IOException
+	{
+		int j;
+		int numBytes;
+		byte tmpbuffer[] = new byte[bytesPerLine()];
+
+		encodeBufferPrefix(outStream);
+
+		while (true)
+		{
+			numBytes = readFully(inStream, tmpbuffer);
+			if (numBytes == 0)
+			{
+				break;
+			}
+			encodeLinePrefix(outStream, numBytes);
+			for (j = 0; j < numBytes; j += bytesPerAtom())
+			{
+
+				if ((j + bytesPerAtom()) <= numBytes)
+				{
+					encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
+				} else
+				{
+					encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
+				}
+			}
+			if (numBytes < bytesPerLine())
+			{
+				break;
+			} else
+			{
+				encodeLineSuffix(outStream);
+			}
+		}
+		encodeBufferSuffix(outStream);
+	}
+
+	/**
+	 * 173 * Encode the buffer in <i>aBuffer</i> and write the encoded 174 *
+	 * result to the OutputStream <i>aStream</i>. 175
+	 */
+	public void encode(byte aBuffer[], OutputStream aStream) throws IOException
+	{
+		ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
+		encode(inStream, aStream);
+	}
+
+	/**
+	 * 183 * A 'streamless' version of encode that simply takes a buffer of 184
+	 * * bytes and returns a string containing the encoded buffer. 185
+	 */
+	public String encode(byte aBuffer[])
+	{
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
+		String retVal = null;
+		try
+		{
+			encode(inStream, outStream);
+			// explicit ascii->unicode conversion
+			retVal = outStream.toString("8859_1");
+		} catch (Exception IOException)
+		{
+			// This should never happen.
+			throw new Error("CharacterEncoder.encode internal error");
+		}
+		return (retVal);
+	}
+
+	/**
+	 * 202 * Return a byte array from the remaining bytes in this ByteBuffer.
+	 * 203 *
+	 * <P>
+	 * 204 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
+	 * 205 *
+	 * <P>
+	 * 206 * To avoid an extra copy, the implementation will attempt to return
+	 * the 207 * byte array backing the ByteBuffer. If this is not possible, a
+	 * 208 * new byte array will be created. 209
+	 */
+	private byte[] getBytes(ByteBuffer bb)
+	{
+		/*
+		 * This should never return a BufferOverflowException, as we're 213 *
+		 * careful to allocate just the right amount. 214
+		 */
+		byte[] buf = null;
+
+		/*
+		 * 218 * If it has a usable backing byte buffer, use it. Use only 219 *
+		 * if the array exactly represents the current ByteBuffer. 220
+		 */
+		if (bb.hasArray())
+		{
+			byte[] tmp = bb.array();
+			if ((tmp.length == bb.capacity()) && (tmp.length == bb.remaining()))
+			{
+				buf = tmp;
+				bb.position(bb.limit());
+			}
+		}
+
+		if (buf == null)
+		{
+			/*
+			 * 232 * This class doesn't have a concept of encode(buf, len, off),
+			 * 233 * so if we have a partial buffer, we must reallocate 234 *
+			 * space. 235
+			 */
+			buf = new byte[bb.remaining()];
+
+			/*
+			 * 239 * position() automatically updated 240
+			 */
+			bb.get(buf);
+		}
+
+		return buf;
+	}
+
+	/**
+	 * 248 * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 249 *
+	 * result to the OutputStream <i>aStream</i>. 250 *
+	 * <P>
+	 * 251 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
+	 * 252
+	 */
+	public void encode(ByteBuffer aBuffer, OutputStream aStream)
+			throws IOException
+	{
+		byte[] buf = getBytes(aBuffer);
+		encode(buf, aStream);
+	}
+
+	/**
+	 * 260 * A 'streamless' version of encode that simply takes a ByteBuffer 261
+	 * * and returns a string containing the encoded buffer. 262 *
+	 * <P>
+	 * 263 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
+	 * 264
+	 */
+	public String encode(ByteBuffer aBuffer)
+	{
+		byte[] buf = getBytes(aBuffer);
+		return encode(buf);
+	}
+
+	/**
+	 * 271 * Encode bytes from the input stream, and write them as text
+	 * characters 272 * to the output stream. This method will run until it
+	 * exhausts the 273 * input stream. It differs from encode in that it will
+	 * add the 274 * line at the end of a final line that is shorter than
+	 * bytesPerLine(). 275
+	 */
+	public void encodeBuffer(InputStream inStream, OutputStream outStream)
+			throws IOException
+	{
+		int j;
+		int numBytes;
+		byte tmpbuffer[] = new byte[bytesPerLine()];
+
+		encodeBufferPrefix(outStream);
+
+		while (true)
+		{
+			numBytes = readFully(inStream, tmpbuffer);
+			if (numBytes == 0)
+			{
+				break;
+			}
+			encodeLinePrefix(outStream, numBytes);
+			for (j = 0; j < numBytes; j += bytesPerAtom())
+			{
+				if ((j + bytesPerAtom()) <= numBytes)
+				{
+					encodeAtom(outStream, tmpbuffer, j, bytesPerAtom());
+				} else
+				{
+					encodeAtom(outStream, tmpbuffer, j, (numBytes) - j);
+				}
+			}
+			encodeLineSuffix(outStream);
+			if (numBytes < bytesPerLine())
+			{
+				break;
+			}
+		}
+		encodeBufferSuffix(outStream);
+	}
+
+	/**
+	 * 306 * Encode the buffer in <i>aBuffer</i> and write the encoded 307 *
+	 * result to the OutputStream <i>aStream</i>. 308
+	 */
+	public void encodeBuffer(byte aBuffer[], OutputStream aStream)
+			throws IOException
+	{
+		ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
+		encodeBuffer(inStream, aStream);
+	}
+
+	/**
+	 * 316 * A 'streamless' version of encode that simply takes a buffer of 317
+	 * * bytes and returns a string containing the encoded buffer. 318
+	 */
+	public String encodeBuffer(byte aBuffer[])
+	{
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		ByteArrayInputStream inStream = new ByteArrayInputStream(aBuffer);
+		try
+		{
+			encodeBuffer(inStream, outStream);
+		} catch (Exception IOException)
+		{
+			// This should never happen.
+			throw new Error("CharacterEncoder.encodeBuffer internal error");
+		}
+		return (outStream.toString());
+	}
+
+	/**
+	 * 332 * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 333 *
+	 * result to the OutputStream <i>aStream</i>. 334 *
+	 * <P>
+	 * 335 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
+	 * 336
+	 */
+	public void encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)
+			throws IOException
+	{
+		byte[] buf = getBytes(aBuffer);
+		encodeBuffer(buf, aStream);
+	}
+
+	/**
+	 * 344 * A 'streamless' version of encode that simply takes a ByteBuffer 345
+	 * * and returns a string containing the encoded buffer. 346 *
+	 * <P>
+	 * 347 * The ByteBuffer's position will be advanced to ByteBuffer's limit.
+	 * 348
+	 */
+	public String encodeBuffer(ByteBuffer aBuffer)
+	{
+		byte[] buf = getBytes(aBuffer);
+		return encodeBuffer(buf);
+	}
+
+}

+ 3 - 37
src/main/java/com/jeeplus/modules/API/sys/RegisterMobileController.java

@@ -290,10 +290,8 @@ public class RegisterMobileController extends BaseController {
             }
 
             String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
-            if(("2").equals(Global.getCodeType())){
-                String result =UserUtils.sendRandomCodes(mobile, randomCode);
-                JSONObject jsonObj = JSONObject.fromObject(result);
-                String statusCode = jsonObj.getString("statusCode");
+            HashMap<String,Object> result =UserUtils.sendRandomCodes(mobile, randomCode);
+            String statusCode = (String) result.get("statusCode");
                 //if (result.contains("Success") && result.contains("ok")) {
                 if (("000000").equals(statusCode)) {
                     j.setSuccess(true);
@@ -325,39 +323,7 @@ public class RegisterMobileController extends BaseController {
                     j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
                     j.put("ErrorXml",result);
                 }
-            }else{
-                String result =UserUtils.sendRandomCode(mobile, randomCode);
-                if (result.contains("Success") && result.contains("ok")) {
-                    j.setSuccess(true);
-                    j.setErrorCode(ErrorCode.code_1004);
-                    j.setMsg("短信发送成功!");
-                    Map<String,Object> map = new HashMap<>();
-                    map.put("randomCode",randomCode);
-                    map.put("type",type);
-                    map.put("mobile",mobile);
-                    j.put("data",map);
-                    logger.info("../f/getRandomCode/  randomCode=" + randomCode);
-                    jedis = JedisUtils.getResource();
-                    if(jedis.get(mobile)!=null && jedis.get(type)!=null){
-                        jedis.del(mobile);
-                        jedis.del(type);
-                    }
-                    jedis.set(mobile, randomCode);
-                    jedis.setex(mobile, 300, randomCode);
-                    jedis.set(type, type);
-               /* if(request.getSession().getServletContext().getAttribute(mobile)!=null && request.getSession().getServletContext().getAttribute(type)!=null){
-                    request.getSession().getServletContext().removeAttribute(mobile);
-                    request.getSession().getServletContext().removeAttribute(type);
-                }
-                request.getSession().getServletContext().setAttribute(mobile, randomCode);
-                request.getSession().getServletContext().setAttribute(type, type);*/
-                } else {
-                    j.setSuccess(false);
-                    j.setErrorCode(ErrorCode.code_1008);
-                    j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
-                    j.put("ErrorXml",result);
-                }
-            }
+
 
         }catch (Exception e){
             logger.info("5");

+ 1 - 1
src/main/java/com/jeeplus/modules/sys/utils/UserUtils.java

@@ -908,7 +908,7 @@ public class UserUtils {
 	}
 
 	//容联云通讯
-	public static String sendRandomCodes(String mobile, String randomCode) throws IOException {
+	public static HashMap<String,Object> sendRandomCodes(String mobile, String randomCode) throws IOException {
 		return SMSUtils.sends(mobile, randomCode);
 
 	}

+ 4 - 35
src/main/java/com/jeeplus/modules/sys/web/LoginController.java

@@ -448,14 +448,11 @@ public class LoginController extends BaseController{
 			String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
 			System.err.println(randomCode);
 			// String result = UserUtils.sendRandomCode(config.getSmsName(),config.getSmsPassword(), mobile, randomCode);
-			String result = null;
+			HashMap<String,Object> result = null;
 			try{
-				if(("2").equals(Global.getCodeType())){
 					//调用工具类返回结果
 					result = UserUtils.sendRandomCodes(mobile, randomCode);
-					JSONObject jsonObj = JSONObject.fromObject(result);
-					String statusCode = jsonObj.getString("statusCode");
-					//if (result.contains("Success") && result.contains("ok")) {
+					String statusCode = (String) result.get("statusCode");
 					if (("000000").equals(statusCode)) {
 						j.setSuccess(true);
 						j.setErrorCode("-1");
@@ -471,37 +468,10 @@ public class LoginController extends BaseController{
 						} finally {
 							JedisUtils.returnResource(jedis);
 						}
-						//存放验证码
-						//request.getSession().getServletContext().setAttribute(mobile, randomCode);
-						//request.getSession().getServletContext().setAttribute("type",type);
-					}else{
+					}else if(statusCode.equals("160040")){
 						j.setSuccess(false);
 						j.setErrorCode("2");
-						//j.setMsg("短信发送失败,错误代码:"+result+",请联系管理员。");
-						j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
-						j.put("ErrorXml",result);
-					}
-				}else{
-					//调用工具类返回结果
-					result = UserUtils.sendRandomCode(mobile, randomCode);
-					if (result.contains("Success") && result.contains("ok")) {
-						j.setSuccess(true);
-						j.setErrorCode("-1");
-						j.setMsg("短信发送成功!");
-						Jedis jedis = null;
-						try {
-							jedis = JedisUtils.getResource();
-							jedis.set(mobile, randomCode);
-							jedis.set("type",type);
-							jedis.setex(mobile, 300, randomCode);
-						} catch (Exception e) {
-							//logger.error("getActiveSessions", e);
-						} finally {
-							JedisUtils.returnResource(jedis);
-						}
-						//存放验证码
-						//request.getSession().getServletContext().setAttribute(mobile, randomCode);
-						//request.getSession().getServletContext().setAttribute("type",type);
+						j.setMsg("号码获取验证码次数已达每日上限!");
 					}else{
 						j.setSuccess(false);
 						j.setErrorCode("2");
@@ -509,7 +479,6 @@ public class LoginController extends BaseController{
 						j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
 						j.put("ErrorXml",result);
 					}
-				}
 
 			}catch (Exception e){
 				e.printStackTrace();

+ 3 - 26
src/main/java/com/jeeplus/modules/sys/web/RegisterController.java

@@ -29,6 +29,7 @@ import redis.clients.jedis.Jedis;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -307,14 +308,12 @@ public class RegisterController extends BaseController {
 		String randomCode = String.valueOf((int) (Math.random() * 9000 + 1000));
 		System.out.println(randomCode);
 		// String result = UserUtils.sendRandomCode(config.getSmsName(),config.getSmsPassword(), mobile, randomCode);
-		String result = null;
+			HashMap<String,Object> result = null;
 		Jedis jedis = null;
 		try{
-			if(("2").equals(Global.getCodeType())){
 				//调用工具类返回结果
 				result = UserUtils.sendRandomCodes(mobile, randomCode);
-				JSONObject jsonObj = JSONObject.fromObject(result);
-				String statusCode = jsonObj.getString("statusCode");
+				String statusCode = (String) result.get("statusCode");
 				//if (result.contains("Success") && result.contains("ok")) {
 				if (("000000").equals(statusCode)) {
 					j.setSuccess(true);
@@ -333,28 +332,6 @@ public class RegisterController extends BaseController {
 					j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
 					j.put("ErrorXml",result);
 				}
-			}else{
-				//调用工具类返回结果
-				result = UserUtils.sendRandomCode(mobile, randomCode);
-				if (result.contains("Success") && result.contains("ok")) {
-					j.setSuccess(true);
-					j.setErrorCode("-1");
-					j.setMsg("短信发送成功!");
-					//存放验证码
-					jedis = JedisUtils.getResource();
-					jedis.set(mobile, randomCode);
-
-					jedis.setex(mobile, 300, randomCode);
-					//request.getSession().getServletContext().setAttribute(mobile, randomCode);
-				}else{
-					j.setSuccess(false);
-					j.setErrorCode("2");
-					//j.setMsg("短信发送失败,错误代码:"+result+",请联系管理员。");
-					j.setMsg("短信发送失败,错误代码:101,请联系管理员。");
-					j.put("ErrorXml",result);
-				}
-			}
-
 		}catch (Exception e){
 			e.printStackTrace();
 			logger.info("5");

+ 4 - 17
src/main/java/com/jeeplus/modules/syswarning/service/SysWarningService.java

@@ -6,10 +6,7 @@ package com.jeeplus.modules.syswarning.service;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
 
 import com.jeeplus.common.config.Global;
 import com.jeeplus.common.sms.SMSUtils;
@@ -234,28 +231,18 @@ public class SysWarningService extends CrudService<SysWarningDao, SysWarning> {
 		}
 	}
 	public static void sendWarning(List<User> userList,SysWarning sysWarning){
-		String result = null;
+		HashMap<String,Object> result = null;
 		if (userList!=null && userList.size()!=0) {
 			for (User u : userList) {
 				try{
-					if(("2").equals(Global.getCodeType())){
 						result = UserUtils.sendRandomCodes(u.getMobile(), sysWarning.getComment());
-						JSONObject jsonObj = JSONObject.fromObject(result);
-						String statusCode = jsonObj.getString("statusCode");
+					    String statusCode = (String) result.get("statusCode");
 						if (("000000").equals(statusCode)) {
 							System.out.println("短信发送成功!");
 						}else{
 							System.out.println("短信发送失败!");
 						}
-					}else{
-						//调用工具类返回结果
-						result = UserUtils.sendWarning(u.getMobile(), sysWarning.getComment());
-						if (result.contains("Success") && result.contains("ok")) {
-							System.out.println("短信发送成功!");
-						}else{
-							System.out.println("短信发送失败!");
-						}
-					}
+
 				}catch (Exception e){
 					e.printStackTrace();
 					System.out.println("短信发送失败!");

+ 4 - 4
src/main/resources/jeeplus.properties

@@ -210,10 +210,10 @@ cpu=100
 jvm=100
 ram=100
 
-rong_userid=8a216da860bad76d0160deacd4890e40
-rong_token=8dba68b745e34847af04da94229cc168
-app_id=8a216da860bad76d0160deacd4e40e46
-template_id=327821
+rong_userid=8a216da86715511501673e331c24171e
+rong_token=3d7dc58c6a334ad6887317efbf847e41
+app_id=8a216da86715511501673e331c741725
+template_id=435329
 code_type=1
 
 #\u531E\u531E\u77ED\u4FE1\u6A21\u7248