Sfoglia il codice sorgente

Merge branch 'phone_verify' into dev

chenbiao 2 anni fa
parent
commit
d1925b9e01

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/views/RenewalView.java

@@ -32,6 +32,9 @@ public class RenewalView {
     @DbField("sku.id")
     private Long skuId;
 
+    @DbField("g.status")
+    private Boolean goodsStatus;
+
     @DbField("sku.status")
     private Boolean skuStatus;
 

+ 0 - 1
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -821,7 +821,6 @@ public class RedisService {
         CLOSE_ORDER_TIME_KEY("close_order_time_key:", "关闭订单key", 3 * 60),
         CHATGPT_CONVERSATION_LIMIT("chatgpt:conversation:limit:", "chatGpt 对话限制", 3 * 60 * 60L),
 
-        CHATGPT_CAR_CONVERSATION_LIMIT("chatgpt:conversation:car:", "chatGpt 车队对话数量", 3 * 60 * 60L),
         CHATGPT_CAR_SCORES("chatgpt:car:scores","chatGpt 车队分数", 48 * 60 * 60L),
         CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:","chatGpt gpt4 对话次数", 48 * 60 * 60L),
         CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),

+ 8 - 43
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -396,8 +396,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         chatgptUserConversationRecord.setModel(conversationRequest.getModel());
         chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
 
-        if(StringUtils.isNotBlank(conversationRequest.getCarId())){
-            updateExperienceAndScore(conversationRequest.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
+        if(StringUtils.isNotBlank(chatgptSession.getCarId())){
+            updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
         }
 
     }
@@ -412,21 +412,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
             if (chatgptUser.getIsCar()) {
                 conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
             }
-            if(carId == null){
-                if (StringUtils.isNotBlank(userToken)) {
-                    if (chatgptUser.getSessionId() != null) {
-                        ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
-                        if(chatgptSession != null){
-                            carId = chatgptSession.getCarId();
-                        }
-                    }
-                }
-            }
-            //车队次数记录
-            String finalCarId = carId;
-            TASK_EXECUTOR.execute(() -> {
-                cardConversationRecord(finalCarId);
-            });
         }
 
         return conversationLimitResponse;
@@ -470,29 +455,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
     }
 
 
-    /**
-     * 记录车队的提问次数
-     */
-    public boolean cardConversationRecord(String carid) {
-        String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carid;
-        long currentTimeMillis = System.currentTimeMillis();
-        long windowStartMillis = currentTimeMillis - (WINDOW_SIZE) * 1000;
-
-        // 清除时间窗口之前的请求记录
-        redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
-
-        Long currentSize = redisService.zCard(key);
-        if (currentSize != null && currentSize >= MAX_REQUESTS) {
-            // 如果当前请求次数超过限制,则拒绝请求
-            return false;
-        } else {
-            // 如果未超过限制,记录当前请求的时间戳
-            redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
-            // 设置ZSet的过期时间,窗口大小加上一段冗余时间
-            redisService.expire(key, (WINDOW_SIZE * 60 * 60) + 20);
-            return true;
-        }
-    }
 
     /**
      * 获取指定用户ID在滑动窗口内的提问次数
@@ -521,9 +483,12 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
      * @return 滑动窗口内的请求次数
      */
     private Long getCarConversationCount(String carId, Long limitTime) {
-        String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carId;
-        long currentTimeMillis = System.currentTimeMillis();
-        long windowStartMillis = currentTimeMillis - (limitTime * 60 * 60) * 1000;
+        // 定义键名
+        String key = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
+        long timestamp = System.currentTimeMillis();
+        // 更新体验数据
+        redisService.zAdd(key, timestamp, String.valueOf(timestamp));
+        long windowStartMillis = timestamp - (limitTime * 60 * 60 * 1000);
 
         // 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
         redisService.zRemoveRangeByScore(key, 0, windowStartMillis);

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonSkuServiceImpl.java

@@ -91,7 +91,7 @@ public class CmsGoodsDonSkuServiceImpl extends ServiceImpl<GoodsDonSkuMapper,Goo
 
 	@Override
 	public void updateMirrorCarUserNum(GoodsDonSku sku) {
-		if (sku.getIsCar()) {
+		if (sku.getIsCar() != null && sku.getIsCar()) {
 			Long id = sku.getId();
 			GoodsDonSku dbSku = skuMapper.selectById(id);
 			Integer gptLimitNum = sku.getGptLimitNum();

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/user/BadIntentionOpService.java

@@ -3,7 +3,7 @@ package com.cyksj.service.user;
 import javax.servlet.http.HttpServletRequest;
 
 public interface BadIntentionOpService {
-    void checkHandleBadUserOp(String phone);
+    void checkHandleBadUserOp(String phone, String verifyCode);
 
     void isBadOpLoginPhone(HttpServletRequest request, String phone);
 }

+ 25 - 1
netflix-service/src/main/java/com/cyksj/service/user/impl/BadIntentionOpServiceImpl.java

@@ -1,12 +1,16 @@
 package com.cyksj.service.user.impl;
 
 import cn.hutool.extra.servlet.ServletUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.user.BadIntentionOpService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
@@ -15,6 +19,10 @@ import javax.servlet.http.HttpServletRequest;
 @RequiredArgsConstructor
 @Slf4j
 public class BadIntentionOpServiceImpl implements BadIntentionOpService {
+
+    @Value("${smsVerify.apiKey}")
+    String apiKey;
+
     private final RedisService redisService;
 
     private static final int PHONE_CODE_GET_NUM_DAY_LIMIT = 30;
@@ -22,8 +30,10 @@ public class BadIntentionOpServiceImpl implements BadIntentionOpService {
 
     private static final int PHONE_LOGIN_CODE_RETRY = 10;
 
+    private static final String VERIFY_URL =  "https://captcha.luosimao.com/api/site_verify";
+
     @Override
-    public void checkHandleBadUserOp(String phone) {
+    public void checkHandleBadUserOp(String phone, String verifyCode) {
         if ("13662979985".equals(phone)) {
             throw BusinessRuntimeException.getInstance("异常手机号");
         }
@@ -42,9 +52,23 @@ public class BadIntentionOpServiceImpl implements BadIntentionOpService {
                 log.error("手机号:{}频繁获取短信验证码", phone);
                 throw BusinessRuntimeException.getInstance("请勿频繁获取短信验证码");
             }
+            if (StringUtils.isBlank(verifyCode)) {
+                throw BusinessRuntimeException.getInstance("人机校验不通过");
+            }else {
+                JSONObject parmas = new JSONObject();
+                parmas.putOpt("api_key", apiKey);
+                parmas.putOpt("response", verifyCode);
+                String post = HttpUtil.post(VERIFY_URL, parmas.toString());
+                JSONObject res = new JSONObject(post);
+                if (!res.getStr("res").equals("success")) {
+                    log.error("手机号:{}验证码校验不通过 res:{}", phone, res);
+                    throw BusinessRuntimeException.getInstance("人机校验不通过");
+                }
+            }
             return;
         }
         redisService.set(dayKey, 1, RedisService.key.PHONE_CODE_USER_NUM_KEY_DAY.getTimeout());
+
     }
 
     @Override

+ 3 - 0
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -354,6 +354,9 @@ public class GoodsDonController {
 		if (o == null) {
 			GoodsFrontListView views = beanSearcher.searchFirst(GoodsFrontListView.class, MapUtils.builder().field(GoodsFrontListView::getId, id)
 					.build());
+			if (views == null) {
+				throw BusinessRuntimeException.getInstance("商品已下架..");
+			}
 
 			views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
 			MapBuilder builder = MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true);

+ 9 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/CorpMsgAuditController.java

@@ -1,6 +1,8 @@
 package com.cyksj.web.controller.manage.corp;
 
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.model.entity.QyMsgContent;
@@ -23,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.servlet.http.HttpServletRequest;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -89,7 +92,12 @@ public class CorpMsgAuditController {
      */
     @GetMapping("/getMsgByFollowIdAndUserId")
     public Result<SearchResult<QyMsgContent>> getMsgByFollowIdAndUserId(){
-        SearchResult<QyMsgContent> search = beanSearcher.search(QyMsgContent.class, MapUtils.flatBuilder(request.getParameterMap()).build());
+        Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
+        log.info("获取聊天记录 param:{}", JSONUtil.toJsonStr(build));
+        if (!build.containsKey("followId") || !build.containsKey("externalUserid")){
+            throw BusinessRuntimeException.getInstance("缺少必填参数.");
+        }
+        SearchResult<QyMsgContent> search = beanSearcher.search(QyMsgContent.class, build);
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
 

+ 7 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.snowflake.Sequence;
@@ -307,7 +308,12 @@ public class WxCorpController {
 	 */
 	@GetMapping("/getMsgByFollowIdAndUserId")
 	public Result<SearchResult<QyMsgContent>> getMsgByFollowIdAndUserId() {
-		SearchResult<QyMsgContent> search = beanSearcher.search(QyMsgContent.class, MapUtils.flatBuilder(request.getParameterMap()).build());
+		Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
+		log.info("获取聊天记录 param:{}", JSONUtil.toJsonStr(build));
+		if (!build.containsKey("followId") || !build.containsKey("externalUserid")){
+			throw BusinessRuntimeException.getInstance("缺少必填参数.");
+		}
+		SearchResult<QyMsgContent> search = beanSearcher.search(QyMsgContent.class, build);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
 

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -365,7 +365,7 @@ public class AuthorizationController {
      */
     @GetMapping("/get/phone/code")
     @NoSubmit
-    public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid) throws Exception {
+    public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid, String verifyCode) throws Exception {
         if (cid == null) cid = 86;
         if (StrUtil.isBlank(phone) || (86 == cid && !Validator.isMobile(phone))) {
             throw BusinessRuntimeException.getInstance("请输入正确的手机号");
@@ -379,7 +379,7 @@ public class AuthorizationController {
             throw BusinessRuntimeException.getInstance("短信验证码未失效");
         }
         //是否是恶意用户
-        badIntentionOpService.checkHandleBadUserOp(phone);
+        badIntentionOpService.checkHandleBadUserOp(phone, verifyCode);
         String code = StringUtil.getRandomCodeStr(digit);
         Boolean isFlag;
         if (!isFree) {

File diff suppressed because it is too large
+ 0 - 0
netflix-web/src/main/resources/application-dev.yml


File diff suppressed because it is too large
+ 0 - 0
netflix-web/src/main/resources/application-prd.yml


+ 4 - 1
netflix-web/src/main/resources/application-pre.yml

@@ -178,4 +178,7 @@ advertisementwxapp:
   notify: https://xue.niupian.com.cn/8081/api/
 
 chatgpt:
-  domain: "https://gpt.claudeplus.com.cn"
+  domain: "https://gpt.claudeplus.com.cn"
+
+smsVerify:
+  apikey: f1ba387b7a12d064af6d30043a88665e

Some files were not shown because too many files changed in this diff