Jelajahi Sumber

add email reg

liuchaojie 4 tahun lalu
induk
melakukan
fc9dadd218

+ 33 - 0
src/main/java/com/xc/controller/EmailApiController.java

@@ -0,0 +1,33 @@
+package com.xc.controller;
+
+import com.xc.common.ServerResponse;
+import com.xc.service.EmailService;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping({"/api/email/"})
+public class EmailApiController {
+
+    private static final Logger log = LoggerFactory.getLogger(SmsApiController.class);
+
+    @Autowired
+    EmailService emailService;
+
+    //注册用户 邮件发送
+    @RequestMapping({"sendRegEmail.do"})
+    @ResponseBody
+    public ServerResponse sendRegEmail(String emailAdd) {
+        if (StringUtils.isBlank(emailAdd)) {
+            return ServerResponse.createByErrorMsg("发送失败,邮箱不能为空");
+        }
+        String code = emailService.sendRegEmail(emailAdd);
+        return ServerResponse.createBySuccessMsg("发送成功");
+    }
+
+}

+ 7 - 0
src/main/java/com/xc/service/EmailService.java

@@ -0,0 +1,7 @@
+package com.xc.service;
+
+
+public interface EmailService {
+
+    String sendRegEmail(String emailAdd);
+}

+ 44 - 0
src/main/java/com/xc/service/impl/EmailServiceImpl.java

@@ -0,0 +1,44 @@
+package com.xc.service.impl;
+
+import com.xc.common.ServerResponse;
+import com.xc.dao.SiteSmsLogMapper;
+import com.xc.pojo.SiteSmsLog;
+import com.xc.service.EmailService;
+import com.xc.utils.DateTimeUtil;
+import com.xc.utils.email.MailSender;
+import com.xc.utils.redis.RedisShardedPoolUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class EmailServiceImpl  implements EmailService {
+
+    @Autowired
+    SiteSmsLogMapper siteSmsLogMapper;
+
+    @Override
+    public String sendRegEmail(String emailAdd){
+        String yzmCode = RandomStringUtils.randomNumeric(4);
+        String str = "您的注册验证码为:" + yzmCode;
+        try {
+            (new MailSender.Builder(str, emailAdd)).send();
+            String keys = "AliyunSmsCode:" + emailAdd;
+            RedisShardedPoolUtils.setEx(keys, yzmCode, 5400);
+            if (!StringUtils.isEmpty(yzmCode)) {
+                SiteSmsLog siteSmsLog = new SiteSmsLog();
+                siteSmsLog.setSmsPhone(emailAdd);
+                siteSmsLog.setSmsTitle("注册验证码");
+                siteSmsLog.setSmsCnt(yzmCode);
+                siteSmsLog.setSmsStatus(0);
+                siteSmsLog.setSmsTemplate("字段无用");
+                siteSmsLog.setAddTime(DateTimeUtil.getCurrentDate());
+                siteSmsLogMapper.insert(siteSmsLog);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return yzmCode;
+    }
+}

+ 0 - 20
src/main/java/com/xc/service/impl/UserServiceImpl.java

@@ -103,17 +103,12 @@ public class UserServiceImpl implements IUserService {
         {
             return ServerResponse.createByErrorMsg("注册失败, 参数不能为空");
         }
-
-
         String keys = "AliyunSmsCode:" + phone;
         String redis_yzm = RedisShardedPoolUtils.get(keys);
-
         log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode);
         if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) {
             return ServerResponse.createByErrorMsg("注册失败, 验证码错误");
         }
-
-
         AgentUser agentUser = this.iAgentUserService.findByCode(agentCode);
         if (agentUser == null) {
             return ServerResponse.createByErrorMsg("注册失败, 代理不存在");
@@ -121,48 +116,33 @@ public class UserServiceImpl implements IUserService {
         if (agentUser.getIsLock().intValue() == 1) {
             return ServerResponse.createByErrorMsg("注册失败, 代理已被锁定");
         }
-
-
         User dbuser = this.userMapper.findByPhone(phone);
         if (dbuser != null) {
             return ServerResponse.createByErrorMsg("注册失败, 手机号已注册");
         }
-
-
         User user = new User();
         user.setAgentId(agentUser.getId());
         user.setAgentName(agentUser.getAgentName());
         user.setPhone(phone);
         user.setUserPwd(userPwd);
-
-
         user.setAccountType(Integer.valueOf(0));
         user.setIsLock(Integer.valueOf(1));
         user.setIsActive(Integer.valueOf(0));
-
         user.setRegTime(new Date());
         String uip = IpUtils.getIp(request);
         user.setRegIp(uip);
         String uadd = JuheIpApi.ip2Add(uip);
         user.setRegAddress(uadd);
-
         user.setIsLogin(Integer.valueOf(0));
-
         user.setUserAmt(new BigDecimal("0"));
         user.setEnableAmt(new BigDecimal("0"));
-
         user.setUserIndexAmt(new BigDecimal("0"));
         user.setEnableIndexAmt(new BigDecimal("0"));
-
         user.setUserFutAmt(new BigDecimal("0"));
         user.setEnableFutAmt(new BigDecimal("0"));
-
         user.setSumBuyAmt(new BigDecimal("0"));
         user.setSumChargeAmt(new BigDecimal("0"));
-
-
         int insertCount = this.userMapper.insert(user);
-
         if (insertCount > 0) {
             log.info("用户注册成功 手机 {} , ip = {} 地址 = {}", new Object[] { phone, uip, uadd });
 //            if (user.getAccountType() !=1){

+ 0 - 16
src/main/java/com/xc/utils/email/MailSender.java

@@ -23,55 +23,42 @@ public class MailSender {
         private String auth = "true";
         private String host = "smtp.163.com";
         private String protocol = "smtp";
-
         private String subject = PropertiesUtil.getProperty("admin.auth.email.subject");
-
         private String fromAddress = PropertiesUtil.getProperty("admin.auth.email");
-
         private String fromCount = PropertiesUtil.getProperty("admin.auth.email");
-
         private String fromPassword = PropertiesUtil.getProperty("admin.auth.email.pwd");
-
         public Builder Debug(String debug) {
             this.debug = debug;
             return this;
         }
-
         public Builder Subject(String subject) {
             this.subject = subject;
             return this;
         }
-
         public Builder Auth(String auth) {
             this.auth = auth;
             return this;
         }
-
         public Builder Host(String host) {
             this.host = host;
             return this;
         }
-
         public Builder FromCount(String fromCount) {
             this.fromCount = fromCount;
             return this;
         }
-
         public Builder FromAddress(String fromAddress) {
             this.fromAddress = fromAddress;
             return this;
         }
-
         public Builder FromPassword(String fromPassword) {
             this.fromPassword = fromPassword;
             return this;
         }
-
         public Builder(String mailContent, String toAddress) {
             this.mailContent = mailContent;
             this.toAddress = toAddress;
         }
-
         public Builder Protocol(String protocol) {
             this.protocol = protocol;
             return this;
@@ -93,14 +80,11 @@ public class MailSender {
         this.prop.setProperty("mail.smtp.socketFactory.port", "465");
         this.session = Session.getInstance(this.prop);
         this.msg = (Message) new MimeMessage(this.session);
-
         this.transport = this.session.getTransport();
         this.msg.setSubject(builder.subject);
         this.msg.setFrom((Address) new InternetAddress(builder.fromAddress, "通知邮件"));
         this.transport.connect(builder.fromCount, builder.fromPassword);
-
         this.msg.setContent(builder.mailContent, "text/html;charset=utf-8");
-
         this.transport.sendMessage(this.msg, new Address[]{ new InternetAddress(builder.toAddress)});
     }
 }

+ 4 - 3
src/main/resources/datasource.properties

@@ -5,9 +5,10 @@ db.driverClassName=com.mysql.jdbc.Driver
 #db.url=jdbc:mysql://127.0.0.1:3306/zhishu?characterEncoding=utf-8
 #db.username=zhishu
 #db.password=stock2chen
-db.url=jdbc:mysql://101.33.116.47:3306/zhishu?characterEncoding=utf-8
-db.username=zhishu
-db.password=stock2chen
+db.url=jdbc:mysql://127.0.0.1:3306/stock2coin?characterEncoding=utf-8
+#db.url=jdbc:mysql://101.32.39.134:3306/stock2coin?characterEncoding=utf-8
+db.username=root
+db.password=S5Y2M8MtsRx5RcJG
 
 # 正式服务器
 #db.url=jdbc:mysql://47.74.220.239:3306/stock2chen?characterEncoding=utf-8

+ 5 - 4
src/main/resources/stock2guo.properties

@@ -36,12 +36,13 @@ agent.key.prefix=SR
 admin.super.name=18916320007
 
 #管理 邮箱 - 发件主题
-admin.auth.email.subject=鸿鹄易融 - 支付通知邮件
+admin.auth.email.subject=众想
 #管理 邮箱 - 发件地址
-admin.auth.email=navihold800@163.com
+#admin.auth.email=navihold800@163.com
+admin.auth.email=18317918160@163.com
 #管理 邮箱 - 发件密码  118318asd  XY118318asd
-admin.auth.email.pwd=XY118318asd
-#cookie config end
+admin.auth.email.pwd=173008754
+#cookie config endXY118318asd
 
 # close order task config start
 close.order.task.time.hour=2