Bladeren bron

短信代码迁移、优化充值审核页面

yjwang 2 weken geleden
bovenliggende
commit
76c07505df

+ 25 - 0
fs-service/src/main/java/com/fs/common/VerifyCodeUtil.java

@@ -0,0 +1,25 @@
+package com.fs.common;
+
+import java.security.SecureRandom;
+
+public class VerifyCodeUtil {
+
+    // 使用 SecureRandom 保证安全性
+    private static final SecureRandom random = new SecureRandom();
+
+    /**
+     * 生成随机 6 位数字验证码
+     * @return 六位验证码字符串
+     */
+    public static String generateCode() {
+        int code = 100000 + random.nextInt(900000); // 保证是六位数,范围 100000-999999
+        return String.valueOf(code);
+    }
+
+    public static void main(String[] args) {
+        // 测试
+        for (int i = 0; i < 5; i++) {
+            System.out.println(VerifyCodeUtil.generateCode());
+        }
+    }
+}

+ 2 - 0
fs-service/src/main/java/com/fs/common/service/ISmsService.java

@@ -21,4 +21,6 @@ public interface ISmsService
     R sendOrderMsg(SmsSendUserParam param);
 
     R sendPackageOrderMsg(SmsSendUserParam param);
+
+    R sendCaptcha(String phone, String captcha, String code,String type);
 }

+ 86 - 0
fs-service/src/main/java/com/fs/common/service/impl/SmsServiceImpl.java

@@ -36,6 +36,7 @@ import com.fs.system.domain.SysConfig;
 import com.fs.system.mapper.SysConfigMapper;
 import com.google.gson.Gson;
 import lombok.Synchronized;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -48,6 +49,7 @@ import java.util.Date;
 import java.util.List;
 
 @Service
+@Slf4j
 public class SmsServiceImpl implements ISmsService
 {
     @Autowired
@@ -664,4 +666,88 @@ public class SmsServiceImpl implements ISmsService
 
         }
     }
+
+    @Override
+    public R sendCaptcha(String phone, String captcha, String code,String type) {
+        log.info(captcha);
+        CompanySmsTemp temp = smsTempService.selectCompanySmsTempByCode(code);
+        if (temp == null) {
+            return R.error("没有模板");
+        }
+        String content = temp.getContent();
+        if (StringUtils.isNotEmpty(captcha)) {
+            content = content.replace("${sms.captcha}", captcha);
+        }
+        String urls = null;
+        SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.sms");
+        FsSmsConfig sms = JSON.parseObject(sysConfig.getConfigValue(), FsSmsConfig.class);
+        if (sms.getType().equals("rf")) {
+            try {
+                content = content.replace("${sms.sign}",sms.getRfSign());
+                if("1".equals(type)){
+                    urls = sms.getRfUrl1() + "sms?action=send&account=" + sms.getRfAccount1() + "&password=" + sms.getRfPassword1() + "&mobile=" + phone + "&content=" + URLEncoder.encode(content, "UTF-8") + "&extno=" + sms.getRfCode1() + "&rt=json";
+                } else if("2".equals(type)){
+                    urls = sms.getRfUrl3() + "sms?action=send&account=" + sms.getRfAccount3() + "&password=" + sms.getRfPassword3() + "&mobile=" + phone + "&content=" + URLEncoder.encode(content, "UTF-8") + "&extno=" + sms.getRfCode3() + "&rt=json";
+                }
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            String post = HttpRequest.get(urls)
+                    .execute().body();
+            SmsSendVO vo = JSONUtil.toBean(post, SmsSendVO.class);
+            if (vo.getStatus().equals(0)) {
+                for (SmsSendItemVO itemVO : vo.getList()) {
+                    if (itemVO.getResult().equals("0")) {
+                        CompanySmsLogs logs = new CompanySmsLogs();
+                        logs.setContent(content);
+                        logs.setTempCode(temp.getTempCode());
+                        logs.setTempId(temp.getTempId());
+                        logs.setPhone(phone);
+                        logs.setSendTime(new Date());
+                        logs.setStatus(0);
+                        logs.setType(sms.getType());
+                        logs.setMid(itemVO.getMid());
+                        Integer counts = logs.getContent().length() / 67;
+                        if (logs.getContent().length() % 67 > 0) {
+                            counts = counts + 1;
+                        }
+                        if (counts == 0) {
+                            counts = 1;
+                        }
+                        logs.setNumber(counts);
+                        smsLogsService.insertCompanySmsLogs(logs);
+                    }
+                }
+            }
+        } else if (sms.getType().equals("dh")) {
+            SendSmsReturn sendSmsReturn = null;
+            content = content.replace("${sms.sign}",sms.getDhSign());
+            sendSmsReturn = smsTService.sendSms(sms.getDhAccount1(), sms.getDhPassword1(), content, phone);
+            if (sendSmsReturn != null) {
+                if (sendSmsReturn.getResult() != null && sendSmsReturn.getResult().equals("0")) {
+                    CompanySmsLogs logs = new CompanySmsLogs();
+                    logs.setContent(content);
+                    logs.setTempCode(temp.getTempCode());
+                    logs.setTempId(temp.getTempId());
+                    logs.setPhone(phone);
+                    logs.setSendTime(new Date());
+                    logs.setStatus(0);
+                    logs.setType(sms.getType());
+                    logs.setMid(sendSmsReturn.getMsgid());
+                    Integer counts = logs.getContent().length() / 67;
+                    if (logs.getContent().length() % 67 > 0) {
+                        counts = counts + 1;
+                    }
+                    if (counts == 0) {
+                        counts = 1;
+                    }
+                    logs.setNumber(counts);
+                    smsLogsService.insertCompanySmsLogs(logs);
+                }
+            }
+        }
+
+
+        return R.ok();
+    }
 }

+ 8 - 1
fs-service/src/main/java/com/fs/company/mapper/CompanyRechargeMapper.java

@@ -128,8 +128,9 @@ public interface CompanyRechargeMapper
     List<CompanyRechargeExportVO> selectCompanyRechargeExportList(@Param("maps") CompanyRecharge companyRecharge);
 
     @Select({"<script> " +
-            "select r.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
+            "select r.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name,sd.dept_name  " +
             "from company_recharge r left join company c on c.company_id=r.company_id " +
+            "LEFT JOIN sys_dept sd ON c.dept_id = sd.dept_id "+
             " left join sys_user su1 on su1.user_id=r.create_user_id " +
             " left join sys_user su2 on su2.user_id=r.audit_user_id " +
             "where 1=1 " +
@@ -152,12 +153,18 @@ public interface CompanyRechargeMapper
             "and r.pay_type = #{maps.payType}" +
             "</if>" +
 
+            "<if test = 'maps.auditTime != null  '> " +
+            "and  r.audit_time >= #{maps.auditTime}" +
+            "</if>" +
             "<if test = 'maps.createTime != null  '> " +
             "and   DATE(r.create_time) = DATE(#{maps.createTime})" +
             "</if>" +
             "<if test = 'maps.companyName != null  '> " +
             "and c.company_name like concat('%', #{maps.companyName }, '%')" +
             "</if>" +
+            "<if test = 'maps.deptName != null  '> " +
+            "and sd.dept_name like concat('%', #{maps.deptName }, '%')" +
+            "</if>" +
 //            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
 //            "and date_format(r.pay_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d') " +
 //            "</if>" +

+ 3 - 0
fs-service/src/main/java/com/fs/company/vo/CompanyRechargeVO.java

@@ -47,6 +47,9 @@ public class CompanyRechargeVO implements Serializable {
     @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date createTime;
 
+    @Excel(name = "部门名称")
+    private String deptName;
+
     /**
      * 支付时间
      */

+ 4 - 0
fs-service/src/main/java/com/fs/his/config/FsSmsConfig.java

@@ -13,6 +13,10 @@ public class FsSmsConfig {
     private String rfCode2;
     private String rfPassword2;
     private String rfUrl2;
+    private String rfAccount3;
+    private String rfCode3;
+    private String rfPassword3;
+    private String rfUrl3;
     private String rfSign;
 
     private String dhAccount1;

+ 2 - 0
fs-service/src/main/java/com/fs/his/mapper/FsUserMapper.java

@@ -451,4 +451,6 @@ public interface FsUserMapper
      * @return  FsUser
      * **/
     FsUser getUserLookAppIdByuserId(@Param("userId") Long userId);
+
+    List<FsUser> selectFsUserListByPhone(String phone);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/his/service/IFsUserService.java

@@ -247,4 +247,6 @@ public interface IFsUserService
      * @return R
      * **/
     R addUserAndSaleFriend(FsUser user,Long compayUserId, Long externalUserId);
+
+    List<FsUser> selectFsUserListByPhone(String phone);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsUserServiceImpl.java

@@ -1480,4 +1480,9 @@ public class FsUserServiceImpl implements IFsUserService {
         }
         return R.ok();
     }
+
+    @Override
+    public List<FsUser> selectFsUserListByPhone(String phone) {
+        return fsUserMapper.selectFsUserListByPhone(phone);
+    }
 }

+ 21 - 0
fs-service/src/main/java/com/fs/his/utils/PhoneUtil.java

@@ -78,6 +78,27 @@ public class PhoneUtil {
         return text;
     }
 
+    /**
+     * 用于查询 使用老的数据加密
+     * @param text
+     * @return
+     */
+    private static String OLD_KEY = "2c8d1a7f4e9b3c6ae6d5c4b3a291f8c9";
+    public static String encryptPhoneOldKey(String text) {
+        String encryptedText=null;
+        try {
+            SecretKeySpec secretKey = new SecretKeySpec(OLD_KEY.getBytes(), "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            // Encryption
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+            byte[] encryptedBytes = cipher.doFinal(text.getBytes());
+            encryptedText = Base64.getEncoder().encodeToString(encryptedBytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return encryptedText;
+    }
+
     public static void main(String[] args) {
         System.out.println(encryptPhone("18580395185"));
     }

+ 3 - 0
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -2306,4 +2306,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             fu.user_id = #{userId}
     </select>
 
+    <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
+        select * from fs_user where phone=#{phone}
+    </select>
 </mapper>

+ 130 - 4
fs-user-app/src/main/java/com/fs/app/controller/AppLoginController.java

@@ -1,13 +1,16 @@
 package com.fs.app.controller;
 
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
 import com.fs.app.annotation.Login;
 import com.fs.app.param.*;
 import com.fs.app.utils.WxUtil;
+import com.fs.common.VerifyCodeUtil;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.service.ISmsService;
 import com.fs.common.utils.sign.Md5Utils;
 import com.fs.core.config.WxOpenProperties;
 import com.fs.his.config.FsSysConfig;
@@ -35,13 +38,11 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 import static com.fs.his.utils.PhoneUtil.encryptPhone;
+import static com.fs.his.utils.PhoneUtil.encryptPhoneOldKey;
 
 @Api("app登录接口")
 @RestController
@@ -60,6 +61,10 @@ public class AppLoginController extends AppBaseController{
 
     @Autowired
     private RedisCache redisCache;
+
+    @Autowired
+    private ISmsService smsService;
+
     @ApiOperation("注册app用户")
     @PostMapping("/register")
     @RepeatSubmit
@@ -543,4 +548,125 @@ public class AppLoginController extends AppBaseController{
         // 不存在,追加到末尾
         return currentAppIds + "," + newAppId;
     }
+
+    @PostMapping("/sendCode")
+    public R sendCode(@RequestBody Map<String, String> body){
+        String phone = body.get("phone");
+        String type = body.get("type");
+        if(StringUtils.isEmpty(type)){
+            return R.error("请选择验证码类型");
+        }
+
+//        String encryptPhone = encryptPhone(phone);
+//        List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
+//        if(CollectionUtil.isEmpty(user)){
+//            user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
+//        }
+//        if (CollectionUtil.isEmpty(user)){
+//            return R.error("此电话号码未绑定用户");
+//        }
+
+        // 验证码 key(3分钟有效)
+        String smsCodeKey = "sms:code:" + phone;
+        // 冷却 key(60秒内不能重复发送)
+        String smsCooldownKey = "sms:cooldown:" + phone;
+
+        // 判断是否在 60 秒冷却期
+        if (redisCache.getCacheObject(smsCooldownKey) != null) {
+            return R.error("验证码已发送,请稍后再试");
+        }
+
+        // 生成新验证码
+        String smsCode = VerifyCodeUtil.generateCode();
+
+        // 发送短信
+        smsService.sendCaptcha(phone, smsCode, "验证码",type);
+
+        // 缓存验证码(3分钟有效)
+        redisCache.setCacheObject(smsCodeKey, smsCode, 180, TimeUnit.SECONDS);
+        // 设置冷却时间(60秒内不能再发)
+        redisCache.setCacheObject(smsCooldownKey, "1", 60, TimeUnit.SECONDS);
+
+        return R.ok("验证码已发送");
+    }
+
+    @PostMapping("/registerSendCode")
+    public R registerSendCode(@RequestBody Map<String, String> body){
+        String phone = body.get("phone");
+        String type = body.get("type");
+        if(StringUtils.isEmpty(type)){
+            return R.error("请选择验证码类型");
+        }
+
+        String encryptPhone = encryptPhone(phone);
+        List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
+        if(CollectionUtil.isEmpty(user)){
+            user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
+        }
+        if (!CollectionUtil.isEmpty(user)){
+            return R.error("此电话号码已注册");
+        }
+
+        // 验证码 key(存验证码,3分钟有效)
+        String smsCodeKey = "sms:code:" + phone;
+        // 发送冷却 key(限制60秒内不能再次发送)
+        String smsCooldownKey = "sms:cooldown:" + phone;
+
+        // 判断是否在60秒冷却时间内
+        if (redisCache.getCacheObject(smsCooldownKey) != null) {
+            return R.error("验证码已发送,请稍后再试");
+        }
+
+        // 生成新的验证码
+        String smsCode = VerifyCodeUtil.generateCode();
+
+        // 发送短信
+        smsService.sendCaptcha(phone, smsCode, "验证码",type);
+
+        // 缓存验证码(3分钟有效)
+        redisCache.setCacheObject(smsCodeKey, smsCode, 180, TimeUnit.SECONDS);
+        // 设置冷却时间(60秒内不能再发)
+        redisCache.setCacheObject(smsCooldownKey, "1", 60, TimeUnit.SECONDS);
+
+        return R.ok("验证码已发送");
+    }
+
+    @PostMapping("/registerByPhone")
+    public R registerByPhone(@RequestBody Map<String,String> map){
+        String phone = map.get("phone");
+        String code = map.get("code");
+        String password = map.get("password");
+        String encryptPhone = encryptPhone(phone);
+        List<FsUser> users = userService.selectFsUserListByPhone(encryptPhone);
+        if (users == null || CollectionUtil.isEmpty(users)){
+            String s = encryptPhoneOldKey(phone);
+            users = userService.selectFsUserListByPhone(s);
+        }
+        if (!CollectionUtil.isEmpty(users)){
+            return R.error("此账号已经注册");
+        }
+        String redisCode = redisCache.getCacheObject("sms:code:" + phone);
+        if (StringUtils.isEmpty(redisCode)){
+            return R.error("验证码已过期,请重新发送");
+        }
+        if (!redisCode.equals(code)) {
+            return R.error("验证码错误");
+        }
+        FsUser user = new FsUser();
+        // 创建新用户
+        user.setPhone(phone);
+        user.setJpushId(map.get("jpushId"));
+        user.setSource(map.get("source"));
+        user.setNickName("app用户" + phone.substring(phone.length() - 4));
+        user.setStatus(1);
+        user.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
+        user.setPassword(Md5Utils.hash(password));
+        user.setCreateTime(new Date());
+        if (userService.insertFsUser(user) > 0) {
+            return R.ok("注册成功");
+        } else {
+            return R.error("注册失败");
+        }
+    }
+
 }