Browse Source

Merge remote-tracking branch 'origin/feature-201823-wangcz' into feature-201823-wangcz

wangcz 7 years ago
parent
commit
b4d64aac7b

+ 1 - 0
pom.xml

@@ -393,6 +393,7 @@
 			<groupId>com.uas.dfs</groupId>
 			<groupId>com.uas.dfs</groupId>
 			<artifactId>dfs-api</artifactId>
 			<artifactId>dfs-api</artifactId>
 		</dependency>
 		</dependency>
+
 		<!-- search -->
 		<!-- search -->
 		<dependency>
 		<dependency>
 			<groupId>com.uas.search</groupId>
 			<groupId>com.uas.search</groupId>

+ 43 - 2
src/main/java/com/uas/platform/b2c/common/weixin/contoller/WeChatController.java

@@ -1,15 +1,18 @@
 package com.uas.platform.b2c.common.weixin.contoller;
 package com.uas.platform.b2c.common.weixin.contoller;
 
 
-import com.uas.platform.b2c.common.account.model.User;
+import com.uas.platform.b2c.common.account.service.UserService;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
+import com.uas.platform.b2c.common.weixin.model.UserVo;
 import com.uas.platform.b2c.common.weixin.service.WeChatService;
 import com.uas.platform.b2c.common.weixin.service.WeChatService;
 import com.uas.platform.b2c.common.weixin.util.CheckoutUtil;
 import com.uas.platform.b2c.common.weixin.util.CheckoutUtil;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.Model;
 import org.springframework.ui.Model;
 import org.springframework.ui.ModelMap;
 import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -32,10 +35,20 @@ public class WeChatController {
 
 
     private Logger logger = LoggerFactory.getLogger(WeChatController.class);
     private Logger logger = LoggerFactory.getLogger(WeChatController.class);
 
 
+    protected static ModelMap success(Object data) {
+        return new ModelMap("success", true).addAttribute("content", data);
+    }
+
+    protected static ModelMap error(String errMsg) {
+        return new ModelMap("error", true).addAttribute("errMsg", errMsg);
+    }
 
 
     @Autowired
     @Autowired
     private WeChatService weChatService;
     private WeChatService weChatService;
 
 
+    @Autowired
+    private UserService userService;
+
     /**
     /**
      * 与微信服务器接口配置
      * 与微信服务器接口配置
      *
      *
@@ -98,8 +111,36 @@ public class WeChatController {
      * @return
      * @return
      */
      */
     @RequestMapping(value = "/bindUser", method = RequestMethod.POST)
     @RequestMapping(value = "/bindUser", method = RequestMethod.POST)
-    public ModelMap bindUser(@RequestBody User user) {
+    public ModelMap bindUser(@RequestBody UserVo user) {
         logger.info("绑定用户 userUU: {}", user.getUserUU());
         logger.info("绑定用户 userUU: {}", user.getUserUU());
         return weChatService.bindUser(user);
         return weChatService.bindUser(user);
     }
     }
+
+    /**
+     * 发送手机验证码
+     * @param mobile 手机号
+     * @return
+     */
+    @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET)
+    public ModelMap sendSmsCode(String mobile) {
+        // 验证手机号是否为空
+        mobile = StringUtils.trimAllWhitespace(mobile);
+        if (StringUtils.isEmpty(mobile)) {
+            return error("手机号不能为空");
+        }
+        // 验证是否存在该用户
+        try {
+            userService.findUserByUserTel(mobile);
+        } catch (Exception e) {
+            return error(e.getMessage());
+        }
+
+        // 随机获得验证码
+        String code = StringUtilB2C.getRandomNumber(6);
+        logger.info("用户:{} 发送验证码,code:{}", mobile, code);
+
+        weChatService.sendSMS(mobile, code);
+        return success("发送成功");
+    }
+
 }
 }

+ 21 - 0
src/main/java/com/uas/platform/b2c/common/weixin/model/UserVo.java

@@ -0,0 +1,21 @@
+package com.uas.platform.b2c.common.weixin.model;
+
+import com.uas.platform.b2c.common.account.model.User;
+
+/**
+ * 验证码 user 包装类
+ * @author liuam
+ * @since 2018/8/14 0014 下午 17:56
+ */
+public class UserVo extends User {
+
+    private String code;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+}

+ 17 - 2
src/main/java/com/uas/platform/b2c/common/weixin/service/WeChatService.java

@@ -1,7 +1,7 @@
 package com.uas.platform.b2c.common.weixin.service;
 package com.uas.platform.b2c.common.weixin.service;
 
 
-import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
+import com.uas.platform.b2c.common.weixin.model.UserVo;
 import org.springframework.ui.ModelMap;
 import org.springframework.ui.ModelMap;
 
 
 import java.util.List;
 import java.util.List;
@@ -33,5 +33,20 @@ public interface WeChatService {
      * @param user
      * @param user
      * @return
      * @return
      */
      */
-    ModelMap bindUser(User user);
+    ModelMap bindUser(UserVo user);
+
+    /**
+     * 发送验证码
+     * @param mobile 手机号
+     * @param code 验证码
+     */
+    void sendSMS(String mobile, String code);
+
+    /**
+     * 对验证码进行验证
+     * @param mobile 手机号
+     * @param code 需要验证的验证码
+     * @return true 验证成功
+     */
+    boolean verifyCode(String mobile, String code);
 }
 }

+ 52 - 6
src/main/java/com/uas/platform/b2c/common/weixin/service/impl/WeChatServiceImpl.java

@@ -5,6 +5,7 @@ import com.uas.platform.b2c.common.account.model.Enterprise;
 import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.common.weixin.exception.WeChatException;
 import com.uas.platform.b2c.common.weixin.exception.WeChatException;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
 import com.uas.platform.b2c.common.weixin.model.MessageModel;
+import com.uas.platform.b2c.common.weixin.model.UserVo;
 import com.uas.platform.b2c.common.weixin.model.req.AuthTokenParams;
 import com.uas.platform.b2c.common.weixin.model.req.AuthTokenParams;
 import com.uas.platform.b2c.common.weixin.model.req.AuthUserParams;
 import com.uas.platform.b2c.common.weixin.model.req.AuthUserParams;
 import com.uas.platform.b2c.common.weixin.model.req.WechatTemplateMsg;
 import com.uas.platform.b2c.common.weixin.model.req.WechatTemplateMsg;
@@ -15,6 +16,7 @@ import com.uas.platform.b2c.common.weixin.model.resp.TemplateMsgResult;
 import com.uas.platform.b2c.common.weixin.service.WeChatService;
 import com.uas.platform.b2c.common.weixin.service.WeChatService;
 import com.uas.platform.b2c.common.weixin.util.HttpReqUtil;
 import com.uas.platform.b2c.common.weixin.util.HttpReqUtil;
 import com.uas.platform.b2c.common.weixin.util.WeChatUtil;
 import com.uas.platform.b2c.common.weixin.util.WeChatUtil;
+import com.uas.platform.b2c.core.utils.MessageUtils;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import com.uas.sso.entity.UserAccount;
 import com.uas.sso.entity.UserAccount;
@@ -51,10 +53,15 @@ public class WeChatServiceImpl implements WeChatService{
     private Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class);
     private Logger logger = LoggerFactory.getLogger(WeChatServiceImpl.class);
 
 
     /**
     /**
-     * 保存到 redis 里的过期时间(second)
+     * 保存到 redis 里的 ACCESS_TOKEN 过期时间(second)
      */
      */
     private static final Integer ACCESS_TOKEN_EXPIRES_IN = 3600;
     private static final Integer ACCESS_TOKEN_EXPIRES_IN = 3600;
 
 
+    /**
+     * 保存到 redis 里的验证码过期时间(second)
+     */
+    private static final Integer SMS_EXPIRES_IN = 10 * 60;
+
     @Override
     @Override
     public ModelMap getWxUserInfo(String code, String state, String openId) {
     public ModelMap getWxUserInfo(String code, String state, String openId) {
         logger.info("得到用户信息 code: {}, state: {}, openId: {}", code, state, openId);
         logger.info("得到用户信息 code: {}, state: {}, openId: {}", code, state, openId);
@@ -155,12 +162,19 @@ public class WeChatServiceImpl implements WeChatService{
      * @return
      * @return
      */
      */
     @Override
     @Override
-    public ModelMap bindUser(User user) {
+    public ModelMap bindUser(UserVo user) {
         logger.info("微信绑定用户 userUU: {}", user.getUserUU());
         logger.info("微信绑定用户 userUU: {}", user.getUserUU());
         ModelMap result = new ModelMap();
         ModelMap result = new ModelMap();
         // 账户中心校验手机号和密码是否正确
         // 账户中心校验手机号和密码是否正确
         if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUserTel()) || StringUtils.isEmpty(user.getUserPwd()) || StringUtils.isEmpty(user.getOpenId())) {
         if (StringUtils.isEmpty(user) || StringUtils.isEmpty(user.getUserTel()) || StringUtils.isEmpty(user.getUserPwd()) || StringUtils.isEmpty(user.getOpenId())) {
-            throw new IllegalOperatorException("信息不完整!");
+            if (StringUtils.isEmpty(user.getCode())) {
+                throw new IllegalOperatorException("信息不完整!");
+            } else {
+                boolean verifyCode = verifyCode(user.getUserTel(), user.getCode());
+                if (!verifyCode) {
+                   return new ModelMap("error", true).addAttribute("errMsg", "验证码错误");
+                }
+            }
         }
         }
         // 是否存在用户信息
         // 是否存在用户信息
         List<User> oldUsers = userDao.findUserByUserTel(user.getUserTel());
         List<User> oldUsers = userDao.findUserByUserTel(user.getUserTel());
@@ -185,11 +199,11 @@ public class WeChatServiceImpl implements WeChatService{
                 throw new IllegalOperatorException("手机号或密码不正确");
                 throw new IllegalOperatorException("手机号或密码不正确");
             }
             }
             oldUser.setOpenId(user.getOpenId());
             oldUser.setOpenId(user.getOpenId());
-            user = userDao.save(oldUser);
+            User newUser = userDao.save(oldUser);
             // 转成UserAccount便于登录
             // 转成UserAccount便于登录
-            UserAccount userAccount = convertUserAccount(user);
+            UserAccount userAccount = convertUserAccount(newUser);
             // 企业信息单独提出
             // 企业信息单独提出
-            Set<Enterprise> enterprises = user.getEnterprises();
+            Set<Enterprise> enterprises = newUser.getEnterprises();
             result.put("userAccount", userAccount);
             result.put("userAccount", userAccount);
             result.put("enterprises", enterprises);
             result.put("enterprises", enterprises);
             result.put("success", true);
             result.put("success", true);
@@ -202,6 +216,36 @@ public class WeChatServiceImpl implements WeChatService{
         }
         }
     }
     }
 
 
+    /**
+     * 发送验证码
+     * @param mobile 手机号
+     * @param code 验证码
+     */
+    @Override
+    public void sendSMS(String mobile, String code) {
+        redisTemplate.opsForValue().set(mobile, mobile, SMS_EXPIRES_IN, TimeUnit.SECONDS);
+        logger.info("用户:{},验证码:{},redis's key:{},redis's expires_in:{}", mobile, code, mobile, SMS_EXPIRES_IN);
+        MessageUtils.sendSms(mobile, code);
+    }
+
+    /**
+     * 对验证码进行验证
+     * @param mobile 手机号
+     * @param code 需要验证的验证码
+     * @return true 验证成功
+     */
+    @Override
+    public boolean verifyCode(String mobile, String code) {
+        logger.info("WeChatServiceImpl#verifyCode 对验证码进行验证:mobile:{},code:{}", mobile, code);
+        String redisCode = (String) redisTemplate.opsForValue().get(mobile);
+        if (code.equals(redisCode)) {
+            logger.info("WeChatServiceImpl#verifyCode 验证成功:mobile:{},code:{}", mobile, code);
+            return true;
+        }
+        logger.warn("WeChatServiceImpl#verifyCode 验证失败:mobile:{},code:{}", mobile, code);
+        return false;
+    }
+
     /**
     /**
      * 通过code获取用户openId
      * 通过code获取用户openId
      * @param code
      * @param code
@@ -264,4 +308,6 @@ public class WeChatServiceImpl implements WeChatService{
         redisTemplate.opsForValue().set("WX_ACCESS_TOKEN", access_token, ACCESS_TOKEN_EXPIRES_IN, TimeUnit.SECONDS);
         redisTemplate.opsForValue().set("WX_ACCESS_TOKEN", access_token, ACCESS_TOKEN_EXPIRES_IN, TimeUnit.SECONDS);
         return access_token;
         return access_token;
     }
     }
+
+
 }
 }

+ 41 - 0
src/main/java/com/uas/platform/b2c/core/utils/MessageUtils.java

@@ -0,0 +1,41 @@
+package com.uas.platform.b2c.core.utils;
+
+import com.uas.message.sms.service.SmsService;
+import com.uas.platform.b2c.common.base.service.impl.RestSmsServiceImpl;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * @author wangmh
+ * @create 2018-06-05 17:17
+ * @desc 发送验证码工具类
+ **/
+public class MessageUtils {
+
+    private static SmsService smsService;
+
+    static {
+        smsService = ContextUtils.getBean(RestSmsServiceImpl.class);
+    }
+
+    /**
+     * 验证码模板ID
+     */
+    private static String TEMPLATE_ID = "f32af236-7211-4399-bf2c-bee41ed97a32";
+
+    /**
+     * 发送短信
+     * @param mobile 手机号
+     * @param data 发送短信适配数据,按顺序添加
+     */
+    public static void sendSms(String mobile, Object... data) {
+        try {
+            if (!StringUtils.isEmpty(mobile)) {
+                smsService.send(TEMPLATE_ID, mobile, data);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+}

+ 13 - 0
src/main/java/com/uas/platform/b2c/core/utils/StringUtilB2C.java

@@ -405,5 +405,18 @@ public class StringUtilB2C {
 		}
 		}
 	}
 	}
 
 
+	/**
+	 * 随机数字
+	 *
+	 * @param len
+	 *            数字长度
+	 * @return
+	 */
+	public static String getRandomNumber(int len) {
+		int max = (int) Math.pow(10, len) - 1;
+		int min = (int) Math.pow(10, len - 1);
+		return String.valueOf(new Random().nextInt(max) % (max - min + 1) + min);
+	}
+
 
 
 }
 }

+ 16 - 1
src/main/java/com/uas/platform/b2c/prod/product/kind/model/Kind.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.prod.product.kind.model;
 
 
 import com.alibaba.fastjson.annotation.JSONField;
 import com.alibaba.fastjson.annotation.JSONField;
 import com.uas.platform.core.model.Constant;
 import com.uas.platform.core.model.Constant;
+import javax.validation.constraints.NotNull;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
@@ -103,6 +104,13 @@ public class Kind implements Serializable {
 	@Column(name = "ki_search_count")
 	@Column(name = "ki_search_count")
 	private Long searchCount;
 	private Long searchCount;
 
 
+	/**
+	 * 类目图标
+	 */
+	@NotNull
+	@Column(name = "ki_img")
+	private String img = "";
+
 	/**
 	/**
 	 * 包含的属性
 	 * 包含的属性
 	 */
 	 */
@@ -260,7 +268,14 @@ public class Kind implements Serializable {
 		this.searchCount = searchCount;
 		this.searchCount = searchCount;
 	}
 	}
 
 
-	/*
+	public String getImg() {
+		return img;
+	}
+
+	public void setImg(String img) {
+		this.img = img;
+	}
+/*
 	 * public KindUas converUas(Kind kind){ KindUas uas = new KindUas();
 	 * public KindUas converUas(Kind kind){ KindUas uas = new KindUas();
 	 * uas.setComponentPrefix(kind.getComponentPrefix());
 	 * uas.setComponentPrefix(kind.getComponentPrefix());
 	 * uas.setComponentsuffix(kind.getComponentsuffix());
 	 * uas.setComponentsuffix(kind.getComponentsuffix());