Browse Source

update 新增短信对接

zouxuan 5 years ago
parent
commit
6bee8dd0e9
41 changed files with 2605 additions and 0 deletions
  1. BIN
      libs/gson-2.6.2.jar
  2. 141 0
      src/main/java/com/ym/mec/collectfee/common/sms/AES.java
  3. 12 0
      src/main/java/com/ym/mec/collectfee/common/sms/BalanceRequest.java
  4. 34 0
      src/main/java/com/ym/mec/collectfee/common/sms/BalanceResponse.java
  5. 38 0
      src/main/java/com/ym/mec/collectfee/common/sms/BaseRequest.java
  6. 43 0
      src/main/java/com/ym/mec/collectfee/common/sms/CustomSmsIdAndMobile.java
  7. 54 0
      src/main/java/com/ym/mec/collectfee/common/sms/CustomSmsIdAndMobileAndContent.java
  8. 105 0
      src/main/java/com/ym/mec/collectfee/common/sms/GZIPUtils.java
  9. 452 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpClient.java
  10. 96 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpRequest.java
  11. 20 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestBytes.java
  12. 70 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestParams.java
  13. 42 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestPraser.java
  14. 45 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestPraserBytes.java
  15. 114 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpResponse.java
  16. 33 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpResponseBytes.java
  17. 20 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpResponseBytesPraser.java
  18. 36 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpResponsePraser.java
  19. 70 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpResultCode.java
  20. 48 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpsParams.java
  21. 22 0
      src/main/java/com/ym/mec/collectfee/common/sms/HttpsRequestBytes.java
  22. 130 0
      src/main/java/com/ym/mec/collectfee/common/sms/JsonHelper.java
  23. 32 0
      src/main/java/com/ym/mec/collectfee/common/sms/MoRequest.java
  24. 65 0
      src/main/java/com/ym/mec/collectfee/common/sms/MoResponse.java
  25. 76 0
      src/main/java/com/ym/mec/collectfee/common/sms/PersonalityParams.java
  26. 32 0
      src/main/java/com/ym/mec/collectfee/common/sms/ReportRequest.java
  27. 94 0
      src/main/java/com/ym/mec/collectfee/common/sms/ReportResponse.java
  28. 29 0
      src/main/java/com/ym/mec/collectfee/common/sms/ResultModel.java
  29. 35 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsBaseRequest.java
  30. 40 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsBatchOnlyRequest.java
  31. 38 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsBatchRequest.java
  32. 318 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsExample.java
  33. 23 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsPersonalityAllRequest.java
  34. 23 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsPersonalityRequest.java
  35. 57 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsResponse.java
  36. 53 0
      src/main/java/com/ym/mec/collectfee/common/sms/SmsSingleRequest.java
  37. 14 0
      src/main/java/com/ym/mec/collectfee/controller/UserController.java
  38. 2 0
      src/main/java/com/ym/mec/collectfee/dao/ApplyInfoDao.java
  39. 5 0
      src/main/java/com/ym/mec/collectfee/service/SchoolService.java
  40. 33 0
      src/main/java/com/ym/mec/collectfee/service/impl/SchoolServiceImpl.java
  41. 11 0
      src/main/resources/config/mybatis/ApplyInfoMapper.xml

BIN
libs/gson-2.6.2.jar


+ 141 - 0
src/main/java/com/ym/mec/collectfee/common/sms/AES.java

@@ -0,0 +1,141 @@
+package com.ym.mec.collectfee.common.sms;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * AES加解密工具
+ * 
+ * @author Frank
+ *
+ */
+public class AES {
+	
+	public final static String ALGORITHM_AEPP = "AES/ECB/PKCS5Padding";
+
+	/**
+	 * AES加密
+	 * 
+	 * @param content
+	 *            内容
+	 * @param password
+	 *            密钥
+	 * @param algorithm
+	 *            算法
+	 * @return 加密后数据
+	 */
+	public static byte[] encrypt(byte[] content, byte[] password, String algorithm) {
+		if (content == null || password == null)
+			return null;
+		try {
+			Cipher cipher = null;
+			if (algorithm.endsWith("PKCS7Padding")) {
+				cipher = Cipher.getInstance(algorithm, "BC");
+			} else {
+				cipher = Cipher.getInstance(algorithm);
+			}
+			cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"));
+			return cipher.doFinal(content);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/**
+	 * AES解密
+	 * 
+	 * @param content
+	 *            加密内容
+	 * @param password
+	 *            密钥
+	 * @param algorithm
+	 *            算法
+	 * @return 解密后数据
+	 */
+	public static byte[] decrypt(byte[] content, byte[] password, String algorithm) {
+		if (content == null || password == null)
+			return null;
+		try {
+			Cipher cipher = null;
+			if (algorithm.endsWith("PKCS7Padding")) {
+				cipher = Cipher.getInstance(algorithm, "BC");
+			} else {
+				cipher = Cipher.getInstance(algorithm);
+			}
+			cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"));
+			byte[] bytes = cipher.doFinal(content);
+			return bytes;
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/**
+	 * AES加密
+	 * 
+	 * @param content
+	 *            内容
+	 * @param password
+	 *            密钥
+	 * @param algorithm
+	 *            算法
+	 * @param ivStr
+	 *            向量
+	 * @return 加密后数据
+	 */
+	public static byte[] encrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
+		if (content == null || password == null)
+			return null;
+		try {
+			Cipher cipher = null;
+			if (algorithm.endsWith("PKCS7Padding")) {
+				cipher = Cipher.getInstance(algorithm, "BC");
+			} else {
+				cipher = Cipher.getInstance(algorithm);
+			}
+			IvParameterSpec iv = new IvParameterSpec(ivStr);
+			cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
+			return cipher.doFinal(content);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	/**
+	 * AES解密
+	 * 
+	 * @param content
+	 *            加密内容
+	 * @param password
+	 *            密钥
+	 * @param algorithm
+	 *            算法
+	 * @param ivStr
+	 *            向量
+	 * @return 解密后数据
+	 */
+	public static byte[] decrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
+		if (content == null || password == null)
+			return null;
+		try {
+			Cipher cipher = null;
+			if (algorithm.endsWith("PKCS7Padding")) {
+				cipher = Cipher.getInstance(algorithm, "BC");
+			} else {
+				cipher = Cipher.getInstance(algorithm);
+			}
+			IvParameterSpec iv = new IvParameterSpec(ivStr);
+			cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
+			byte[] bytes = cipher.doFinal(content);
+			return bytes;
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+}

+ 12 - 0
src/main/java/com/ym/mec/collectfee/common/sms/BalanceRequest.java

@@ -0,0 +1,12 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 请求Balance参数
+ * @author Frank
+ *
+ */
+public class BalanceRequest extends BaseRequest {
+	
+	private static final long serialVersionUID = 1L;
+
+}

+ 34 - 0
src/main/java/com/ym/mec/collectfee/common/sms/BalanceResponse.java

@@ -0,0 +1,34 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+
+/**
+ * 余额数据
+ * @author Frank
+ *
+ */
+public class BalanceResponse implements Serializable{
+	
+	private static final long serialVersionUID = 1L;
+
+	private long balance;// 余额
+
+
+	public BalanceResponse() {
+
+	}
+
+	public BalanceResponse(long balance) {
+		this.balance = balance;
+	}
+
+	public long getBalance() {
+		return balance;
+	}
+
+	public void setBalance(long balance) {
+		this.balance = balance;
+	}
+
+}

+ 38 - 0
src/main/java/com/ym/mec/collectfee/common/sms/BaseRequest.java

@@ -0,0 +1,38 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+public class BaseRequest implements Serializable{
+	
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 请求时间
+	 */
+	private long requestTime = System.currentTimeMillis();
+	
+	/**
+	 * 请求有效时间(秒)<br/>
+	 * 服务器接受时间与请求时间对比,如果超过有效时间,拒绝此次请求<br/>
+	 * 防止被网络抓包不断发送同一条请求<br/>
+	 * 默认1分钟有效期
+	 */
+	private int requestValidPeriod  = 60;
+
+	public long getRequestTime() {
+		return requestTime;
+	}
+	
+	public void setRequestTime(long requestTime) {
+		this.requestTime = requestTime;
+	}
+
+	public int getRequestValidPeriod() {
+		return requestValidPeriod;
+	}
+
+	public void setRequestValidPeriod(int requestValidPeriod) {
+		this.requestValidPeriod = requestValidPeriod;
+	}
+
+}

+ 43 - 0
src/main/java/com/ym/mec/collectfee/common/sms/CustomSmsIdAndMobile.java

@@ -0,0 +1,43 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 自定义SMSID 手机号
+ * @author Frank
+ *
+ */
+public class CustomSmsIdAndMobile implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private String customSmsId;
+	
+	private String mobile;
+	
+	public CustomSmsIdAndMobile(){
+		
+	}
+	
+	public CustomSmsIdAndMobile(String customSmsId, String mobile){
+		this.customSmsId = customSmsId;
+		this.mobile = mobile;
+	}
+
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+}

+ 54 - 0
src/main/java/com/ym/mec/collectfee/common/sms/CustomSmsIdAndMobileAndContent.java

@@ -0,0 +1,54 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 自定义SMSID 手机号 内容
+ * @author Frank
+ *
+ */
+public class CustomSmsIdAndMobileAndContent implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private String customSmsId;
+	
+	private String mobile;
+	
+	private String content;
+
+	public CustomSmsIdAndMobileAndContent(){
+		
+	}
+	
+	public CustomSmsIdAndMobileAndContent(String customSmsId, String mobile, String content){
+		this.customSmsId = customSmsId;
+		this.mobile = mobile;
+		this.content = content;
+	}
+	
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+}

+ 105 - 0
src/main/java/com/ym/mec/collectfee/common/sms/GZIPUtils.java

@@ -0,0 +1,105 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * GZIP 压缩工具
+ * @author Frank
+ *
+ */
+public class GZIPUtils {
+
+	public static void main(String[] args) throws IOException {
+		String sst = "hahahah";
+		System.out.println(sst);
+		System.out.println(System.currentTimeMillis());
+		System.out.println("size:" + sst.length());
+		byte[] bytes = sst.getBytes();
+		System.out.println("length:" + bytes.length);
+		System.out.println(System.currentTimeMillis());
+		byte[] end = compress(bytes);
+		System.out.println(System.currentTimeMillis());
+		System.out.println("length:" + end.length);
+		System.out.println(System.currentTimeMillis());
+		byte[] start = decompress(end);
+		System.out.println(System.currentTimeMillis());
+		System.out.println("length:" + start.length);
+		System.out.println(new String(start));
+	}
+
+	/**
+	 * 数据压缩传输
+	 * 
+	 * @param is
+	 * @param os
+	 * @throws Exception
+	 */
+	public static void compressTransfe(byte[] bytes, OutputStream out) throws IOException {
+		GZIPOutputStream gos = null;
+		try {
+			gos = new GZIPOutputStream(out);
+			gos.write(bytes);
+			gos.finish();
+			gos.flush();
+		} finally{
+			if(gos != null){
+				gos.close();
+			}
+		}
+	}
+	
+	/**
+	 * 数据压缩
+	 * 
+	 * @param is
+	 * @param os
+	 * @throws Exception
+	 */
+	public static byte[] compress(byte[] bytes) throws IOException {
+		ByteArrayOutputStream out = null;
+		GZIPOutputStream gos = null;
+		try {
+			out = new ByteArrayOutputStream();
+			gos = new GZIPOutputStream(out);
+			gos.write(bytes);
+			gos.finish();
+			gos.flush();
+		} finally{
+			if(gos != null){
+				gos.close();
+			}
+			if(out != null){
+				out.close();
+			}
+		}
+		return out.toByteArray();
+	}
+	
+	/**
+	 * 数据解压
+	 * 
+	 * @param in
+	 * @return
+	 * @throws IOException
+	 */
+	public static byte[] decompress(byte[] bytes) throws IOException {
+		ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+		GZIPInputStream gin = new GZIPInputStream(in);
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		int count;
+		byte data[] = new byte[1024];
+		while ((count = gin.read(data, 0, 1024)) != -1) {
+			out.write(data, 0, count);
+		}
+		out.flush();
+		out.close();
+		gin.close();
+		return out.toByteArray();
+	}
+
+}

+ 452 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpClient.java

@@ -0,0 +1,452 @@
+package com.ym.mec.collectfee.common.sms;
+
+import javax.net.ssl.*;
+import java.io.*;
+import java.net.*;
+import java.security.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * EMAY http客户端
+ * 
+ * @author Frank
+ *
+ */
+public class HttpClient {
+
+	/**
+	 * 链接超时时间(s)
+	 */
+	private int httpConnectionTimeOut = 30;
+
+	/**
+	 * 数据传输超时时间(s)
+	 */
+	private int httpReadTimeOut = 30;
+
+	public HttpClient() {
+
+	}
+
+	/**
+	 * 
+	 * @param httpConnectionTimeOut
+	 *            链接超时时间(s)
+	 * @param httpReadTimeOut
+	 *            数据传输超时时间(s)
+	 */
+	public HttpClient(int httpConnectionTimeOut, int httpReadTimeOut) {
+		this.httpConnectionTimeOut = httpConnectionTimeOut;
+		this.httpReadTimeOut = httpReadTimeOut;
+	}
+
+	/**
+	 * 发送HTTP请求
+	 * 
+	 * @param request
+	 *            请求
+	 * @param praser
+	 *            响应解析器
+	 * @return T 响应
+	 */
+	public <T> T service(HttpRequest<?> request, HttpResponsePraser<T> praser) {
+		HttpResultCode code = HttpResultCode.SUCCESS;
+		if (request.getHttpParams().getUrl() == null || request.getHttpParams().getUrl().length() == 0) {
+			code = HttpResultCode.ERROR_URL_NULL;
+			return praser.prase(code, 0, null, null, request.getHttpParams().getCharSet(), null);
+		}
+		HttpURLConnection conn = null;
+		int httpCode = 0;
+		Map<String, String> headers = null;
+		List<String> cookies = null;
+		ByteArrayOutputStream outputStream = null;
+		try {
+			String realUrl = this.genUrl(request);
+			conn = this.createConnection(request, realUrl);
+			this.fillConnection(conn, request);
+			this.request(conn, request);
+			httpCode = conn.getResponseCode();
+			headers = this.getHeaders(conn, request.getHttpParams().getCharSet());
+			cookies = this.getCookies(conn, request.getHttpParams().getCharSet());
+			outputStream = this.getResultOutputStream(conn);
+		} catch (SocketTimeoutException e) {
+			code = HttpResultCode.ERROR_TIMEOUT;
+			e.printStackTrace();
+		} catch (KeyManagementException e) {
+			code = HttpResultCode.ERROR_HTTPS_SSL;
+			e.printStackTrace();
+		} catch (NoSuchAlgorithmException e) {
+			code = HttpResultCode.ERROR_HTTPS_SSL;
+			e.printStackTrace();
+		} catch (ProtocolException e) {
+			code = HttpResultCode.ERROR_METHOD;
+			e.printStackTrace();
+		} catch (UnsupportedEncodingException e) {
+			code = HttpResultCode.ERROR_CHARSET;
+			e.printStackTrace();
+		} catch (MalformedURLException e) {
+			code = HttpResultCode.ERROR_URL;
+			httpCode = 500;
+			e.printStackTrace();
+		} catch (IOException e) {
+			code = HttpResultCode.ERROR_CONNECT;
+			e.printStackTrace();
+		} catch (UnrecoverableKeyException e) {
+			code = HttpResultCode.ERROR_HTTPS_SSL;
+			e.printStackTrace();
+		} catch (KeyStoreException e) {
+			code = HttpResultCode.ERROR_HTTPS_SSL;
+			e.printStackTrace();
+		} catch (CertificateException e) {
+			code = HttpResultCode.ERROR_HTTPS_SSL;
+			e.printStackTrace();
+		} finally {
+			if (conn != null) {
+				conn.disconnect();
+			}
+		}
+		T t = null;
+		try {
+			t = praser.prase(code, httpCode, headers, cookies, request.getHttpParams().getCharSet(), outputStream);
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (outputStream != null) {
+				try {
+					outputStream.flush();
+					outputStream.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return t;
+	}
+
+	private <T> String genUrl(HttpRequest<T> request) {
+		if (request.getHttpParams().getMethod().equalsIgnoreCase("GET")) {
+			String getprams = request.getContentPraser().praseRqeuestContentToString(request.getHttpParams());
+			if (getprams != null) {
+				String url = null;
+				if (request.getHttpParams().getUrl().indexOf("?") > 0) {
+					url = request.getHttpParams().getUrl() + "&" + getprams;
+				} else {
+					url = request.getHttpParams().getUrl() + "?" + getprams;
+				}
+				return url;
+			} else {
+				return request.getHttpParams().getUrl();
+			}
+		} else {
+			return request.getHttpParams().getUrl();
+		}
+	}
+
+	/**
+	 * 获取HTTP响应头
+	 * 
+	 * @param conn
+	 * @param charSet
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	private Map<String, String> getHeaders(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
+		Map<String, String> resultHeaders = new HashMap<String, String>();
+		Map<String, List<String>> header = conn.getHeaderFields();
+		if (header != null && header.size() > 0) {
+			for (Entry<String, List<String>> entry : header.entrySet()) {
+				if (!"Set-Cookie".equalsIgnoreCase(entry.getKey())) {
+					String valuer = "";
+					if (entry.getValue() != null && entry.getValue().size() > 0) {
+						for (String value : entry.getValue()) {
+							valuer += new String(value.getBytes("ISO-8859-1"), charSet) + ",";
+						}
+						valuer = valuer.substring(0, valuer.length() - 1);
+					}
+					resultHeaders.put(entry.getKey(), valuer);
+				}
+			}
+		}
+		return resultHeaders;
+	}
+
+	/**
+	 * 获取HTTP响应Cookies
+	 * 
+	 * @param conn
+	 * @param charSet
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	private List<String> getCookies(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
+		List<String> resultC = new ArrayList<String>();
+		List<String> cookies = null;
+		Map<String, List<String>> header = conn.getHeaderFields();
+		if (header != null && header.size() > 0) {
+			cookies = header.get("Set-Cookie");
+		}
+		if (cookies != null) {
+			for (String cookie : cookies) {
+				resultC.add(new String(cookie.getBytes("ISO-8859-1"), charSet));
+			}
+		}
+		return cookies;
+	}
+
+	/**
+	 * 获取HTTP响应数据流
+	 * 
+	 * @param conn
+	 * @return
+	 * @throws IOException
+	 */
+	private ByteArrayOutputStream getResultOutputStream(HttpURLConnection conn) throws IOException {
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		InputStream is = conn.getInputStream();
+		try {
+			if (is != null) {
+				byte[] buffer = new byte[1024];
+				int len = 0;
+				while ((len = is.read(buffer)) != -1) {
+					outStream.write(buffer, 0, len);
+				}
+			}
+		} catch (IOException e) {
+			throw e;
+		} finally {
+			if (is != null) {
+				is.close();
+			}
+		}
+		return outStream;
+	}
+
+	/**
+	 * 发送Http请求
+	 * 
+	 * @param conn
+	 * @param request
+	 * @throws IOException
+	 */
+	private <T> void request(HttpURLConnection conn, HttpRequest<T> request) throws IOException {
+		if (request.getHttpParams().getMethod().equalsIgnoreCase("POST")) {
+			conn.setDoOutput(true);
+			// conn.connect();
+			if (request.getHttpParams().getParams() != null) {
+				byte[] content = request.getContentPraser().praseRqeuestContentToBytes(request.getHttpParams());
+				fillHeader(conn, "Content-Length", String.valueOf(request.getContentPraser().praseRqeuestContentLength(request.getHttpParams())));
+				DataOutputStream out = new DataOutputStream(conn.getOutputStream());
+				out.write(content);
+				out.flush();
+				out.close();
+			}
+		} else {
+			conn.connect();
+		}
+	}
+
+	/**
+	 * 添加请求信息
+	 * 
+	 * @param conn
+	 * @param request
+	 * @throws ProtocolException
+	 */
+	private void fillConnection(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
+		this.fillTimeout(conn);
+		this.filleMethod(conn, request);
+		this.fillHeaders(conn, request);
+		this.fillCookies(conn, request);
+	}
+
+	/**
+	 * 添加超时时间
+	 * 
+	 * @param conn
+	 */
+	private void fillTimeout(HttpURLConnection conn) {
+		if (httpConnectionTimeOut != 0) {
+			conn.setConnectTimeout(httpConnectionTimeOut * 1000);
+		}
+		if (httpReadTimeOut != 0) {
+			conn.setReadTimeout(httpReadTimeOut * 1000);
+		}
+	}
+
+	/**
+	 * 指定HTTP方法
+	 * 
+	 * @param conn
+	 * @param request
+	 * @throws ProtocolException
+	 */
+	private void filleMethod(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
+		conn.setRequestMethod(request.getHttpParams().getMethod().toUpperCase());
+	}
+
+	/**
+	 * 添加头信息
+	 * 
+	 * @param conn
+	 * @param request
+	 */
+	private void fillHeaders(HttpURLConnection conn, HttpRequest<?> request) {
+		if (request.getHttpParams().getHeaders() != null) {
+			for (Entry<String, String> entry : request.getHttpParams().getHeaders().entrySet()) {
+				fillHeader(conn, entry.getKey(), entry.getValue());
+			}
+		}
+	}
+
+	/**
+	 * 添加头信息
+	 * 
+	 * @param conn
+	 * @param request
+	 */
+	private void fillHeader(HttpURLConnection conn, String key, String value) {
+		conn.setRequestProperty(key, value);
+	}
+
+	/**
+	 * 添加Cookies
+	 * 
+	 * @param conn
+	 * @param request
+	 */
+	private void fillCookies(HttpURLConnection conn, HttpRequest<?> request) {
+		if (request.getHttpParams().getCookies() != null) {
+			conn.setRequestProperty("Cookie", request.getHttpParams().getCookies());
+		}
+	}
+
+	/**
+	 * 创建Http链接
+	 * 
+	 * @param request
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws KeyManagementException
+	 * @throws MalformedURLException
+	 * @throws IOException
+	 * @throws CertificateException
+	 * @throws KeyStoreException
+	 * @throws UnrecoverableKeyException
+	 */
+	private HttpURLConnection createConnection(HttpRequest<?> request, String realUrl)
+			throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, IOException, UnrecoverableKeyException, KeyStoreException, CertificateException {
+		URL console = new URL(realUrl);
+		HttpURLConnection conn;
+		if (request.isHttps()) {
+			conn = genHttpsConn(console, request);
+		} else {
+			conn = (HttpURLConnection) console.openConnection();
+		}
+		return conn;
+	}
+
+	private HttpURLConnection genHttpsConn(URL console, HttpRequest<?> request)
+			throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+		SSLContext ctx = getSSLContext(request.getHttpsParams());
+		HttpsURLConnection sconn = (HttpsURLConnection) console.openConnection();
+		sconn.setSSLSocketFactory(ctx.getSocketFactory());
+		sconn.setHostnameVerifier(new HostnameVerifier() {
+			public boolean verify(String hostname, SSLSession session) {
+				return true;
+			}
+		});
+		return sconn;
+	}
+
+	/**
+	 * 获得KeyStore.
+	 * 
+	 * @param keyStorePath
+	 *            密钥库路径
+	 * @param password
+	 *            密码
+	 * @return 密钥库
+	 * @throws KeyStoreException
+	 * @throws IOException
+	 * @throws CertificateException
+	 * @throws NoSuchAlgorithmException
+	 * @throws Exception
+	 */
+	private KeyStore getKeyStore(HttpsParams params) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
+		// 实例化密钥库 KeyStore用于存放证书,创建对象时 指定交换数字证书的加密标准
+		// 指定交换数字证书的加密标准
+		KeyStore ks = KeyStore.getInstance(params.getAlgorithm());
+		// 获得密钥库文件流
+		FileInputStream is = new FileInputStream(params.getKeyStorePath());
+		// 加载密钥库
+		ks.load(is, params.getPassword().toCharArray());
+		// 关闭密钥库文件流
+		is.close();
+		return ks;
+	}
+
+	/**
+	 * 获得SSLSocketFactory.
+	 * 
+	 * @param password
+	 *            密码
+	 * @param keyStorePath
+	 *            密钥库路径
+	 * @param trustStorePath
+	 *            信任库路径
+	 * @return SSLSocketFactory
+	 * @throws NoSuchAlgorithmException
+	 * @throws IOException
+	 * @throws CertificateException
+	 * @throws KeyStoreException
+	 * @throws UnrecoverableKeyException
+	 * @throws KeyManagementException
+	 * @throws Exception
+	 */
+	private SSLContext getSSLContext(HttpsParams params) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
+		// 实例化SSL上下文
+		SSLContext ctx = SSLContext.getInstance("TLS");
+		if (params != null) {
+			// 实例化密钥库 KeyManager选择证书证明自己的身份
+			KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+			// 实例化信任库 TrustManager决定是否信任对方的证书
+			TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+			// 获得密钥库
+			KeyStore keyStore = getKeyStore(params);
+			// 初始化密钥工厂
+			keyManagerFactory.init(keyStore, params.getPassword().toCharArray());
+			// 获得信任库
+			KeyStore trustStore = getKeyStore(params);
+			// 初始化信任库
+			trustManagerFactory.init(trustStore);
+			// 初始化SSL上下文
+			ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
+		} else {
+			ctx.init(null, new TrustManager[] { myX509TrustManager }, new java.security.SecureRandom());
+		}
+		return ctx;
+	}
+
+	private TrustManager myX509TrustManager = new X509TrustManager() {
+
+		@Override
+		public X509Certificate[] getAcceptedIssuers() {
+			return null;
+		}
+
+		@Override
+		public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+		}
+
+		@Override
+		public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+		}
+	};
+
+}

+ 96 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpRequest.java

@@ -0,0 +1,96 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * Http 请求实体<请求数据类型>
+ * 
+ * @author Frank
+ *
+ * @param <T>
+ */
+public class HttpRequest<T> {
+
+	/**
+	 * http参数
+	 */
+	private HttpRequestParams<T> httpParams;
+
+	/**
+	 * https参数
+	 */
+	private HttpsParams httpsParams;
+
+	/**
+	 * 内容解析器
+	 */
+	private HttpRequestPraser<T> contentPraser;
+
+	/**
+	 * 是否https请求
+	 */
+	private boolean isHttps;
+
+	/**
+	 * 
+	 */
+	protected HttpRequest() {
+
+	}
+
+	/**
+	 * 
+	 * @param httpParams
+	 *            http参数
+	 * @param contentPraser
+	 *            内容解析器
+	 */
+	protected HttpRequest(HttpRequestParams<T> httpParams, HttpRequestPraser<T> contentPraser) {
+		this.httpParams = httpParams;
+		this.contentPraser = contentPraser;
+		this.isHttps = false;
+	}
+
+	/**
+	 * 
+	 * @param httpParams
+	 *            http参数
+	 * @param httpsParams
+	 *            https参数
+	 * @param contentPraser
+	 *            内容解析器
+	 */
+	protected HttpRequest(HttpRequestParams<T> httpParams, HttpsParams httpsParams, HttpRequestPraser<T> contentPraser) {
+		this.httpParams = httpParams;
+		this.httpsParams = httpsParams;
+		this.contentPraser = contentPraser;
+		this.isHttps = true;
+	}
+
+	public boolean isHttps() {
+		return isHttps;
+	}
+
+	public HttpRequestParams<T> getHttpParams() {
+		return httpParams;
+	}
+
+	public void setHttpParams(HttpRequestParams<T> httpParams) {
+		this.httpParams = httpParams;
+	}
+
+	public HttpsParams getHttpsParams() {
+		return httpsParams;
+	}
+
+	public void setHttpsParams(HttpsParams httpsParams) {
+		this.httpsParams = httpsParams;
+	}
+
+	public HttpRequestPraser<T> getContentPraser() {
+		return contentPraser;
+	}
+
+	public void setContentPraser(HttpRequestPraser<T> contentPraser) {
+		this.contentPraser = contentPraser;
+	}
+
+}

+ 20 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestBytes.java

@@ -0,0 +1,20 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * Http 请求实体<byte[]>
+ * 
+ * @author Frank
+ *
+ */
+public class HttpRequestBytes extends HttpRequest<byte[]> {
+
+	/**
+	 * 
+	 * @param httpParams
+	 *            请求参数
+	 */
+	public HttpRequestBytes(HttpRequestParams<byte[]> httpParams) {
+		super(httpParams, new HttpRequestPraserBytes());
+	}
+
+}

+ 70 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestParams.java

@@ -0,0 +1,70 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.util.Map;
+
+/**
+ * Http参数
+ * 
+ * @author Frank
+ *
+ * @param <T>
+ *            传输数据类型
+ */
+public class HttpRequestParams<T> {
+
+	private String url;// URL
+	private String charSet = "UTF-8";// 编码
+	private String method = "GET";// Http方法
+	private Map<String, String> headers;// 头信息
+	private String cookies;// cookie信息
+	private T params;// 传输数据
+
+	public String getUrl() {
+		return url;
+	}
+
+	public void setUrl(String url) {
+		this.url = url;
+	}
+
+	public String getCharSet() {
+		return charSet;
+	}
+
+	public void setCharSet(String charSet) {
+		this.charSet = charSet;
+	}
+
+	public String getMethod() {
+		return method;
+	}
+
+	public void setMethod(String method) {
+		this.method = method;
+	}
+
+	public Map<String, String> getHeaders() {
+		return headers;
+	}
+
+	public void setHeaders(Map<String, String> headers) {
+		this.headers = headers;
+	}
+
+	public String getCookies() {
+		return cookies;
+	}
+
+	public void setCookies(String cookies) {
+		this.cookies = cookies;
+	}
+
+	public T getParams() {
+		return params;
+	}
+
+	public void setParams(T params) {
+		this.params = params;
+	}
+
+}

+ 42 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestPraser.java

@@ -0,0 +1,42 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * Http请求,参数解析器
+ * 
+ * @author Frank
+ *
+ * @param <T>
+ */
+public interface HttpRequestPraser<T> {
+
+	/**
+	 * 将请求参数转换为String<br/>
+	 * 主要用于get方法传输
+	 * 
+	 * @param httpParams
+	 *            请求参数
+	 * @return
+	 */
+	public String praseRqeuestContentToString(HttpRequestParams<T> httpParams);
+
+	/**
+	 * 将请求参数转换为byte[]<br/>
+	 * 主要用于post方法传输
+	 * 
+	 * @param httpParams
+	 *            请求参数
+	 * @return
+	 */
+	public byte[] praseRqeuestContentToBytes(HttpRequestParams<T> httpParams);
+
+	/**
+	 * 获取请求参数大小<br/>
+	 * 主要用于post方法传输
+	 * 
+	 * @param httpParams
+	 *            请求参数
+	 * @return
+	 */
+	public int praseRqeuestContentLength(HttpRequestParams<T> httpParams);
+
+}

+ 45 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpRequestPraserBytes.java

@@ -0,0 +1,45 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Http 请求解析器:byte[]
+ * 
+ * @author Frank
+ *
+ */
+public class HttpRequestPraserBytes implements HttpRequestPraser<byte[]> {
+
+	/**
+	 * 请求内容字符串
+	 */
+	private String contentString;
+
+	@Override
+	public String praseRqeuestContentToString(HttpRequestParams<byte[]> httpParams) {
+		if (contentString != null) {
+			return contentString;
+		}
+		try {
+			contentString = new String(httpParams.getParams(), httpParams.getCharSet());
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		return contentString;
+	}
+
+	@Override
+	public byte[] praseRqeuestContentToBytes(HttpRequestParams<byte[]> httpParams) {
+		return httpParams.getParams();
+	}
+
+	@Override
+	public int praseRqeuestContentLength(HttpRequestParams<byte[]> httpParams) {
+		if (httpParams.getParams() != null) {
+			return httpParams.getParams().length;
+		} else {
+			return 0;
+		}
+	}
+
+}

+ 114 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpResponse.java

@@ -0,0 +1,114 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Http响应
+ * 
+ * @author Frank
+ *
+ */
+public class HttpResponse<T> {
+
+	/**
+	 * Http 结果代码
+	 */
+	private HttpResultCode resultCode;
+
+	/**
+	 * Http链接Code
+	 */
+	private int httpCode;
+
+	/**
+	 * Http响应头
+	 */
+	private Map<String, String> headers;
+
+	/**
+	 * http响应Cookies
+	 */
+	private List<String> cookies;
+	/**
+	 * http字符集
+	 */
+	private String charSet;
+	/**
+	 * http响应数据
+	 */
+	private T result;
+
+	/**
+	 * 
+	 * @param resultCode
+	 *            Http 结果代码
+	 * @param httpCode
+	 *            Http链接Code
+	 * @param headers
+	 *            Http响应头
+	 * @param cookies
+	 *            http响应Cookies
+	 * @param charSet
+	 *            http字符集
+	 * @param result
+	 *            http响应数据
+	 */
+	public HttpResponse(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, T result) {
+		this.resultCode = resultCode;
+		this.httpCode = httpCode;
+		this.headers = headers;
+		this.cookies = cookies;
+		this.charSet = charSet;
+		this.result = result;
+	}
+
+	public HttpResultCode getResultCode() {
+		return resultCode;
+	}
+
+	public void setResultCode(HttpResultCode resultCode) {
+		this.resultCode = resultCode;
+	}
+
+	public int getHttpCode() {
+		return httpCode;
+	}
+
+	public void setHttpCode(int httpCode) {
+		this.httpCode = httpCode;
+	}
+
+	public Map<String, String> getHeaders() {
+		return headers;
+	}
+
+	public void setHeaders(Map<String, String> headers) {
+		this.headers = headers;
+	}
+
+	public List<String> getCookies() {
+		return cookies;
+	}
+
+	public void setCookies(List<String> cookies) {
+		this.cookies = cookies;
+	}
+
+	public String getCharSet() {
+		return charSet;
+	}
+
+	public void setCharSet(String charSet) {
+		this.charSet = charSet;
+	}
+
+	public T getResult() {
+		return result;
+	}
+
+	public void setResult(T result) {
+		this.result = result;
+	}
+
+}

+ 33 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpResponseBytes.java

@@ -0,0 +1,33 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * http 响应: byte[]
+ * 
+ * @author Frank
+ *
+ */
+public class HttpResponseBytes extends HttpResponse<byte[]> {
+
+	/**
+	 * 
+	 * @param resultCode
+	 *            Http 结果代码
+	 * @param httpCode
+	 *            Http链接Code
+	 * @param headers
+	 *            Http响应头
+	 * @param cookies
+	 *            http响应Cookies
+	 * @param charSet
+	 *            http字符集
+	 * @param result
+	 *            http响应数据
+	 */
+	public HttpResponseBytes(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, byte[] result) {
+		super(resultCode, httpCode, headers, cookies, charSet, result);
+	}
+
+}

+ 20 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpResponseBytesPraser.java

@@ -0,0 +1,20 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 解析Byte[]响应的解析器
+ * 
+ * @author Frank
+ *
+ */
+public class HttpResponseBytesPraser implements HttpResponsePraser<HttpResponseBytes> {
+
+	@Override
+	public HttpResponseBytes prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream) {
+		return new HttpResponseBytes(resultCode, httpCode, headers, cookies, charSet, outputStream == null ? null : outputStream.toByteArray());
+	}
+
+}

+ 36 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpResponsePraser.java

@@ -0,0 +1,36 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 
+ * Http响应解析器
+ * 
+ * @author Frank
+ *
+ * @param <T>
+ *            http响应数据转换后实体
+ */
+public interface HttpResponsePraser<T> {
+
+	/**
+	 * 解析
+	 * 
+	 * @param resultCode
+	 *            Http 结果代码
+	 * @param httpCode
+	 *            Http链接Code
+	 * @param headers
+	 *            Http响应头
+	 * @param cookies
+	 *            http响应Cookies
+	 * @param charSet
+	 *            http字符集
+	 * @param result
+	 *            http响应数据
+	 */
+	public T prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream);
+
+}

+ 70 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpResultCode.java

@@ -0,0 +1,70 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * HTTP 访问结果编码
+ * 
+ * @author Frank
+ *
+ */
+public enum HttpResultCode {
+
+	SUCCESS("成功", "SUCCESS"), //
+	ERROR_URL_NULL("URL为空", "ERROR-URL-NULL"), //
+	ERROR_URL("URL访问失败", "ERROR-URL"), //
+	ERROR_HTTPS_SSL("HTTPS异常", "ERROR-HTTPS-SSL"), //
+	ERROR_METHOD("HTTP方法无法识别", "ERROR-METHOD"), //
+	ERROR_CHARSET("编码错误", "ERROR-CHARSET"), //
+	ERROR_CONNECT("访问失败", "ERROR-CONNECT"), //
+	ERROR_TIMEOUT("访问超时", "ERROR-TIMEOUT"), //
+
+	;
+
+	/**
+	 * 名称
+	 */
+	private String name;
+	/**
+	 * 编码
+	 */
+	private String code;
+
+	private HttpResultCode(String name, String code) {
+		this.name = name;
+		this.code = code;
+	}
+
+	public static String findNameByCode(String code) {
+		for (HttpResultCode oc : HttpResultCode.values()) {
+			if (oc.getCode().equals(code)) {
+				return oc.getName();
+			}
+		}
+		return null;
+	}
+
+	public static String findCodeByName(String name) {
+		for (HttpResultCode oc : HttpResultCode.values()) {
+			if (oc.getName().equals(name)) {
+				return oc.getCode();
+			}
+		}
+		return null;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+}

+ 48 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpsParams.java

@@ -0,0 +1,48 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * https 参数
+ * 
+ * @author Frank
+ *
+ */
+public class HttpsParams {
+
+	private String password;// 密钥库密钥
+	private String keyStorePath;// 密钥库文件地址
+	private String trustStorePath;// 信任库文件地址
+	private String algorithm;// 指定交换数字证书的加密标准:JKS
+
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+	public String getKeyStorePath() {
+		return keyStorePath;
+	}
+
+	public void setKeyStorePath(String keyStorePath) {
+		this.keyStorePath = keyStorePath;
+	}
+
+	public String getTrustStorePath() {
+		return trustStorePath;
+	}
+
+	public void setTrustStorePath(String trustStorePath) {
+		this.trustStorePath = trustStorePath;
+	}
+
+	public String getAlgorithm() {
+		return algorithm;
+	}
+
+	public void setAlgorithm(String algorithm) {
+		this.algorithm = algorithm;
+	}
+
+}

+ 22 - 0
src/main/java/com/ym/mec/collectfee/common/sms/HttpsRequestBytes.java

@@ -0,0 +1,22 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * Https 请求实体<byte[]>
+ * 
+ * @author Frank
+ *
+ */
+public class HttpsRequestBytes extends HttpRequest<byte[]> {
+
+	/**
+	 * 
+	 * @param httpParams
+	 *            http请求参数
+	 * @param httpsParams
+	 *            https参数
+	 */
+	public HttpsRequestBytes(HttpRequestParams<byte[]> httpParams, HttpsParams httpsParams) {
+		super(httpParams, httpsParams, new HttpRequestPraserBytes());
+	}
+
+}

+ 130 - 0
src/main/java/com/ym/mec/collectfee/common/sms/JsonHelper.java

@@ -0,0 +1,130 @@
+package com.ym.mec.collectfee.common.sms;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * json util 
+ * 
+ * @author 东旭
+ *
+ */
+public class JsonHelper {
+
+	private static Map<String,Gson> gsons = new HashMap<String, Gson>();
+
+	private static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
+	
+	static {
+		gsons.put(DEFAULT_DATE_PATTERN, createGson(DEFAULT_DATE_PATTERN));
+	}
+	
+	private static Gson createGson(String datePattern){
+		return  new GsonBuilder().setDateFormat(datePattern).disableHtmlEscaping().serializeNulls().create();
+	}
+	
+	public static Gson getGson() {
+		return gsons.get(DEFAULT_DATE_PATTERN);
+	}
+
+	public static Gson getGson(String datePattern) {
+		Gson gson = gsons.get(datePattern);
+		if(gson == null){
+			gson = createGson(datePattern);
+			gsons.put(datePattern, gson);
+		}
+		return gson;
+	}
+	
+	public static GsonBuilder newGsonBuilder() {
+		return new GsonBuilder();
+	}
+
+	/**
+	 * 将对象转换为json串
+	 * 
+	 * @param obj
+	 * @return
+	 */
+	public static String toJsonString(Object obj) {
+		if (obj == null) {
+			return null;
+		}
+		return getGson().toJson(obj);
+	}
+
+	/**
+	 * 将对象转换为json串,自定义日期转换规则
+	 * 
+	 * @param obj
+	 * @param datePattern
+	 * @return
+	 */
+	public static String toJsonString(Object obj, String datePattern) {
+		if (obj == null) {
+			return null;
+		}
+		return getGson(datePattern).toJson(obj);
+	}
+
+	/**
+	 * 将json串转换为对象
+	 * 
+	 * @param clazz
+	 * @param jsonString
+	 * @return
+	 */
+	public static <T> T fromJson(Class<T> clazz, String jsonString) {
+		if (jsonString == null) {
+			return null;
+		}
+		return getGson().fromJson(jsonString, clazz);
+	}
+	
+	/**
+	 * 将json串转换为对象
+	 * 
+	 * @Type type
+	 * @param jsonString
+	 * @return
+	 */
+	public static <T> T fromJson(TypeToken<T> token, String jsonString) {
+		if (jsonString == null) {
+			return null;
+		}
+		return getGson().fromJson(jsonString, token.getType());
+	}
+	
+	/**
+	 * 将json串转换为对象
+	 * 
+	 * @Type type
+	 * @param jsonString
+	 * @return
+	 */
+	public static <T> T fromJson(TypeToken<T> token, String jsonString, String datePattern) {
+		if (jsonString == null) {
+			return null;
+		}
+		return getGson(datePattern).fromJson(jsonString, token.getType());
+	}
+
+	/**
+	 * 将json串转换为对象
+	 * 
+	 * @param clazz
+	 * @param jsonString
+	 * @return
+	 */
+	public static <T> T fromJson(Class<T> clazz, String jsonString, String datePattern) {
+		if (jsonString == null) {
+			return null;
+		}
+		return getGson(datePattern).fromJson(jsonString, clazz);
+	}
+
+}

+ 32 - 0
src/main/java/com/ym/mec/collectfee/common/sms/MoRequest.java

@@ -0,0 +1,32 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 请求Balance参数
+ * @author Frank
+ *
+ */
+public class MoRequest extends BaseRequest {
+	
+	private static final long serialVersionUID = 1L;
+	
+	/**
+	 * 请求数量<br/>
+	 * 最大500
+	 */
+	private int number = 500;
+
+	public int getNumber() {
+		if(number <= 0 || number > 500){
+			number = 500;
+		}
+		return number;
+	}
+
+	public void setNumber(int number) {
+		if(number > 500){
+			number = 500;
+		}
+		this.number = number;
+	}
+
+}

+ 65 - 0
src/main/java/com/ym/mec/collectfee/common/sms/MoResponse.java

@@ -0,0 +1,65 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 上行数据
+ * @author Frank
+ *
+ */
+public class MoResponse implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private String mobile;// 手机号
+
+	private String extendedCode; // 扩展码
+
+	private String content;// 内容
+
+	private String moTime;// 手机上行时间
+	
+	public MoResponse(){
+		
+	}
+	
+	public MoResponse(String mobile, String extendedCode, String content, String moTime){
+		this.mobile = mobile;
+		this.extendedCode = extendedCode;
+		this.content = content;
+		this.moTime = moTime;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getExtendedCode() {
+		return extendedCode;
+	}
+
+	public void setExtendedCode(String extendedCode) {
+		this.extendedCode = extendedCode;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public String getMoTime() {
+		return moTime;
+	}
+
+	public void setMoTime(String moTime) {
+		this.moTime = moTime;
+	}
+
+}

+ 76 - 0
src/main/java/com/ym/mec/collectfee/common/sms/PersonalityParams.java

@@ -0,0 +1,76 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 自定义SMSID 手机号 内容
+ * @author Frank
+ *
+ */
+public class PersonalityParams implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+	
+	private String customSmsId;
+	
+	private String mobile;
+	
+	private String content;
+	
+	private String extendedCode;
+	
+	private String timerTime;
+
+	public PersonalityParams(){
+		
+	}
+	
+	public PersonalityParams(String customSmsId, String mobile, String content, String extendedCode, String timerTime){
+		this.customSmsId = customSmsId;
+		this.mobile = mobile;
+		this.content = content;
+		this.timerTime = timerTime;
+		this.extendedCode = extendedCode;
+	}
+	
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public String getExtendedCode() {
+		return extendedCode;
+	}
+
+	public void setExtendedCode(String extendedCode) {
+		this.extendedCode = extendedCode;
+	}
+
+	public String getTimerTime() {
+		return timerTime;
+	}
+
+	public void setTimerTime(String timerTime) {
+		this.timerTime = timerTime;
+	}
+
+}

+ 32 - 0
src/main/java/com/ym/mec/collectfee/common/sms/ReportRequest.java

@@ -0,0 +1,32 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 请求Balance参数
+ * @author Frank
+ *
+ */
+public class ReportRequest extends BaseRequest {
+	
+	private static final long serialVersionUID = 1L;
+	
+	/**
+	 * 请求数量<br/>
+	 * 最大500
+	 */
+	private int number = 500;
+
+	public int getNumber() {
+		if(number <= 0 || number > 500){
+			number = 500;
+		}
+		return number;
+	}
+
+	public void setNumber(int number) {
+		if(number > 500){
+			number = 500;
+		}
+		this.number = number;
+	}
+
+}

+ 94 - 0
src/main/java/com/ym/mec/collectfee/common/sms/ReportResponse.java

@@ -0,0 +1,94 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 状态报告数据
+ * @author Frank
+ *
+ */
+public class ReportResponse implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private String smsId;// 短信唯一标识
+
+	private String customSmsId;// 客户自定义SmsId 
+
+	private String state;// 成功失败标识
+
+	private String desc;// 状态报告描述
+
+	private String mobile;// 手机号
+
+	private String receiveTime;// 状态报告返回时间
+
+	private String submitTime;// 信息提交时间
+
+	private String extendedCode;// 扩展码
+
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+	public String getState() {
+		return state;
+	}
+
+	public void setState(String state) {
+		this.state = state;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getReceiveTime() {
+		return receiveTime;
+	}
+
+	public void setReceiveTime(String receiveTime) {
+		this.receiveTime = receiveTime;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+
+	public void setDesc(String desc) {
+		this.desc = desc;
+	}
+
+	public String getSmsId() {
+		return smsId;
+	}
+
+	public void setSmsId(String smsId) {
+		this.smsId = smsId;
+	}
+
+	public String getSubmitTime() {
+		return submitTime;
+	}
+
+	public void setSubmitTime(String submitTime) {
+		this.submitTime = submitTime;
+	}
+
+	public String getExtendedCode() {
+		return extendedCode;
+	}
+
+	public void setExtendedCode(String extendedCode) {
+		this.extendedCode = extendedCode;
+	}
+
+}

+ 29 - 0
src/main/java/com/ym/mec/collectfee/common/sms/ResultModel.java

@@ -0,0 +1,29 @@
+package com.ym.mec.collectfee.common.sms;
+
+public class ResultModel {
+
+	private String code;
+	private String result;
+
+	public ResultModel(String code, String result) {
+		this.code = code;
+		this.result = result;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getResult() {
+		return result;
+	}
+
+	public void setResult(String result) {
+		this.result = result;
+	}
+
+}

+ 35 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsBaseRequest.java

@@ -0,0 +1,35 @@
+package com.ym.mec.collectfee.common.sms;
+
+
+public class SmsBaseRequest extends BaseRequest {
+	
+	private static final long serialVersionUID = 1L;
+	
+	/**
+	 * 定时时间
+	 * yyyy-MM-dd HH:mm:ss
+	 */
+	private String timerTime;
+	
+	/**
+	 * 扩展码
+	 */
+	private String extendedCode;
+
+	public String getTimerTime() {
+		return timerTime;
+	}
+
+	public void setTimerTime(String timerTime) {
+		this.timerTime = timerTime;
+	}
+
+	public String getExtendedCode() {
+		return extendedCode;
+	}
+
+	public void setExtendedCode(String extendedCode) {
+		this.extendedCode = extendedCode;
+	}
+
+}

+ 40 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsBatchOnlyRequest.java

@@ -0,0 +1,40 @@
+package com.ym.mec.collectfee.common.sms;
+
+
+
+/**
+ * 批量短信发送参数
+ * @author Frank
+ *
+ */
+public class SmsBatchOnlyRequest extends SmsBaseRequest {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 手机号与自定义SmsId
+	 */
+	private String[] mobiles;
+	
+	/**
+	 * 短信内容
+	 */
+	private String content;
+	
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public String[] getMobiles() {
+		return mobiles;
+	}
+
+	public void setMobiles(String[] mobiles) {
+		this.mobiles = mobiles;
+	}
+
+}

+ 38 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsBatchRequest.java

@@ -0,0 +1,38 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 批量短信发送参数
+ * @author Frank
+ *
+ */
+public class SmsBatchRequest extends SmsBaseRequest {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 手机号与自定义SmsId
+	 */
+	private CustomSmsIdAndMobile[] smses;
+	
+	/**
+	 * 短信内容
+	 */
+	private String content;
+	
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public CustomSmsIdAndMobile[] getSmses() {
+		return smses;
+	}
+
+	public void setSmses(CustomSmsIdAndMobile[] smses) {
+		this.smses = smses;
+	}
+
+}

+ 318 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsExample.java

@@ -0,0 +1,318 @@
+package com.ym.mec.collectfee.common.sms;
+
+import org.springframework.beans.factory.annotation.Value;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SmsExample {
+
+    @Value("${com.properties.sms-appId}")
+    private String appId;
+    @Value("${com.properties.sms-secretKey}")
+    private String secretKey;
+    @Value("${com.properties.sms-host-dev}")
+    private String host;
+    // 加密算法
+    private static String algorithm = "AES/ECB/PKCS5Padding";
+    // 编码
+    static String encode = "UTF-8";
+    // 是否压缩
+    static boolean isGizp = true;
+
+	public static void main(String[] args) {
+		// appId
+		String appId = "EUCP-EMY-SMS1-11111";// 请联系销售,或者在页面中 获取
+		// 密钥
+		String secretKey = "1111111111111111";// 请联系销售,或者在页面中 获取
+		// 接口地址
+		String host = "http://emay.com";// 请联系销售获取
+		// 加密算法
+		String algorithm = "AES/ECB/PKCS5Padding";
+		// 编码
+		String encode = "UTF-8";
+		// 是否压缩
+		boolean isGizp = true;
+
+		// 获取余额
+		getBalance(appId, secretKey, host, algorithm, isGizp, encode);
+		// 获取状态报告
+		getReport(appId, secretKey, host, algorithm, isGizp, encode);
+		// 获取上行
+		getMo(appId, secretKey, host, algorithm, isGizp, encode);
+		// 发送单条短信
+		setSingleSms(appId, secretKey, host, algorithm, "【某某公司】您的验证码是123", null, null, "12100000000", isGizp, encode);//短信内容请以商务约定的为准,如果已经在通道端绑定了签名,则无需在这里添加签名
+		// // 发送批次短信[有自定义SMSID]
+		setBatchSms(appId, secretKey, host, algorithm, "【某某公司】您的验证码是123", null,
+				new CustomSmsIdAndMobile[] { new CustomSmsIdAndMobile("1", "12100000000"), new CustomSmsIdAndMobile("2", "12100000000") }, isGizp, encode);
+		// // 发送批次短信[无自定义SMSID]
+		setBatchOnlySms(appId, secretKey, host, algorithm, "【某某公司】您的验证码是123", null, new String[] { "12100000000", "12100000001" }, isGizp, encode);
+		// // 发送个性短信
+		setPersonalitySms(appId, secretKey, host, algorithm, null, new CustomSmsIdAndMobileAndContent[] { new CustomSmsIdAndMobileAndContent("1", "12100000000", "【某某公司】您的验证码是123"),
+				new CustomSmsIdAndMobileAndContent("2", "12100000001", "【某某公司】您的验证码是123") }, isGizp, encode);
+		// // 发送全个性短信
+		setPersonalityAllSms(appId, secretKey, host, algorithm, new PersonalityParams[] { new PersonalityParams("101", "12100000000", "【天气不错0", "01", null),
+				new PersonalityParams("102", "12100000001", "天气不错1", "02", null) }, isGizp, encode);
+	}
+
+
+    /**
+     * 获取余额
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void getBalance(String appId, String secretKey, String host, String algorithm, boolean isGzip, String encode) {
+        System.out.println("=============begin getBalance==================");
+        BalanceRequest pamars = new BalanceRequest();
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/getBalance", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            BalanceResponse response = JsonHelper.fromJson(BalanceResponse.class, result.getResult());
+            if (response != null) {
+                System.out.println("result data : " + response.getBalance());
+            }
+        }
+        System.out.println("=============end getBalance==================");
+    }
+
+    /**
+     * 获取状态报告
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void getReport(String appId, String secretKey, String host, String algorithm, boolean isGzip, String encode) {
+        System.out.println("=============begin getReport==================");
+        ReportRequest pamars = new ReportRequest();
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/getReport", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            ReportResponse[] response = JsonHelper.fromJson(ReportResponse[].class, result.getResult());
+            if (response != null) {
+                for (ReportResponse d : response) {
+                    System.out.println("result data : " + d.getExtendedCode() + "," + d.getMobile() + "," + d.getCustomSmsId() + "," + d.getSmsId() + "," + d.getState() + "," + d.getDesc() + ","
+                            + d.getSubmitTime() + "," + d.getReceiveTime());
+                }
+            }
+        }
+        System.out.println("=============end getReport==================");
+    }
+
+    /**
+     * 获取上行
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void getMo(String appId, String secretKey, String host, String algorithm, boolean isGzip, String encode) {
+        System.out.println("=============begin getMo==================");
+        MoRequest pamars = new MoRequest();
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/getMo", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            MoResponse[] response = JsonHelper.fromJson(MoResponse[].class, result.getResult());
+            if (response != null) {
+                for (MoResponse d : response) {
+                    System.out.println("result data:" + d.getContent() + "," + d.getExtendedCode() + "," + d.getMobile() + "," + d.getMoTime());
+                }
+            }
+        }
+        System.out.println("=============end getMo==================");
+    }
+
+    /**
+     * 发送单条短信
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void setSingleSms(String appId, String secretKey, String host, String algorithm, String content, String customSmsId, String extendCode, String mobile, boolean isGzip, String encode) {
+        System.out.println("=============begin setSingleSms==================");
+        SmsSingleRequest pamars = new SmsSingleRequest();
+        pamars.setContent(content);
+        pamars.setCustomSmsId(customSmsId);
+        pamars.setExtendedCode(extendCode);
+        pamars.setMobile(mobile);
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendSingleSMS", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            SmsResponse response = JsonHelper.fromJson(SmsResponse.class, result.getResult());
+            if (response != null) {
+                System.out.println("data : " + response.getMobile() + "," + response.getSmsId() + "," + response.getCustomSmsId());
+            }
+        }
+        System.out.println("=============end setSingleSms==================");
+    }
+
+    /**
+     * 发送批次短信
+     * 自定义SMSID
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void setBatchOnlySms(String appId, String secretKey, String host, String algorithm, String content, String extendCode, String[] mobiles, boolean isGzip, String encode) {
+        System.out.println("=============begin setBatchOnlySms==================");
+        SmsBatchOnlyRequest pamars = new SmsBatchOnlyRequest();
+        pamars.setMobiles(mobiles);
+        pamars.setExtendedCode(extendCode);
+        pamars.setContent(content);
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendBatchOnlySMS", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            SmsResponse[] response = JsonHelper.fromJson(SmsResponse[].class, result.getResult());
+            if (response != null) {
+                for (SmsResponse d : response) {
+                    System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
+                }
+            }
+        }
+        System.out.println("=============end setBatchOnlySms==================");
+    }
+
+    /**
+     * 发送批次短信
+     * 非自定义SMSID
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void setBatchSms(String appId, String secretKey, String host, String algorithm, String content, String extendCode, CustomSmsIdAndMobile[] customSmsIdAndMobiles, boolean isGzip,
+                                    String encode) {
+        System.out.println("=============begin setBatchSms==================");
+        SmsBatchRequest pamars = new SmsBatchRequest();
+        pamars.setSmses(customSmsIdAndMobiles);
+        pamars.setExtendedCode(extendCode);
+        pamars.setContent(content);
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendBatchSMS", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            SmsResponse[] response = JsonHelper.fromJson(SmsResponse[].class, result.getResult());
+            if (response != null) {
+                for (SmsResponse d : response) {
+                    System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
+                }
+            }
+        }
+        System.out.println("=============end setBatchSms==================");
+    }
+
+    /**
+     * 发送个性短信
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void setPersonalitySms(String appId, String secretKey, String host, String algorithm, String extendCode, CustomSmsIdAndMobileAndContent[] customSmsIdAndMobileAndContents,
+                                          boolean isGzip, String encode) {
+        System.out.println("=============begin setPersonalitySms==================");
+        SmsPersonalityRequest pamars = new SmsPersonalityRequest();
+        pamars.setSmses(customSmsIdAndMobileAndContents);
+        pamars.setExtendedCode(extendCode);
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendPersonalitySMS", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            SmsResponse[] response = JsonHelper.fromJson(SmsResponse[].class, result.getResult());
+            if (response != null) {
+                for (SmsResponse d : response) {
+                    System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
+                }
+            }
+        }
+        System.out.println("=============end setPersonalitySms==================");
+    }
+
+    /**
+     * 发送个性短信
+     *
+     * @param isGzip
+     *            是否压缩
+     */
+    public static void setPersonalityAllSms(String appId, String secretKey, String host, String algorithm, PersonalityParams[] customSmsIdAndMobileAndContents, boolean isGzip, String encode) {
+        System.out.println("=============begin setPersonalityAllSms==================");
+        SmsPersonalityAllRequest pamars = new SmsPersonalityAllRequest();
+        pamars.setSmses(customSmsIdAndMobileAndContents);
+        ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendPersonalityAllSMS", isGzip, encode);
+        System.out.println("result code :" + result.getCode());
+        if ("SUCCESS".equals(result.getCode())) {
+            SmsResponse[] response = JsonHelper.fromJson(SmsResponse[].class, result.getResult());
+            if (response != null) {
+                for (SmsResponse d : response) {
+                    System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
+                }
+            }
+        }
+        System.out.println("=============end setPersonalityAllSms==================");
+    }
+
+    /**
+     * 公共请求方法
+     */
+    public static ResultModel request(String appId, String secretKey, String algorithm, Object content, String url, final boolean isGzip, String encode) {
+        Map<String, String> headers = new HashMap<String, String>();
+        HttpRequest<byte[]> request = null;
+        try {
+            headers.put("appId", appId);
+            headers.put("encode", encode);
+            String requestJson = JsonHelper.toJsonString(content);
+            System.out.println("result json: " + requestJson);
+            byte[] bytes = requestJson.getBytes(encode);
+            System.out.println("request data size : " + bytes.length);
+            if (isGzip) {
+                headers.put("gzip", "on");
+                bytes = GZIPUtils.compress(bytes);
+                System.out.println("request data size [com]: " + bytes.length);
+            }
+            byte[] parambytes = AES.encrypt(bytes, secretKey.getBytes(), algorithm);
+            System.out.println("request data size [en] : " + parambytes.length);
+            HttpRequestParams<byte[]> params = new HttpRequestParams<byte[]>();
+            params.setCharSet("UTF-8");
+            params.setMethod("POST");
+            params.setHeaders(headers);
+            params.setParams(parambytes);
+            params.setUrl(url);
+            if (url.startsWith("https://")) {
+                request = new HttpsRequestBytes(params, null);
+            } else {
+                request = new HttpRequestBytes(params);
+            }
+        } catch (Exception e) {
+            System.out.println("加密异常");
+            e.printStackTrace();
+        }
+        HttpClient client = new HttpClient();
+        String code = null;
+        String result = null;
+        try {
+            HttpResponseBytes res = client.service(request, new HttpResponseBytesPraser());
+            if (res == null) {
+                System.out.println("请求接口异常");
+                return new ResultModel(code, result);
+            }
+            if (res.getResultCode().equals(HttpResultCode.SUCCESS)) {
+                if (res.getHttpCode() == 200) {
+                    code = res.getHeaders().get("result");
+                    if (code.equals("SUCCESS")) {
+                        byte[] data = res.getResult();
+                        System.out.println("response data size [en and com] : " + data.length);
+                        data = AES.decrypt(data, secretKey.getBytes(), algorithm);
+                        if (isGzip) {
+                            data = GZIPUtils.decompress(data);
+                        }
+                        System.out.println("response data size : " + data.length);
+                        result = new String(data, encode);
+                        System.out.println("response json: " + result);
+                    }
+                } else {
+                    System.out.println("请求接口异常,请求码:" + res.getHttpCode());
+                }
+            } else {
+                System.out.println("请求接口网络异常:" + res.getResultCode().getCode());
+            }
+        } catch (Exception e) {
+            System.out.println("解析失败");
+            e.printStackTrace();
+        }
+        ResultModel re = new ResultModel(code, result);
+        return re;
+    }
+}

+ 23 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsPersonalityAllRequest.java

@@ -0,0 +1,23 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 批量短信发送参数
+ * @author Frank
+ *
+ */
+public class SmsPersonalityAllRequest extends BaseRequest {
+
+	private static final long serialVersionUID = 1L;
+
+	private PersonalityParams[] smses;
+
+	public PersonalityParams[] getSmses() {
+		return smses;
+	}
+
+	public void setSmses(PersonalityParams[] smses) {
+		this.smses = smses;
+	}
+	
+
+}

+ 23 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsPersonalityRequest.java

@@ -0,0 +1,23 @@
+package com.ym.mec.collectfee.common.sms;
+
+/**
+ * 批量短信发送参数
+ * @author Frank
+ *
+ */
+public class SmsPersonalityRequest extends SmsBaseRequest {
+
+	private static final long serialVersionUID = 1L;
+
+	private CustomSmsIdAndMobileAndContent[] smses;
+
+	public CustomSmsIdAndMobileAndContent[] getSmses() {
+		return smses;
+	}
+
+	public void setSmses(CustomSmsIdAndMobileAndContent[] smses) {
+		this.smses = smses;
+	}
+	
+
+}

+ 57 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsResponse.java

@@ -0,0 +1,57 @@
+package com.ym.mec.collectfee.common.sms;
+
+import java.io.Serializable;
+
+/**
+ * 单条短信发送响应
+ * @author Frank
+ *
+ */
+public class SmsResponse implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 系统唯一smsId
+	 */
+	private String smsId;
+	
+	private String mobile;
+	
+	private String customSmsId;
+	
+	public SmsResponse(){
+		
+	}
+	
+	public SmsResponse(String smsId, String mobile, String customSmsId){
+		this.smsId = smsId;
+		this.mobile = mobile;
+		this.customSmsId = customSmsId;
+	}
+
+	public String getSmsId() {
+		return smsId;
+	}
+
+	public void setSmsId(String smsId) {
+		this.smsId = smsId;
+	}
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+}

+ 53 - 0
src/main/java/com/ym/mec/collectfee/common/sms/SmsSingleRequest.java

@@ -0,0 +1,53 @@
+package com.ym.mec.collectfee.common.sms;
+
+
+/**
+ * 单条短信发送参数
+ * @author Frank
+ *
+ */
+public class SmsSingleRequest extends SmsBaseRequest {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 电话号码
+	 */
+	private String mobile;
+	
+	/**
+	 * 短信内容
+	 */
+	private String content;
+	
+	/**
+	 * 自定义smsid
+	 */
+	private String customSmsId;
+	
+
+	public String getMobile() {
+		return mobile;
+	}
+
+	public void setMobile(String mobile) {
+		this.mobile = mobile;
+	}
+
+	public String getContent() {
+		return content;
+	}
+
+	public void setContent(String content) {
+		this.content = content;
+	}
+
+	public String getCustomSmsId() {
+		return customSmsId;
+	}
+
+	public void setCustomSmsId(String customSmsId) {
+		this.customSmsId = customSmsId;
+	}
+
+}

+ 14 - 0
src/main/java/com/ym/mec/collectfee/controller/UserController.java

@@ -184,6 +184,20 @@ public class UserController extends BaseController {
         return succeed();
     }
 
+    /**
+     * 开启乐团缴费功能
+     * @return
+     */
+    @ApiOperation(value = "开启乐团缴费功能")
+    @PostMapping("/openClassPay")
+    public Object openClassPay(Integer id){
+        if(id == null){
+            return failed(Constants.PARAM_VERIFY_ERROR_MSG);
+        }
+        schoolService.openClassPay(id);
+        return succeed();
+    }
+
 
     /**
      * 修改学生信息

+ 2 - 0
src/main/java/com/ym/mec/collectfee/dao/ApplyInfoDao.java

@@ -44,4 +44,6 @@ public interface ApplyInfoDao extends BaseDAO<Integer, ApplyInfo> {
      * @param subId
      */
     void updateUserSub(@Param("userId") Integer userId, @Param("subId")Integer subId, @Param("courseId")Integer courseId, @Param("updateTime") Date updateTime);
+
+    List<String> findUserByClass(@Param("classId") Integer classId,@Param("status") Integer status);
 }

+ 5 - 0
src/main/java/com/ym/mec/collectfee/service/SchoolService.java

@@ -8,4 +8,9 @@ public interface SchoolService extends BaseService<Integer, School> {
 
     School upsetSchool(ResponseCourseEntity courseEntity);
 
+    /**
+     * 开启乐团缴费
+     * @param classId
+     */
+    void openClassPay(Integer classId);
 }

+ 33 - 0
src/main/java/com/ym/mec/collectfee/service/impl/SchoolServiceImpl.java

@@ -2,12 +2,15 @@ package com.ym.mec.collectfee.service.impl;
 
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
+import com.ym.mec.collectfee.common.sms.SmsExample;
+import com.ym.mec.collectfee.dao.ApplyInfoDao;
 import com.ym.mec.collectfee.dao.SchoolDao;
 import com.ym.mec.collectfee.entity.Course;
 import com.ym.mec.collectfee.entity.ResponseCourseEntity;
 import com.ym.mec.collectfee.entity.School;
 import com.ym.mec.collectfee.service.SchoolService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -19,6 +22,21 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implemen
 	
 	@Autowired
 	private SchoolDao schoolDao;
+	@Autowired
+	private ApplyInfoDao applyInfoDao;
+
+	@Value("${common.properties.sms-appId}")
+	private String appId;
+	@Value("${common.properties.sms-secretKey}")
+	private String secretKey;
+	@Value("${common.properties.sms-host-dev}")
+	private String host;
+	// 加密算法
+	private String algorithm = "AES/ECB/PKCS5Padding";
+	// 编码
+	private String encode = "UTF-8";
+	// 是否压缩
+	private boolean isGizp = true;
 
 	@Override
 	public BaseDAO<Integer, School> getDAO() {
@@ -47,4 +65,19 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implemen
 		}
 		return null;
 	}
+
+	@Override
+	public void openClassPay(Integer classId) {
+		School school = schoolDao.get(classId);
+		if(school != null && school.getStatus() == 1){
+			school.setUpdateTime(new Date());
+			school.setStatus(2);
+			schoolDao.update(school);
+			//发送短信
+			//获取所有用户手机号列表
+			List<String> userPhone = applyInfoDao.findUserByClass(classId,null);
+			String[] objects = (String[]) userPhone.toArray();
+//			SmsExample.setBatchOnlySms(appId,secretKey,host,algorithm,"开团了",null,objects,isGizp,encode);
+		}
+	}
 }

+ 11 - 0
src/main/resources/config/mybatis/ApplyInfoMapper.xml

@@ -200,4 +200,15 @@
 	<select id="findByUserId" resultMap="ApplyInfo">
 		SELECT * FROM apply_info WHERE user_id_ = #{userId}
 	</select>
+	<select id="findUserByClass" resultType="java.lang.String">
+		SELECT patriarch_phone_ FROM apply_info
+		<where>
+			<if test="classId != null">
+				class_id_ = #{classId}
+			</if>
+			<if test="status != null">
+				status_ = #{status}
+			</if>
+		</where>
+	</select>
 </mapper>