Explorar o código

sms短信模块,api接口开发准备

ZhangWenQiang %!s(int64=6) %!d(string=hai) anos
pai
achega
0d103aa866

+ 75 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/sms/SMS253Utils.java

@@ -0,0 +1,75 @@
+package org.jeecg.common.sms;
+
+import com.alibaba.fastjson.JSON;
+import okhttp3.*;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author zwq
+ * @Description:253普通短信发送
+ */
+public class SMS253Utils {
+
+    private static String account = "N3241700";// N6000001" 用户在253云通讯平台上申请的API账号
+    private static String password = "O04MCJiBLc6b64";// 123456" 用户在253云通讯平台上申请的API账号对应的API密钥
+    private static String smsUrl = "http://smssh1.253.com/msg/send/json"; // http://xxx/msg/send/json 或者 https://xxx/msg/send/json
+    private static String smsSign = "%e3%80%90%e5%bc%80%e5%bf%83%e5%b7%a5%e4%bd%9c%e3%80%91"; // 在zz.253.com 后台设置签名管理
+    private static final Logger logger = LoggerFactory.getLogger(SMS253Utils.class);
+    private static final OkHttpClient client = new OkHttpClient();
+    private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
+
+    /**
+     * @param sendMap 短信map内容
+     * @return true 表示提交发送指令成功,false 表示提交指令失败
+     */
+
+    public static Map<String, Object> sendSms(HashMap<String, String> sendMap) {
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        try {
+            //短信内容
+            String msg = sendMap.get("msg");
+            //发送的手机号
+            String phoneNum = sendMap.get("phone");
+
+            SmsSendRequest smsSendRequest = new SmsSendRequest();
+            smsSendRequest.setAccount(account);
+            smsSendRequest.setPassword(password);
+            // 拼接签名(不带签名则使用默认签名)
+            smsSendRequest.setMsg(StringUtils.appendIfMissing(smsSign, msg));
+//            smsSendRequest.setMsg(msg);
+            smsSendRequest.setPhone(phoneNum);
+            String postBody = JSON.toJSONString(smsSendRequest);
+
+            Request request =
+                    new Request.Builder().url(smsUrl).post(RequestBody.create(MEDIA_TYPE_JSON, postBody)).build();
+
+            Response response = client.newCall(request).execute();
+
+            if (response.isSuccessful()) {
+                String jsonString = new String(response.body().bytes(), Charset.forName("utf-8"));
+
+                SmsSendResponse res = JSON.parseObject(jsonString, SmsSendResponse.class);
+
+                if (res.getCode() != null && res.getCode().equals(SMSConst.OKCode)) {
+                    returnMap.put("success", res.getCode());
+                    returnMap.put("msg", "获取短信验证码成功!");
+                } else {
+                    logger.warn("SmsSendResponse : {} ", res);
+                    returnMap.put("success", res.getCode());
+                    returnMap.put("msg", res.getErrorMsg());
+                }
+            }
+
+        } catch (Exception e) {
+            logger.warn("sendSms  exception : { } ", e);
+        }
+        return returnMap;
+    }
+
+}

+ 21 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/sms/SMSConst.java

@@ -0,0 +1,21 @@
+package org.jeecg.common.sms;
+
+/**
+ * @author zwq
+ * 短信状态码
+ */
+public class SMSConst {
+    /**
+     * 提交成功
+     */
+    public static final String OKCode = "0";
+    /**
+     * 无此用户
+     */
+    public static final String NOUSER = "101";
+    /**
+     * 密码错误
+     */
+    public static final String MSGERROR = "102";
+
+}

+ 162 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/sms/SmsSendRequest.java

@@ -0,0 +1,162 @@
+package org.jeecg.common.sms;
+
+/**
+ * @author tianyh
+ * @Description:普通短信发送实体类
+ */
+public class SmsSendRequest {
+    /**
+     * 创蓝API账号,必填
+     */
+    private String account;
+    /**
+     * 创蓝API密码,必填
+     */
+    private String password;
+    /**
+     * 短信内容。长度不能超过536个字符,必填
+     */
+    private String msg;
+    /**
+     * 机号码。多个手机号码使用英文逗号分隔,必填
+     */
+    private String phone;
+
+
+    /**
+     * 定时发送短信时间。格式为yyyyMMddHHmm,值小于或等于当前时间则立即发送,默认立即发送,选填
+     */
+    private String sendtime;
+    /**
+     * 是否需要状态报告(默认false),选填
+     */
+    private String report;
+    /**
+     * 下发短信号码扩展码,纯数字,建议1-3位,选填
+     */
+    private String extend;
+    /**
+     * 该条短信在您业务系统内的ID,如订单号或者短信发送记录流水号,选填
+     */
+    private String uid;
+
+    public SmsSendRequest() {
+
+    }
+
+    public SmsSendRequest(String account, String password, String msg, String phone) {
+        super();
+        this.account = account;
+        this.password = password;
+        this.msg = msg;
+        this.phone = phone;
+    }
+
+    public SmsSendRequest(String account, String password, String msg, String phone, String report) {
+        super();
+        this.account = account;
+        this.password = password;
+        this.msg = msg;
+        this.phone = phone;
+        this.report = report;
+    }
+
+    public SmsSendRequest(String account, String password, String msg, String phone, String report, String sendtime) {
+        super();
+        this.account = account;
+        this.password = password;
+        this.msg = msg;
+        this.phone = phone;
+        this.sendtime = sendtime;
+        this.report = report;
+    }
+
+    public SmsSendRequest(String account, String password, String msg, String phone, String sendtime, String report, String uid) {
+        super();
+        this.account = account;
+        this.password = password;
+        this.msg = msg;
+        this.phone = phone;
+        this.sendtime = sendtime;
+        this.report = report;
+        this.uid = uid;
+    }
+
+    public String getAccount() {
+        return account;
+    }
+
+    public void setAccount(String account) {
+        this.account = account;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getSendtime() {
+        return sendtime;
+    }
+
+    public void setSendtime(String sendtime) {
+        this.sendtime = sendtime;
+    }
+
+    public String getReport() {
+        return report;
+    }
+
+    public void setReport(String report) {
+        this.report = report;
+    }
+
+    public String getExtend() {
+        return extend;
+    }
+
+    public void setExtend(String extend) {
+        this.extend = extend;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    @Override
+    public String toString() {
+        return "SmsSendRequest{" +
+                "account='" + account + '\'' +
+                ", password='" + password + '\'' +
+                ", msg='" + msg + '\'' +
+                ", phone='" + phone + '\'' +
+                ", sendtime='" + sendtime + '\'' +
+                ", report='" + report + '\'' +
+                ", extend='" + extend + '\'' +
+                ", uid='" + uid + '\'' +
+                '}';
+    }
+}

+ 62 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/sms/SmsSendResponse.java

@@ -0,0 +1,62 @@
+package org.jeecg.common.sms;
+
+/**
+ * @author tianyh
+ * @Description:普通短信发送响应实体类
+ */
+public class SmsSendResponse {
+    /**
+     * 响应时间
+     */
+    private String time;
+    /**
+     * 消息id
+     */
+    private String msgId;
+    /**
+     * 状态码说明(成功返回空)
+     */
+    private String errorMsg;
+    /**
+     * 状态码(详细参考提交响应状态码)
+     */
+    private String code;
+
+    public String getTime() {
+        return time;
+    }
+
+    public void setTime(String time) {
+        this.time = time;
+    }
+
+    public String getMsgId() {
+        return msgId;
+    }
+
+    public void setMsgId(String msgId) {
+        this.msgId = msgId;
+    }
+
+    public String getErrorMsg() {
+        return errorMsg;
+    }
+
+    public void setErrorMsg(String errorMsg) {
+        this.errorMsg = errorMsg;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    @Override
+    public String toString() {
+        return "SmsSingleResponse [time=" + time + ", msgId=" + msgId + ", errorMsg=" + errorMsg + ", code=" + code
+                + "]";
+    }
+}

+ 34 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/util/ErrorCode.java

@@ -0,0 +1,34 @@
+package org.jeecg.common.util;
+
+/**
+ * 错误码定义
+ */
+public interface ErrorCode {
+
+    final int code_1000 = 0;   //正确数据
+    final int code_1001 = 1001;  // 会话失效
+    final int code_1002 = 1002;  // 用户或密码错误, 请重试.
+    final int code_1003 = 1003;  //登录失败, 该用户未注册.
+    final int code_1004 = 1004;  //授权code码为空
+    final int code_1005 = 1005;   //小程序、微信登录失败
+    final int code_1006 = 1006;   //已经登陆
+    final int code_1007 = 1007;   //手机号已被使用
+    final int code_1008 = 1008;   //短信发送异常
+    final int code_1009 = 1009;   //图片上传失败
+    final int code_1010 = 1010;   //openId为空
+    final int code_1011 = 1011;   //验证码错误
+    final int code_1012 = 1012;   //验证码无效或不存在
+    final int code_1013 = 1013;    //refreshToken已过期
+    final int code_1014 = 1014;    //用户暂无手机号,前往绑定
+    final int code_1015 = 1015;    //用户简历不存在
+    final int code_1016 = 1016;    //您已投递该岗位
+    final int code_1017 = 1017;    //您申请的拼团已结束
+    final int code_1018 = 1018;    //您投递的岗位已过期
+    final int code_1019 = 1019;    //您已参团
+    final int code_1020 = 1020;    //用户手机号为空
+    final int code_1021 = 1021;    //该岗位已下架
+    final int code_1022 = 1022;    //用户未认证通过
+    final int code_2006 = 2006; // 操作数据失败
+    final int code_2007 = 2007; // 数据不存在
+    final int code_2008 = 2008;   //用户信息验证失败或token失效
+}

+ 34 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/util/OtherException.java

@@ -0,0 +1,34 @@
+package org.jeecg.common.util;
+
+/**
+ * 自定义异常
+ * @author hanxu
+ *	2013-03-19
+ */
+public class OtherException extends Exception {
+
+	private static final long serialVersionUID = 1L;
+	private String errorCode; //错误编码
+	private String errorMsg;  //错误信息
+	
+	public String getErrorCode() {
+		return errorCode;
+	}
+	public void setErrorCode(String errorCode) {
+		this.errorCode = errorCode;
+	}
+	public String getErrorMsg() {
+		return errorMsg;
+	}
+	public void setErrorMsg(String errorMsg) {
+		this.errorMsg = errorMsg;
+	}
+	
+	public OtherException(String errorCode, String errorMsg) {
+		super();
+		this.errorCode = errorCode;
+		this.errorMsg = errorMsg;
+	}
+	
+	
+}

+ 400 - 0
happy-boot-base-common/src/main/java/org/jeecg/common/util/StringUtils.java

@@ -0,0 +1,400 @@
+/**
+ * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
+ */
+package org.jeecg.common.util;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringEscapeUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
+ * @author jeeplus
+ * @version 2016-05-22
+ */
+public class StringUtils extends org.apache.commons.lang3.StringUtils {
+	
+    private static final char SEPARATOR = '_';
+    private static final String CHARSET_NAME = "UTF-8";
+    
+    /**
+     * 转换为字节数组
+     * @param str
+     * @return
+     */
+    public static byte[] getBytes(String str){
+    	if (str != null){
+    		try {
+				return str.getBytes(CHARSET_NAME);
+			} catch (UnsupportedEncodingException e) {
+				return null;
+			}
+    	}else{
+    		return null;
+    	}
+    }
+    
+    /**
+     * 转换为字节数组
+     * @param bytes
+     * @return
+     */
+    public static String toString(byte[] bytes){
+    	try {
+			return new String(bytes, CHARSET_NAME);
+		} catch (UnsupportedEncodingException e) {
+			return EMPTY;
+		}
+    }
+    
+    /**
+     * 是否包含字符串
+     * @param str 验证字符串
+     * @param strs 字符串组
+     * @return 包含返回true
+     */
+    public static boolean inString(String str, String... strs){
+    	if (str != null){
+        	for (String s : strs){
+        		if (str.equals(trim(s))){
+        			return true;
+        		}
+        	}
+    	}
+    	return false;
+    }
+    
+	/**
+	 * 替换掉HTML标签方法
+	 */
+	public static String replaceHtml(String html) {
+		if (isBlank(html)){
+			return "";
+		}
+		String regEx = "<.+?>";
+		Pattern p = Pattern.compile(regEx);
+		Matcher m = p.matcher(html);
+		String s = m.replaceAll("");
+		return s;
+	}
+	
+	/**
+	 * 替换为手机识别的HTML,去掉样式及属性,保留回车。
+	 * @param html
+	 * @return
+	 */
+	public static String replaceMobileHtml(String html){
+		if (html == null){
+			return "";
+		}
+		return html.replaceAll("<([a-z]+?)\\s+?.*?>", "<$1>");
+	}
+	
+	/**
+	 * 替换为手机识别的HTML,去掉样式及属性,保留回车。
+	 * @param txt
+	 * @return
+	 */
+//	public static String toHtml(String txt){
+//		if (txt == null){
+//			return "";
+//		}
+//		return replace(replace(Encodes.escapeHtml(txt), "\n", "<br/>"), "\t", "&nbsp; &nbsp; ");
+//	}
+
+	/**
+	 * 缩略字符串(不区分中英文字符)
+	 * @param str 目标字符串
+	 * @param length 截取长度
+	 * @return
+	 */
+	public static String abbr(String str, int length) {
+		if (str == null) {
+			return "";
+		}
+		try {
+			StringBuilder sb = new StringBuilder();
+			int currentLength = 0;
+			for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) {
+				currentLength += String.valueOf(c).getBytes("GBK").length;
+				if (currentLength <= length - 3) {
+					sb.append(c);
+				} else {
+					sb.append("...");
+					break;
+				}
+			}
+			return sb.toString();
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		return "";
+	}
+	
+	public static String abbr2(String param, int length) {
+		if (param == null) {
+			return "";
+		}
+		StringBuffer result = new StringBuffer();
+		int n = 0;
+		char temp;
+		boolean isCode = false; // 是不是HTML代码
+		boolean isHTML = false; // 是不是HTML特殊字符,如&nbsp;
+		for (int i = 0; i < param.length(); i++) {
+			temp = param.charAt(i);
+			if (temp == '<') {
+				isCode = true;
+			} else if (temp == '&') {
+				isHTML = true;
+			} else if (temp == '>' && isCode) {
+				n = n - 1;
+				isCode = false;
+			} else if (temp == ';' && isHTML) {
+				isHTML = false;
+			}
+			try {
+				if (!isCode && !isHTML) {
+					n += String.valueOf(temp).getBytes("GBK").length;
+				}
+			} catch (UnsupportedEncodingException e) {
+				e.printStackTrace();
+			}
+
+			if (n <= length - 3) {
+				result.append(temp);
+			} else {
+				result.append("...");
+				break;
+			}
+		}
+		// 取出截取字符串中的HTML标记
+		String temp_result = result.toString().replaceAll("(>)[^<>]*(<?)",
+				"$1$2");
+		// 去掉不需要结素标记的HTML标记
+		temp_result = temp_result
+				.replaceAll(
+						"</?(AREA|BASE|BASEFONT|BODY|BR|COL|COLGROUP|DD|DT|FRAME|HEAD|HR|HTML|IMG|INPUT|ISINDEX|LI|LINK|META|OPTION|P|PARAM|TBODY|TD|TFOOT|TH|THEAD|TR|area|base|basefont|body|br|col|colgroup|dd|dt|frame|head|hr|html|img|input|isindex|li|link|meta|option|p|param|tbody|td|tfoot|th|thead|tr)[^<>]*/?>",
+						"");
+		// 去掉成对的HTML标记
+		temp_result = temp_result.replaceAll("<([a-zA-Z]+)[^<>]*>(.*?)</\\1>",
+				"$2");
+		// 用正则表达式取出标记
+		Pattern p = Pattern.compile("<([a-zA-Z]+)[^<>]*>");
+		Matcher m = p.matcher(temp_result);
+		List<String> endHTML = Lists.newArrayList();
+		while (m.find()) {
+			endHTML.add(m.group(1));
+		}
+		// 补全不成对的HTML标记
+		for (int i = endHTML.size() - 1; i >= 0; i--) {
+			result.append("</");
+			result.append(endHTML.get(i));
+			result.append(">");
+		}
+		return result.toString();
+	}
+	
+	/**
+	 * 转换为Double类型
+	 */
+	public static Double toDouble(Object val){
+		if (val == null){
+			return 0D;
+		}
+		try {
+			return Double.valueOf(trim(val.toString()));
+		} catch (Exception e) {
+			return 0D;
+		}
+	}
+
+	/**
+	 * 转换为Float类型
+	 */
+	public static Float toFloat(Object val){
+		return toDouble(val).floatValue();
+	}
+
+	/**
+	 * 转换为Long类型
+	 */
+	public static Long toLong(Object val){
+		return toDouble(val).longValue();
+	}
+
+	/**
+	 * 转换为Integer类型
+	 */
+	public static Integer toInteger(Object val){
+		return toLong(val).intValue();
+	}
+	
+	/**
+	 * 获得i18n字符串
+	 */
+//	public static String getMessage(String code, Object[] args) {
+//		LocaleResolver localLocaleResolver = (LocaleResolver) SpringContextHolder.getBean(LocaleResolver.class);
+//		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
+//		Locale localLocale = localLocaleResolver.resolveLocale(request);
+//		return SpringContextHolder.getApplicationContext().getMessage(code, args, localLocale);
+//	}
+	
+	/**
+	 * 获得用户远程地址
+	 */
+	public static String getRemoteAddr(HttpServletRequest request){
+		String remoteAddr = request.getHeader("X-Real-IP");
+        if (isNotBlank(remoteAddr)) {
+        	remoteAddr = request.getHeader("X-Forwarded-For");
+        }else if (isNotBlank(remoteAddr)) {
+        	remoteAddr = request.getHeader("Proxy-Client-IP");
+        }else if (isNotBlank(remoteAddr)) {
+        	remoteAddr = request.getHeader("WL-Proxy-Client-IP");
+        }
+        return remoteAddr != null ? remoteAddr : request.getRemoteAddr();
+	}
+
+	/**
+	 * 驼峰命名法工具
+	 * @return
+	 * 		toCamelCase("hello_world") == "helloWorld" 
+	 * 		toCapitalizeCamelCase("hello_world") == "HelloWorld"
+	 * 		toUnderScoreCase("helloWorld") = "hello_world"
+	 */
+    public static String toCamelCase(String s) {
+        if (s == null) {
+            return null;
+        }
+
+        s = s.toLowerCase();
+
+        StringBuilder sb = new StringBuilder(s.length());
+        boolean upperCase = false;
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+
+            if (c == SEPARATOR) {
+                upperCase = true;
+            } else if (upperCase) {
+                sb.append(Character.toUpperCase(c));
+                upperCase = false;
+            } else {
+                sb.append(c);
+            }
+        }
+
+        return sb.toString();
+    }
+
+    /**
+	 * 驼峰命名法工具
+	 * @return
+	 * 		toCamelCase("hello_world") == "helloWorld" 
+	 * 		toCapitalizeCamelCase("hello_world") == "HelloWorld"
+	 * 		toUnderScoreCase("helloWorld") = "hello_world"
+	 */
+    public static String toCapitalizeCamelCase(String s) {
+        if (s == null) {
+            return null;
+        }
+        s = toCamelCase(s);
+        return s.substring(0, 1).toUpperCase() + s.substring(1);
+    }
+    
+    /**
+	 * 驼峰命名法工具
+	 * @return
+	 * 		toCamelCase("hello_world") == "helloWorld" 
+	 * 		toCapitalizeCamelCase("hello_world") == "HelloWorld"
+	 * 		toUnderScoreCase("helloWorld") = "hello_world"
+	 */
+    public static String toUnderScoreCase(String s) {
+        if (s == null) {
+            return null;
+        }
+
+        StringBuilder sb = new StringBuilder();
+        boolean upperCase = false;
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+
+            boolean nextUpperCase = true;
+
+            if (i < (s.length() - 1)) {
+                nextUpperCase = Character.isUpperCase(s.charAt(i + 1));
+            }
+
+            if ((i > 0) && Character.isUpperCase(c)) {
+                if (!upperCase || !nextUpperCase) {
+                    sb.append(SEPARATOR);
+                }
+                upperCase = true;
+            } else {
+                upperCase = false;
+            }
+
+            sb.append(Character.toLowerCase(c));
+        }
+
+        return sb.toString();
+    }
+    
+    /**
+     * 如果不为空,则设置值
+     * @param target
+     * @param source
+     */
+    public static void setValueIfNotBlank(String target, String source) {
+		if (isNotBlank(source)){
+			target = source;
+		}
+	}
+ 
+    /**
+     * @param target
+     * @param str
+     */
+    public static int lastIndexOf(String target, String str) {
+    	if(isBlank(target) || isBlank(str)){
+    		return -1;
+    	}
+		return target.lastIndexOf(str);
+	}
+ 
+    /**
+     * 转换为JS获取对象值,生成三目运算返回结果
+     * @param objectString 对象串
+     *   例如:row.user.id
+     *   返回:!row?'':!row.user?'':!row.user.id?'':row.user.id
+     */
+    public static String jsGetVal(String objectString){
+    	StringBuilder result = new StringBuilder();
+    	StringBuilder val = new StringBuilder();
+    	String[] vals = split(objectString, ".");
+    	for (int i=0; i<vals.length; i++){
+    		val.append("." + vals[i]);
+    		result.append("!"+(val.substring(1))+"?'':");
+    	}
+    	result.append(val.substring(1));
+    	return result.toString();
+    }
+
+    public static String getLabels(String values){
+    	String[] valueAttr = values.split("\\|");
+    	String labels = "";
+    	for(String value:valueAttr){
+    		labels += StringUtils.substringAfterLast(value, "/")+",";
+		}
+		if(StringUtils.isBlank(labels)){
+    		return labels;
+		}else{
+    		return labels.substring(0,labels.length()-1);
+		}
+	}
+    
+}

+ 331 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/api/sys/BaseAppController.java

@@ -0,0 +1,331 @@
+package org.jeecg.modules.api.sys;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import org.jeecg.common.util.IPUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * app端Controller基类
+ *
+ * @author zwq 2019-03-18
+ */
+public class BaseAppController {
+
+    private static Logger logger = LoggerFactory.getLogger(BaseAppController.class);
+    // 日志时需要忽略的字段
+    private static final HashSet<String> paramsToOmit = new HashSet<String>();
+
+    static {
+        paramsToOmit.add("loginPassword");
+        paramsToOmit.add("loginPasswordChk");
+        paramsToOmit.add("password");
+        paramsToOmit.add("oldPassword");
+        paramsToOmit.add("newPassword");
+    }
+
+    public static final String DATA = "data";
+    public static final String ERROR = "error";
+    public static final String STATUS = "status";
+    public static final String ERRORMSG = "errmsg";
+    public static final String ERRORCODE = "errcode";
+
+    /**
+     * 将request里面访问的所有参数转成HashMap
+     *
+     * @param request
+     * @return HashMap<String                                                               ,                                                               String>
+     */
+    @SuppressWarnings("rawtypes")
+    protected HashMap<String, String> findRequestMap(HttpServletRequest request) {
+        HashMap<String, String> requestMap = new HashMap<String, String>();
+        // Map requestParams = request.getParameterMap();
+        if (request.getMethod().equals("GET")) {
+            Map requestParams = request.getParameterMap();
+            for (Iterator iter = requestParams.keySet().iterator(); iter
+                    .hasNext(); ) {
+                String name = (String) iter.next();
+                String[] values = (String[]) requestParams.get(name);
+                String valueStr = "";
+                for (int i = 0; i < values.length; i++) {
+                    valueStr = (i == values.length - 1) ? valueStr + values[i]
+                            : valueStr + values[i] + ",";
+                }
+                requestMap.put(name, valueStr);
+            }
+        } else {
+            String jsonString = null;
+            try {
+                jsonString = getRequestJsonString(request);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            if (jsonString.contains("&")) {
+                String[] strs = jsonString.split("&");
+                for (int i = 0; i < strs.length; i++) {
+                    String json = strs[i];
+                    String[] strs1 = json.split("=");
+
+                    if (strs1.length == 1) {
+                        requestMap.put(strs1[0].trim(), "");
+                    } else {
+                        requestMap.put(strs1[0].trim(), strs1[1].trim());
+                    }
+                }
+            } else {
+                JSONObject jsonObject = JSONObject.fromObject(jsonString);
+
+                Iterator<String> keys = jsonObject.keys();// 定义迭代器
+
+                String key = null;
+                String value = null;
+
+                while (keys.hasNext()) {
+                    key = keys.next().toString();
+                    value = jsonObject.get(key).toString();
+
+                    requestMap.put(key.trim(), value.trim());
+                }
+
+            }
+        }
+        return requestMap;
+
+    }
+
+    /***
+     * 获取 request 中 json 字符串的内容
+     *
+     * @param request
+     * @return : <code>byte[]</code>
+     * @throws IOException
+     */
+    public String getRequestJsonString(HttpServletRequest request)
+            throws IOException {
+        String submitMehtod = request.getMethod();
+        System.out.println("submitMehtod ============>" + submitMehtod);
+        // GET
+        if (submitMehtod.equals("GET")) {
+            return new String(request.getQueryString().getBytes("iso-8859-1"),
+                    "utf-8").replaceAll("%22", "\"").replaceAll("\\+", "%2B");
+            // POST
+        } else {
+            return getRequestPostStr(request);
+        }
+    }
+
+    /**
+     * 描述:获取 post 请求的 byte[] 数组
+     *
+     * <pre>
+     * 举例:
+     * </pre>
+     *
+     * @param request
+     * @return
+     * @throws IOException
+     */
+    public byte[] getRequestPostBytes(HttpServletRequest request)
+            throws IOException {
+        int contentLength = request.getContentLength();
+        if (contentLength < 0) {
+            return null;
+        }
+        byte buffer[] = new byte[contentLength];
+        for (int i = 0; i < contentLength; ) {
+
+            int readlen = request.getInputStream().read(buffer, i,
+                    contentLength - i);
+            if (readlen == -1) {
+                break;
+            }
+            i += readlen;
+        }
+        return buffer;
+    }
+
+    /**
+     * 描述:获取 post 请求内容
+     *
+     * <pre>
+     * 举例:
+     * </pre>
+     *
+     * @param request
+     * @return
+     * @throws IOException
+     */
+    public String getRequestPostStr(HttpServletRequest request)
+            throws IOException {
+        byte buffer[] = getRequestPostBytes(request);
+        String charEncoding = request.getCharacterEncoding();
+        if (charEncoding == null) {
+            charEncoding = "UTF-8";
+        }
+        return new String(buffer, charEncoding);
+    }
+
+
+    // 输出map正确消息
+    public Map<String, Object> successResult(int errorCode, String errorMsg,
+                                             Object data) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(ERRORCODE, errorCode);
+        map.put(ERRORMSG, errorMsg);
+        map.put(DATA, data);
+        return map;
+    }
+
+
+    // 输出map错误消息
+    public Map<String, Object> errorResult(int errorCode, String errorMsg) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(ERRORCODE, errorCode);
+        map.put(ERRORMSG, errorMsg);
+        return map;
+    }
+
+    // AJAX输出文本,返回null
+    public String ajaxText(String text, HttpServletResponse response) {
+        return ajax(text, "text/plain", response);
+    }
+
+    // AJAX输出HTML,返回null
+    public String ajaxHtml(String html, HttpServletResponse response) {
+        return ajax(html, "text/html", response);
+    }
+
+    // 根据字符串输出JSON,返回null
+    public String ajaxJson(String jsonString, HttpServletResponse response) {
+        return ajax(jsonString, "text/html", response);
+    }
+
+    // 根据Map输出JSON,返回null
+    public String ajaxJson(Map<String, Object> jsonMap,
+                           HttpServletResponse response) {
+        JSONObject jsonObject = JSONObject.fromObject(jsonMap);
+        return ajax(jsonObject.toString(), "text/html", response);
+    }
+
+    // 根据HashMap输出JSON,返回null
+    public String ajaxJson(HashMap<String, String> jsonMap,
+                           HttpServletResponse response) {
+        JSONObject jsonObject = JSONObject.fromObject(jsonMap);
+        return ajax(jsonObject.toString(), "text/html", response);
+    }
+
+    // 根据List输出JSON,返回null
+    public String ajaxJson(List<HashMap<String, String>> list,
+                           HttpServletResponse response) {
+        JSONArray jsonArray = JSONArray.fromObject(list);
+        return ajax(jsonArray.toString(), "text/html", response);
+    }
+
+    // 根据List输出JSON,返回null
+    public String ajaxJsonListObject(List<Map<String, Object>> list,
+                                     HttpServletResponse response) {
+        JSONArray jsonArray = JSONArray.fromObject(list);
+        return ajax(jsonArray.toString(), "text/html", response);
+    }
+
+    // AJAX输出,返回null
+    public String ajax(String content, String type, HttpServletResponse response) {
+        try {
+            response.setContentType(type + ";charset=UTF-8");
+            response.setHeader("Pragma", "No-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            response.setDateHeader("Expires", 0);
+            response.getWriter().write(content);
+            response.getWriter().flush();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 给重要的功能入口加日志功能
+     *
+     * @param request
+     * @param action  动作
+     */
+    protected void logInfo(HttpServletRequest request, String action) {
+        StringBuilder sb = new StringBuilder("实际调用方法:")
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getClassName())
+                .append(".")
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getMethodName())
+                .append('(')
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getLineNumber()).append(')').append(",IP地址")
+                .append(IPUtils.getIpAddr(request)).append(") —— 动作:")
+                .append(action).append(" 请求参数是|").append(getParams(request));
+        logger.info(sb.toString());
+    }
+
+    /**
+     * 记录错误日志
+     *
+     * @param request
+     * @param message 错误信息
+     */
+    protected void logError(HttpServletRequest request, String message) {
+        logError(request, message, null);
+    }
+
+    protected void logError(HttpServletRequest request, String message,
+                            Exception e) {
+        StringBuilder sb = new StringBuilder("实际调用方法:")
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getClassName())
+                .append(".")
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getMethodName())
+                .append('(')
+                .append(Thread.currentThread().getStackTrace()[2]
+                        .getLineNumber()).append(')').append("错误信息:")
+                .append(message).append(",IP地址").append(IPUtils.getIpAddr(request))
+                .append(" 请求参数是|").append(getParams(request));
+        sb.append("||异常信息:").append(message);
+        logger.error(sb.toString(), e);
+    }
+
+    /**
+     * 得到请求参数
+     *
+     * @param request
+     */
+    @SuppressWarnings("rawtypes")
+    protected String getParams(HttpServletRequest request) {
+        StringBuilder sb = new StringBuilder();
+        Map params = request.getParameterMap();
+        for (Object key : params.keySet()) {
+            Object[] objs = null;
+            if (null != params.get(key))
+                objs = (Object[]) params.get(key);
+
+            sb.append(key).append(":");
+            if (objs != null) {
+                // 密码等不能写入日志!!
+                if (paramsToOmit.contains(key)) {
+                    sb.append("*****/");
+                } else {
+                    for (Object object : objs) {
+                        sb.append(object).append("/");
+                    }
+                }
+            }
+            sb.append(",");
+        }
+        return sb.toString();
+    }
+
+}

+ 98 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/api/sys/LoginAppControllerAPI.java

@@ -0,0 +1,98 @@
+package org.jeecg.modules.api.sys;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.sms.SMSConst;
+import org.jeecg.common.util.ErrorCode;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.StringUtils;
+import org.jeecg.modules.user.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@Api(tags="用户api")
+@RestController
+@RequestMapping("/api/hpuser")
+public class LoginAppControllerAPI extends BaseAppController{
+    @Autowired
+    private IUserService userService;
+    @Autowired
+    private RedisUtil redisUtil;
+
+    /**
+     * 手机端快速登录,验证码发送
+     */
+    @ApiOperation(notes = "getAuthCode", httpMethod = "POST", value = "app获取验证码")
+    @ApiImplicitParams(@ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "query", dataType = "string"))
+    @PostMapping(value = "/getAuthCode")
+    public ModelAndView getAuthCode4LoginQuickly(HttpServletRequest request, HttpServletResponse response) {
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Method", "POST,GET");
+        Map<String, Object> obj = null;
+        HashMap<String, String> requestMap = findRequestMap(request);
+        Map<String, Object> map = new HashMap<>();
+        try {
+            Map<String, Object> returnMap = userService.sendMobileCode(requestMap);
+            if (SMSConst.OKCode.equals(returnMap.get("success"))) {
+                map.put("code", returnMap.get("code"));
+                obj = successResult(ErrorCode.code_1000, "", map);
+            } else {
+                obj = errorResult(ErrorCode.code_1008, (String) returnMap.get("msg"));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            obj = errorResult(ErrorCode.code_1008, "获取验证码失败");
+            logError(request, e.getMessage(), e);
+        }
+
+        ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
+        return view;
+    }
+
+    /**
+     * 手机端快速登录,登录验证
+     */
+    @PostMapping(value = "/phoneLogin")
+    public ModelAndView getLoginMapQuickly(HttpServletRequest request, HttpServletResponse response) {
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Method", "POST,GET");
+        Map<String, Object> obj = null;
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        Map<String, String> requestMap = findRequestMap(request);
+        try {
+            String phone = requestMap.get("phone");
+            if (StringUtils.isNotBlank(phone)) {
+                String code = (String) redisUtil.get(phone);
+                String getCode = requestMap.get("code");
+                if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(getCode)) {
+                    if (code.equals(getCode)) {
+                        returnMap = userService.getLoginApp(requestMap);
+                        obj = successResult(ErrorCode.code_1000, "登录成功", returnMap);
+                    } else {
+                        obj = errorResult(ErrorCode.code_1011, "验证码错误");
+                    }
+                } else {
+                    obj = errorResult(ErrorCode.code_1012, "验证码无效或不存在");
+                }
+            }
+        } catch (Exception e) {
+            System.out.println("Exception e:" + e);
+            e.printStackTrace();
+            obj = errorResult(ErrorCode.code_1003, "登录失败");
+            logError(request, e.getMessage(), e);
+        }
+        ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
+        return view;
+    }
+}

+ 8 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/user/service/IUserService.java

@@ -1,9 +1,13 @@
 package org.jeecg.modules.user.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.jeecg.common.util.OtherException;
 import org.jeecg.modules.user.entity.User;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @Description: 用户审核
  * @Author: jeecg-boot
@@ -13,4 +17,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IUserService extends IService<User> {
 
     Page<User> queryPageListNew(Page<User> pageList, User user);
+
+    Map<String,Object> sendMobileCode(HashMap<String,String> requestMap) throws OtherException;
+
+    Map<String,Object> getLoginApp(Map<String,String> requestMap);
 }

+ 50 - 2
happy-boot-module-hppay/src/main/java/org/jeecg/modules/user/service/impl/UserServiceImpl.java

@@ -1,29 +1,77 @@
 package org.jeecg.modules.user.service.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.jeecg.common.sms.SMS253Utils;
+import org.jeecg.common.sms.SMSConst;
+import org.jeecg.common.util.OtherException;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.common.util.StringUtils;
 import org.jeecg.modules.hpposition.mapper.PositionMapper;
 import org.jeecg.modules.user.entity.User;
 import org.jeecg.modules.user.mapper.UserMapper;
 import org.jeecg.modules.user.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
 
 /**
  * @Description: 用户审核
  * @Author: jeecg-boot
- * @Date:   2019-05-30
+ * @Date: 2019-05-30
  * @Version: V1.0
  */
 @Service
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
     @Resource
     private UserMapper userMapper;
+    @Autowired
+    private RedisUtil redisUtil;
 
     @Override
     public Page<User> queryPageListNew(Page<User> page, User user) {
-        return userMapper.queryPageListNew(page,user);
+        return userMapper.queryPageListNew(page, user);
+    }
+
+    @Override
+    public Map<String, Object> sendMobileCode(HashMap<String, String> requestMap) throws OtherException {
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        String mobile = requestMap.get("phone");
+        if (StringUtils.isNotEmpty(mobile)) {
+            try {
+                Random random = new Random();
+                String code = "";
+                for (int i = 0; i < 6; i++) {
+                    code += random.nextInt(10);
+                }
+                HashMap<String, String> hashMaps = new HashMap<String, String>();
+                hashMaps.put("phone", mobile);// 手机号码
+                hashMaps.put("msg", "亲爱的用户,您的验证码是" + code + ",如非本人操作请忽略!");
+                returnMap = SMS253Utils.sendSms(hashMaps);
+                if (SMSConst.OKCode.equals(returnMap.get("success"))) {
+                    returnMap.put("code", code);
+                    //将获取到的验证码存到redis中
+                    redisUtil.set(mobile, code);
+                }
+            } catch (Exception e) {
+                throw new OtherException("10000", "系统内部错误!");
+            }
+        }
+        return returnMap;
+    }
+
+    @Override
+    @Transactional
+    public Map<String, Object> getLoginApp(Map<String, String> requestMap) {
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        String mobile = requestMap.get("phone");
+        String clientId = requestMap.get("client_id");
+        return returnMap;
     }
 }

+ 8 - 0
happy-boot-module-hppay/src/main/resources/application-dev.yml

@@ -116,4 +116,12 @@ jeecg :
     accessKeyId: LTAIdrFEg3iDHDzd
     accessKeySecret: 72NuLZN12fVHLstI3iQdn13XGKSrpx
     bucketName: hpjobtest
+  sms :
+    #用户在253云通讯平台上申请的API账号  例如:N6000001
+    account: N3241700
+    #用户在253云通讯平台上申请的API账号对应的API密钥 例如:123456
+    password: O04MCJiBLc6b64
+    smsUrl: http://smssh1.253.com/msg/send/json
+    #253云通讯平台上配置签名
+    smsSign: %e3%80%90%e5%bc%80%e5%bf%83%e5%b7%a5%e4%bd%9c%e3%80%91
 

+ 7 - 0
pom.xml

@@ -59,6 +59,7 @@
         <mybatis-plus.version>3.0.6</mybatis-plus.version>
         <druid.version>1.1.10</druid.version>
         <commons.version>2.6</commons.version>
+		<okhttp-version>3.11.0</okhttp-version>
     </properties>
     
 	<dependencies>
@@ -243,6 +244,12 @@
 			<artifactId>aliyun-sdk-oss</artifactId>
 			<version>2.6.0</version>
 		</dependency>
+
+		<dependency>
+			<groupId>com.squareup.okhttp3</groupId>
+			<artifactId>okhttp</artifactId>
+			<version>${okhttp-version}</version>
+		</dependency>
 	</dependencies>
 
 	<dependencyManagement>