Explorar el Código

Merge remote-tracking branch 'origin/master'

yubin hace 3 días
padre
commit
fc4eb05298

+ 35 - 0
cif-service/src/main/java/com/txz/cif/configurer/CSHuaGuConf.java

@@ -0,0 +1,35 @@
+package com.txz.cif.configurer;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * 短信服务配置类
+ *
+ * @author lingma
+ * @date 2025-09-28
+ */
+@Data
+@Component
+@RefreshScope
+@ConfigurationProperties(prefix = "cshg")
+public class CSHuaGuConf {
+    
+    /**
+     * 短信服务API地址
+     */
+    private String apiurl;
+    
+    /**
+     * API密钥
+     */
+    private String apikey;
+    
+    /**
+     * API密钥
+     */
+    private String apisecret;
+    
+}

+ 2 - 0
cif-service/src/main/java/com/txz/cif/constants/RedisConstants.java

@@ -7,5 +7,7 @@ package com.txz.cif.constants;
 public class RedisConstants {
 
   public static final String USER_SMS_CODE = "user:sms:code:%s";
+  
+  public static final String USER_SMS_LOGIN_CODE = "user:sms:login:code:%s";
 
 }

+ 8 - 0
cif-service/src/main/java/com/txz/cif/core/Result.java

@@ -58,6 +58,14 @@ public class Result<T> implements Serializable {
                 .data(data)
                 .build();
     }
+    
+    public static Result fail() {
+        return Result.builder()
+                .code("400")
+                .message("")
+                .data("")
+                .build();
+    }
 
     public static Result fail(String code, String message) {
         return Result.builder()

+ 11 - 0
cif-service/src/main/java/com/txz/cif/service/CSHuaGuService.java

@@ -0,0 +1,11 @@
+package com.txz.cif.service;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/9/28
+ */
+
+public interface CSHuaGuService {
+    
+    boolean sendValidCode(String mobile, String message);
+}

+ 2 - 0
cif-service/src/main/java/com/txz/cif/service/UserService.java

@@ -45,4 +45,6 @@ public interface UserService extends Service<User> {
     //    boolean sendMsg(MessageParam param);
     
     List<UserDTO> getUsersByIds(List<Long> userIds);
+    
+    void delCode(String phoneNo);
 }

+ 51 - 0
cif-service/src/main/java/com/txz/cif/service/impl/CSHuaGuServiceImpl.java

@@ -0,0 +1,51 @@
+package com.txz.cif.service.impl;
+
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.txz.cif.configurer.CSHuaGuConf;
+import com.txz.cif.service.CSHuaGuService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/9/28
+ */
+@Service
+@Slf4j
+@AllArgsConstructor
+public class CSHuaGuServiceImpl implements CSHuaGuService {
+    
+    private final CSHuaGuConf csHuaGuConf;
+    
+    @Override
+    public boolean sendValidCode(String mobile, String message) {
+        log.info("开始发送短信--->" + mobile + ",内容--->" + message);
+        JSONObject body = new JSONObject();
+        body.put("phone", mobile);
+        body.put("context", message);
+        body.put("apikey", csHuaGuConf.getApikey());
+        body.put("secret", csHuaGuConf.getApisecret());
+        String result = "";
+        try {
+            result = HttpUtil.createPost(csHuaGuConf.getApiurl())
+                    .body(body.toJSONString())
+                    .contentType("application/json")
+                    .execute()
+                    .body();
+            // {"code":200,"res":"892352879716536320","error":null,"seqid":null}
+            JSONObject resultJson = JSON.parseObject(result);
+            if (resultJson.getInteger("code") == 200) {
+                log.info("发送短信成功--->" + result);
+                return true;
+            }
+            log.info("发送短信失败--->" + result);
+            return false;
+        } catch (Exception e) {
+            log.error("发送短信异常--->" + result);
+            return false;
+        }
+    }
+}

+ 45 - 27
cif-service/src/main/java/com/txz/cif/service/impl/UserServiceImpl.java

@@ -2,6 +2,7 @@ package com.txz.cif.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
@@ -14,6 +15,7 @@ import com.txz.cif.dubbo.client.OperatingConfigDubboServiceClient;
 import com.txz.cif.model.Account;
 import com.txz.cif.model.User;
 import com.txz.cif.service.AccountService;
+import com.txz.cif.service.CSHuaGuService;
 import com.txz.cif.service.UserService;
 import com.txz.cif.web.para.UserAddParam;
 import org.slf4j.Logger;
@@ -53,6 +55,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
     @Resource
     private OperatingConfigDubboServiceClient messageDubboServiceClient;
     
+    private static final String SMS_MESSAGE = "Your verification code is %s .It will expire in 5 minutes.Do not share it with anyone";
+    
+    @Resource
+    private CSHuaGuService csHuaGuService;
+    
     @Override
     public Boolean checkMail(String email) {
         User user = findBy("email", email);
@@ -66,34 +73,38 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
         return String.format(RedisConstants.USER_SMS_CODE, email);
     }
     
+    private String getSmsKey(String phoneNo) {
+        return String.format(RedisConstants.USER_SMS_LOGIN_CODE, phoneNo);
+    }
+    
     @Override
     public Result<Object> sendCode(String phoneNo) {
-        String key = getKey(phoneNo);
+        String key = this.getSmsKey(phoneNo);
+        Object o = redisClient.get(key);
+        if (ObjectUtil.isNotEmpty(o)) {
+            return Result.success();
+        }
         String code = RandomUtil.randomNumbers(6);
-        String subject = "来自Free City的CODE码";
-        String content = "您的CODE为: " + code;
-        // TODO 发短信
-        //        Result<Object> result = MailClient.send(email, subject, content, null);
-        //        if (result.isSuccess()) {
-        //            redisClient.set(key, code, 60);
-        //        }
-        redisClient.set(key, code, 60);
-        return Result.success(code);
+        if (csHuaGuService.sendValidCode(phoneNo, String.format(SMS_MESSAGE, code))) {
+            redisClient.set(key, code, 60 * 5);
+            return Result.fail();
+        }
+        return Result.success();
     }
     
     @Override
     public Boolean checkCode(String phoneNo, String code) {
-        if (StrUtil.equals("888888", code)) {
-            return true;
-        }
-        log.error("checkCode  phoneNo:" + phoneNo);
-        log.error("checkCode  code:" + code);
-        String key = getKey(phoneNo);
+        // if (StrUtil.equals("888888", code)) {
+        //     return true;
+        // }
+        // log.error("checkCode  phoneNo:" + phoneNo);
+        // log.error("checkCode  code:" + code);
+        String key = this.getSmsKey(phoneNo);
         Object o = redisClient.get(key);
-        if (o != null) {
-            log.error("checkCode  o:" + o.toString());
+        if (ObjectUtil.isEmpty(o)) {
+            return false;
         }
-        if (o != null && StrUtil.equals(o.toString(), code)) {
+        if (StrUtil.equals(o.toString(), code)) {
             return true;
         }
         return false;
@@ -209,16 +220,18 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
         if (user == null) {
             return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
         }
-        //fixme 暂时跳过短验
-        if (!verifyCode.equals("888888")) {
-            String key = getKey(user.getPhoneNo());
-            Object o = redisClient.get(key);
-            if (!StrUtil.equals(o.toString(), verifyCode)) {
-                return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
-            }
+        // if (!verifyCode.equals("888888")) {
+        String key = getSmsKey(user.getAreaCode() + user.getPhoneNo());
+        Object o = redisClient.get(key);
+        if (ObjectUtil.isNull(o)) {
+            return Result.fail();
+        }
+        if (!StrUtil.equals(o.toString(), verifyCode)) {
+            return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
         }
+        // }
         update(User.builder().id(user.getId()).pwd(SecureUtil.md5(newPwd + user.getSalt())).build());
-        
+        redisClient.del(key);
         return Result.success();
     }
     
@@ -227,6 +240,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
         return userMapper.getUsersByIds(Joiner.on(",").join(userIds));
     }
     
+    @Override
+    public void delCode(String phoneNo) {
+        redisClient.del(getSmsKey(phoneNo));
+    }
+    
     //    @Override
     //    public boolean sendMsg(MessageParam param) {
     //        if (param == null){

+ 32 - 0
cif-service/src/main/java/com/txz/cif/web/CSHuaGuController.java

@@ -0,0 +1,32 @@
+package com.txz.cif.web;
+
+import com.txz.cif.web.ro.SmsRecordRO;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 短信通知
+ *
+ * @author: MTD®️
+ * @date: 2025/9/28
+ */
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("sms")
+public class CSHuaGuController {
+    
+    /**
+     * cshg短信回调
+     */
+    @PostMapping("notice")
+    // {"date":"202509","index":0,"phone":"8801865055177","smsId":"892352879716536320","status":0}
+    public String notice(@RequestBody SmsRecordRO ro) {
+        // fixme ps:短信回调???接不接业务上有啥区别?
+        return "OK";
+    }
+}

+ 2 - 2
cif-service/src/main/java/com/txz/cif/web/RechargeRecordApiController.java

@@ -26,7 +26,7 @@ import com.txz.cif.service.impl.BizLogServiceImpl;
 import com.txz.cif.util.IpUtils;
 import com.txz.cif.util.TFPayUtil;
 import com.txz.cif.web.para.RecordParam;
-import com.txz.cif.web.ro.TFPayNotifyDTO;
+import com.txz.cif.web.ro.TFPayNotifyRO;
 import com.txz.cif.web.vo.CreatePayVO;
 import com.txz.cif.web.vo.PaymentPriceVO;
 import com.txz.mall.enums.NoticeEnum;
@@ -280,7 +280,7 @@ public class RechargeRecordApiController {
      * 回调通知
      */
     @PostMapping("/callback/tfpay")
-    public Object callback(@ModelAttribute TFPayNotifyDTO dto) {
+    public Object callback(@ModelAttribute TFPayNotifyRO dto) {
         LockInfo lockInfo = lockTemplate.lock(String.format(MyConstants.TF_PAY_NOTIFY_LOCK, dto.getOrderid()), Long.valueOf(1000 * 60 * 2), Long.valueOf(1000 * 1), RedisTemplateLockExecutor.class);
         if (null == lockInfo) {
             return "WAIT";

+ 5 - 5
cif-service/src/main/java/com/txz/cif/web/UserApiController.java

@@ -200,10 +200,8 @@ public class UserApiController extends AbstractApiController {
     @ApiOperation(value = "获取验证码", notes = "", httpMethod = "GET")
     @GetMapping("/getCode")
     public Result<UserInfoBO> getCode(@RequestParam String phoneNo) {
-        //        Long userId = authService.getTokenUserId(request);
-        // TODO 发送短信
-        Result<Object> result = userService.sendCode(phoneNo);
-        return ResultGenerator.genSuccessResult(result.getData().toString());
+        userService.sendCode(phoneNo);
+        return ResultGenerator.genSuccessResult();
     }
     
     @ApiOperation(value = "获取会员等级配置", notes = "", httpMethod = "GET")
@@ -320,7 +318,7 @@ public class UserApiController extends AbstractApiController {
             if (CollUtil.isNotEmpty(users)) {
                 return ResultGenerator.genFailResult(ResultCode.USER_IS_EXIST);
             }
-            if (!userService.checkCode(params.getPhone(), params.getVerifyCode())) {
+            if (!userService.checkCode(params.getAreaCode() + params.getPhone(), params.getVerifyCode())) {
                 return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
             }
             String salt = RandomUtil.randomString(4);
@@ -389,6 +387,8 @@ public class UserApiController extends AbstractApiController {
             userService.update(user);
             user.setPwd("***");
             user.setSalt("***");
+            // 删除验证码
+            userService.delCode(params.getAreaCode() + params.getPhone());
             return ResultGenerator.genSuccessResult(user);
         } catch (Exception e) {
             log.error("注册异常", e);

+ 2 - 2
cif-service/src/main/java/com/txz/cif/web/WithdrawRecordApiController.java

@@ -23,7 +23,7 @@ import com.txz.cif.service.*;
 import com.txz.cif.util.TFPayUtil;
 import com.txz.cif.web.para.RecordParam;
 import com.txz.cif.web.para.WithdrawParam;
-import com.txz.cif.web.ro.TFWithdrawCallbackDTO;
+import com.txz.cif.web.ro.TFWithdrawCallbackRO;
 import com.txz.mall.enums.NoticeEnum;
 import com.txz.operating.dto.ConfigDTO;
 import io.jsonwebtoken.Claims;
@@ -227,7 +227,7 @@ public class WithdrawRecordApiController {
      * tfpay提现通知
      */
     @PostMapping("/callback/tfpay")
-    public String callback(@ModelAttribute TFWithdrawCallbackDTO dto) {
+    public String callback(@ModelAttribute TFWithdrawCallbackRO dto) {
         LockInfo lockInfo = lockTemplate.lock(String.format(MyConstants.TF_PAY_WITHDRAW_NOTIFY_LOCK, dto.getOrderid()), Long.valueOf(1000 * 60 * 2), Long.valueOf(1000 * 1), RedisTemplateLockExecutor.class);
         if (null == lockInfo) {
             return "WAIT";

+ 36 - 0
cif-service/src/main/java/com/txz/cif/web/ro/SmsRecordRO.java

@@ -0,0 +1,36 @@
+package com.txz.cif.web.ro;
+
+import lombok.Data;
+
+/**
+ * 短信记录
+ */
+@Data
+public class SmsRecordRO {
+    
+    /**
+     * 日期(年月)
+     */
+    private String date;
+    
+    /**
+     * 推送次数
+     */
+    private Integer index;
+    
+    /**
+     * 手机号
+     */
+    private String phone;
+    
+    /**
+     * 短信ID
+     */
+    private String smsId;
+    
+    /**
+     * 状态 0:成功   1:失败
+     */
+    private Integer status;
+    
+}

+ 1 - 1
cif-service/src/main/java/com/txz/cif/web/ro/TFPayNotifyDTO.java → cif-service/src/main/java/com/txz/cif/web/ro/TFPayNotifyRO.java

@@ -8,7 +8,7 @@ import lombok.Data;
  */
 
 @Data
-public class TFPayNotifyDTO {
+public class TFPayNotifyRO {
     
     /**
      * 商户编号 - 平台分配商户号

+ 1 - 1
cif-service/src/main/java/com/txz/cif/web/ro/TFWithdrawCallbackDTO.java → cif-service/src/main/java/com/txz/cif/web/ro/TFWithdrawCallbackRO.java

@@ -7,7 +7,7 @@ import lombok.Data;
  * @date: 2025/9/3
  */
 @Data
-public class TFWithdrawCallbackDTO {
+public class TFWithdrawCallbackRO {
     
     /**
      * 商户编号 - 平台分配商户号

+ 5 - 0
cif-service/src/main/resources/bootstrap.properties

@@ -122,3 +122,8 @@ yp.ali.appid=2021003182699876
 yp.wx.appid=wxf85cf793dbaa8a61
 
 logging.level.com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler=off
+
+#cshg
+cshg.apiurl=http://smsapi.cshuagu.com/api/msg/key/send
+cshg.apikey=e3543dc9
+cshg.apisecret=7bf5efdb

+ 1 - 1
cif-service/src/main/resources/logback.xml

@@ -18,7 +18,7 @@
             <!-- rollover daily -->
             <fileNamePattern>${LOG_HOME}/log.cif.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
             <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
-            <maxFileSize>2GB</maxFileSize>
+            <maxFileSize>50MB</maxFileSize>
             <maxHistory>2</maxHistory>
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">