From 34e64f1437ed897056bed0c3851e7a46ac220423 Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期四, 18 九月 2025 18:01:57 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/haizhentong --- ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/H5AICallbackController.java | 130 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/H5AICallbackController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/H5AICallbackController.java new file mode 100644 index 0000000..38e527b --- /dev/null +++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/H5AICallbackController.java @@ -0,0 +1,130 @@ +package com.ruoyi.web.controller.api; + +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.redis.service.RedisService; +import com.ruoyi.framework.web.service.SysLoginService; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.model.TSysAiConfig; +import com.ruoyi.system.model.TSysInspection; +import com.ruoyi.system.service.TSysAiConfigService; +import com.ruoyi.system.service.TSysAppUserService; +import com.ruoyi.system.service.TSysInspectionService; +import com.ruoyi.system.utils.util.AesSimpleUtil; +import com.ruoyi.system.utils.util.RsaSimpleUtil; +import com.ruoyi.system.utils.wx.model.WeixinProperties; +import com.ruoyi.system.utils.wx.tools.WxAppletTools; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; + +/** + * <p> + * 微信小程序登录 前端控制器 + * </p> + * + * @author xiaochen + * @since 2024-08-06 + */ +@Slf4j +@RestController +@RequestMapping("/aiCallback") +public class H5AICallbackController { + + @Autowired + private TSysAiConfigService sysAiConfigService; + @Autowired + private TSysInspectionService sysInspectionService; + + @PostMapping("/reportReturn") + public String reportReturn(String encryptedJson, String signEncryptedJson) throws Exception { + TSysAiConfig sysAiConfig = sysAiConfigService.getById(1); + // 应用AES秘钥 + String aesKey = sysAiConfig.getAesKey(); + // 平台RSA公钥 + String rsaPublicKey = sysAiConfig.getRsaPublicKey(); + + // 1. 先解密 + String source = AesSimpleUtil.decrypt(encryptedJson, aesKey); + System.out.println("AI问诊回调数据=====:"+ source); + JSONObject jsonObject = JSONObject.parseObject(source); + + // 2. 再验证签名 + String signSource = String.format("%s_%s", + jsonObject.getString("thirdId"), + jsonObject.getString("time")); + boolean verify = RsaSimpleUtil.verify(signSource, signEncryptedJson, rsaPublicKey); + if (!verify) { + return "error"; + } + // 3. 验证成功,则仅仅业务保存并返回success字符串 + /** + * { + * "returnType": 1, + * "name": "张三", + * "phone": "13344445555", + * "email": null, + * "sex": 1, + * "age": 42, + * "time": "2023-03-08 08:23:13", + * "pdf": "https://labelsys-images.oss-cn-hangzhou.aliyuncs.com/tongueFile/check/2023/03/87d76220-085e-4d2e-9fd7-9f5a01da1940.pdf", + * "healthIndex": 100.0, + * "constitutionNames": "气虚", + * "symptomName": "胃气虚证", + * "thirdId": "13344445555", + * "tongueFeature": "正常人舌色,舌质淡红润泽。舌苔呈现白色。", + * "faceFeature": "面部颜色暗沉。" + * } + */ + + Integer returnType = jsonObject.getInteger("returnType"); + String name = jsonObject.getString("name"); + String phone = jsonObject.getString("phone"); + String email = jsonObject.getString("email"); + Integer sex = jsonObject.getInteger("sex"); + Integer age = jsonObject.getInteger("age"); + String time = jsonObject.getString("time"); + String pdf = jsonObject.getString("pdf"); + Double healthIndex = jsonObject.getDouble("healthIndex"); + String constitutionNames = jsonObject.getString("constitutionNames"); + String symptomName = jsonObject.getString("symptomName"); + String thirdId = jsonObject.getString("thirdId"); + String tongueFeature = jsonObject.getString("tongueFeature"); + String faceFeature = jsonObject.getString("faceFeature"); + + if(returnType == 2){ + log.info("用户["+phone+"]检测失败"); + } + + long count = sysInspectionService.count(Wrappers.lambdaQuery(TSysInspection.class) + .eq(TSysInspection::getPersonPhone, phone) + .eq(TSysInspection::getCheckTime, time)); + if (count == 0) { + TSysInspection sysInspection = new TSysInspection(); + sysInspection.setPersonName(name); + sysInspection.setPersonPhone(phone); + sysInspection.setPersonSex(sex); + sysInspection.setPersonAge(age); + sysInspection.setCheckTime(time); + sysInspection.setPdfUrl(pdf); + sysInspection.setHealthIndex(healthIndex); + sysInspection.setConstitutionNames(constitutionNames); + sysInspection.setSymptomName(symptomName); + sysInspection.setTongueFeature(tongueFeature); + sysInspection.setFaceFeature(faceFeature); + sysInspection.setAppUserId(thirdId); + sysInspection.setInspectionType(2); + sysInspection.setIsPay(0); + sysInspectionService.save(sysInspection); + } + + return "success"; + } + +} -- Gitblit v1.7.1