From 2176d7dde4f16970e2840d810d9ef91a91e41ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AE=87=E8=88=AA?= <19856072110@163.com> Date: Tue, 17 Dec 2024 10:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wsk/controller/SendEmailController.java | 131 ++++++++++++++++++ src/main/java/com/wsk/dao/ShopCarMapper.java | 23 +++ src/main/java/com/wsk/pojo/ShopCar.java | 46 ++++++ .../java/com/wsk/service/ShopCarService.java | 26 ++++ 4 files changed, 226 insertions(+) create mode 100644 src/main/java/com/wsk/controller/SendEmailController.java create mode 100644 src/main/java/com/wsk/dao/ShopCarMapper.java create mode 100644 src/main/java/com/wsk/pojo/ShopCar.java create mode 100644 src/main/java/com/wsk/service/ShopCarService.java diff --git a/src/main/java/com/wsk/controller/SendEmailController.java b/src/main/java/com/wsk/controller/SendEmailController.java new file mode 100644 index 0000000..db1d828 --- /dev/null +++ b/src/main/java/com/wsk/controller/SendEmailController.java @@ -0,0 +1,131 @@ +package com.wsk.controller; + +import com.wsk.pojo.UserInformation; +import com.wsk.response.BaseResponse; +import com.wsk.service.UserInformationService; +import com.wsk.tool.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Random; + +/** + * Created by wsk1103 on 2017/4/30. + */ +@Controller +public class SendEmailController { + + @Resource + private UserInformationService userInformationService; + private static final Logger log = LoggerFactory.getLogger(SendEmailController.class); + + //send the Email to the phone + @RequestMapping(value = "sendCode.do", method = {RequestMethod.POST, RequestMethod.GET}) + @ResponseBody + public BaseResponse sendEmail(HttpServletRequest req, HttpServletResponse res, + @RequestParam String phone, @RequestParam String action, + @RequestParam String token) { + res.setContentType("text/html;charset=UTF-8"); + //token,防止重复提交 + String sendCodeToken = (String) req.getSession().getAttribute("token"); + if (StringUtils.getInstance().isNullOrEmpty(sendCodeToken) || !sendCodeToken.equals(token)) { + return BaseResponse.fail(); + } + //判断手机号码是否为正确 + if (!StringUtils.getInstance().isPhone(phone)) { + return BaseResponse.fail(); + } + //如果是忘记密码提交的发送短信 + if ("forget".equals(action)) { + if (!isUserPhoneExists(phone)) { + //失败 + return BaseResponse.fail(); + } + } else if ("register".equals(action)) { + //失败 + if (isUserPhoneExists(phone)) { + return BaseResponse.fail(); + } + } + //get the random num to phone which should check the phone to judge the phone is belong user + getRandomForCodePhone(req); + String ra = (String) req.getSession().getAttribute("codePhone"); + String text1 = "【WSK的验证码】您的验证码是:"; + String text2 = ",请保护好自己的验证码。"; + String text = text1 + ra + text2; + Properties prop = new Properties(); + prop.setProperty("mail.host", "smtp.139.com"); + prop.setProperty("mail.transport.protocol", "smtp"); + prop.setProperty("mail.smtp.auth", "true"); + prop.setProperty("mail.smtp.port", "25"); + try { + String realPhone = phone; +// phone += "@139.com"; +// message.setRecipient(Message.RecipientType.TO, new InternetAddress(phone)); +// message.setSubject("来自WSK的验证码"); +// message.setContent(text, "text/html;charset=UTF-8"); + //这里先不发生信息,以后要开启的 +// ts.sendMessage(message, message.getAllRecipients()); +// ts.close(); + req.getSession().setAttribute("phone", realPhone); + return BaseResponse.success(); + } catch (Exception me) { + me.printStackTrace(); + return BaseResponse.fail(); + } + } + + // get the random phone`s code + private void getRandomForCodePhone(HttpServletRequest req) { + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 4; i++) { + sb.append(random.nextInt(10)); + } + log.info("短信验证码={}", sb); + System.out.println(sb.toString()); + req.getSession().setAttribute("codePhone", sb.toString()); + } + +// //检验验证码 +// private boolean checkPhoto(String photo, HttpServletRequest request) { +// photo = photo.toLowerCase(); +// String true_photo = (String) request.getSession().getAttribute("rand"); +// return true_photo.equals(photo); +// } + + //To determine whether the user's mobile phone number exists + private boolean isUserPhoneExists(String phone) { + boolean result = false; + try { + int id = userInformationService.selectIdByPhone(phone); + if (id == 0) { + return result; + } + UserInformation userInformation = userInformationService.selectByPrimaryKey(id); + + if (StringUtils.getInstance().isNullOrEmpty(userInformation)) { + return false; + } + String userPhone = userInformation.getPhone(); + result = !userPhone.equals(""); + } catch (Exception e) { + e.printStackTrace(); + return result; + } + return result; + } + + +} diff --git a/src/main/java/com/wsk/dao/ShopCarMapper.java b/src/main/java/com/wsk/dao/ShopCarMapper.java new file mode 100644 index 0000000..6d535a9 --- /dev/null +++ b/src/main/java/com/wsk/dao/ShopCarMapper.java @@ -0,0 +1,23 @@ +package com.wsk.dao; + +import com.wsk.pojo.ShopCar; + +public interface ShopCarMapper { + int deleteByPrimaryKey(Integer id); + + int insert(ShopCar record); + + int insertSelective(ShopCar record); + + ShopCar selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(ShopCar record); + + int updateByPrimaryKey(ShopCar record); + + int getCounts(int uid); + +// List selectByUid(int uid, int start); + + ShopCar selectByUid(int uid); +} \ No newline at end of file diff --git a/src/main/java/com/wsk/pojo/ShopCar.java b/src/main/java/com/wsk/pojo/ShopCar.java new file mode 100644 index 0000000..c8cd854 --- /dev/null +++ b/src/main/java/com/wsk/pojo/ShopCar.java @@ -0,0 +1,46 @@ +package com.wsk.pojo; + +import java.io.Serializable; +import java.util.Date; + +public class ShopCar implements Serializable { + private Integer id; + + private Date modified; + + private Integer display; + + private Integer uid; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Date getModified() { + return modified == null ? null : (Date) modified.clone(); + } + + public void setModified(Date modified) { + this.modified = modified == null ? null : (Date) modified.clone(); + } + + public Integer getDisplay() { + return display; + } + + public void setDisplay(Integer display) { + this.display = display; + } + + public Integer getUid() { + return uid; + } + + public void setUid(Integer uid) { + this.uid = uid; + } +} \ No newline at end of file diff --git a/src/main/java/com/wsk/service/ShopCarService.java b/src/main/java/com/wsk/service/ShopCarService.java new file mode 100644 index 0000000..98455ee --- /dev/null +++ b/src/main/java/com/wsk/service/ShopCarService.java @@ -0,0 +1,26 @@ +package com.wsk.service; + +import com.wsk.pojo.ShopCar; + +/** + * Created by wsk1103 on 2017/5/13. + */ +public interface ShopCarService { + int deleteByPrimaryKey(Integer id); + + int insert(ShopCar record); + + int insertSelective(ShopCar record); + + ShopCar selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(ShopCar record); + + int updateByPrimaryKey(ShopCar record); + + int getCounts(int uid); + +// List selectByUid(int uid, int start); + + ShopCar selectByUid(int uid); +}