From 89ad0fa748b1773d58822290e4822a4bbbb1d9f9 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期五, 22 八月 2025 17:29:28 +0800 Subject: [PATCH] 添加蓉政通登陆接口 --- doc/运维文档.md | 18 +++++ ruoyi-admin/pom.xml | 8 ++ ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java | 61 +++++++++++++++++++ ruoyi-admin/src/main/resources/application-prod.yml | 5 + ruoyi-admin/src/main/java/org/dromara/web/utils/RZTHttpUtils.java | 57 +++++++++++++++++++ ruoyi-admin/src/main/resources/application-dev.yml | 16 +++-- 6 files changed, 156 insertions(+), 9 deletions(-) diff --git "a/doc/\350\277\220\347\273\264\346\226\207\346\241\243.md" "b/doc/\350\277\220\347\273\264\346\226\207\346\241\243.md" index 251c637..e4ed7ef 100644 --- "a/doc/\350\277\220\347\273\264\346\226\207\346\241\243.md" +++ "b/doc/\350\277\220\347\273\264\346\226\207\346\241\243.md" @@ -33,12 +33,18 @@ 瀵嗙爜锛歈yqkwwjtbxtWersdf01 ``` +杩炴帴涓奦PN鍚庯紝杈撳叆 https://192.168.50.17 + + + 鍫″瀿鏈鸿处鍙峰瘑鐮侊紙鍗宠繍缁村鎴风鐧诲綍璐﹀彿瀵嗙爜锛夛細 ``` 璐﹀彿锛歲yqkwwjtbxt01 -瀵嗙爜锛歈yqkwwjtbxtWersdf@02 +瀵嗙爜锛歈yqkwwjtbxtWersdf@06 ``` + + ## 鏉愭枡 @@ -170,6 +176,16 @@ ## 鍚庣鏈嶅姟 +# 鎵撳寘鐢熶骇鐜 +mvn clean package -Pprod + +# 鍚姩鏈嶅姟 + +systemctl stop java-server + +systemctl start java-server + + ```bash nohup java -jar & ``` diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 8875fa6..538f03e 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -126,6 +126,14 @@ </execution> </executions> </plugin> + <!-- 璺宠繃Test娴嬭瘯鎵撳寘 --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java index a541e1f..4e3a53c 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java @@ -3,7 +3,9 @@ import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.aliyun.dingtalkcontact_1_0.models.GetUserHeaders; import com.aliyun.dingtalkcontact_1_0.models.GetUserResponseBody; import com.aliyun.dingtalkoauth2_1_0.models.GetUserTokenRequest; @@ -14,9 +16,7 @@ import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.*; import com.dingtalk.api.response.OapiUserGetbyunionidResponse; -import com.dingtalk.api.response.OapiUserGetuserinfoResponse; import com.dingtalk.api.response.OapiV2UserGetResponse; -import com.dingtalk.api.response.OapiV2UserGetuserinfoResponse; import com.taobao.api.ApiException; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; @@ -33,6 +33,7 @@ import org.dromara.common.core.utils.MessageUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.redis.utils.RedisUtils; import org.dromara.common.social.config.properties.SocialLoginConfigProperties; import org.dromara.common.social.config.properties.SocialProperties; import org.dromara.common.social.utils.SocialUtils; @@ -50,12 +51,16 @@ import org.dromara.web.service.IAuthStrategy; import org.dromara.web.service.SysLoginService; import org.dromara.web.service.SysRegisterService; +import org.dromara.web.utils.RZTHttpUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import com.aliyun.teaopenapi.models.Config; import java.net.URL; +import java.time.Duration; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 璁よ瘉 @@ -79,6 +84,7 @@ private final ISysClientService clientService; private final ISysUserService userService; private final SysUserMapper userMapper; + private final RZTHttpUtils rzthttpUtils; /** @@ -315,4 +321,55 @@ return rsp.getResult(); } + + final String redisKey = "RZT_TOKEN"; + + @RequestMapping(value = "/rztLogin", method = RequestMethod.GET) + public String getRztAccessToken(@RequestParam(value = "code") String code) { + try { + + log.info("code鍊硷細{}", code); + String accessToken = getRztToken(); + if (StrUtil.isNotBlank(accessToken)) { + Map<String, String> hashMap = new HashMap<>(); + hashMap.put("code", code); + hashMap.put("token", accessToken); + String userJson = rzthttpUtils.sendGetRequest("/login/info", hashMap); + log.info("鐢ㄦ埛淇℃伅锛歿}", userJson); + JSONObject userObject = JSON.parseObject(userJson); + if (userObject.getIntValue("errcode") == 0) { + return userObject.getString("userid"); + } else { + log.error("鑾峰彇鐢ㄦ埛淇℃伅澶辫触锛歿}", userObject.getString("errmsg")); + } + } + + } catch (Exception e) { + log.error("鑾峰彇鐢ㄦ埛淇℃伅寮傚父锛歿}", e.getMessage()); + } + return ""; + } + + private String getRztToken() throws Exception { + String token = RedisUtils.getCacheObject(redisKey); + if (StrUtil.isEmpty(token)) { + + String corpId = "ww9904fd98c1b0df9e"; + String corpSecret = "mZdTP-ULDWHEPgFCpl62OwudbP3bODgqN9lC-rUtNSA"; + String accessJson = rzthttpUtils.sendGetRequest("/gettoken?corpId=" + corpId + "&corpsecret=" + corpSecret, null); + JSONObject jsonObject = JSON.parseObject(accessJson); + if (jsonObject.getIntValue("errcode") == 0) { + String accessToken = jsonObject.getString("access_token"); + Integer expiresIn = jsonObject.getIntValue("expires_in"); + RedisUtils.setCacheObject(redisKey, accessToken, Duration.ofSeconds(expiresIn)); + return accessToken; + } else { + log.error("鑾峰彇token澶辫触锛歿},{}", jsonObject.getIntValue("errcode"), jsonObject.getString("errmsg")); + return null; + } + + } else { + return token; + } + } } diff --git a/ruoyi-admin/src/main/java/org/dromara/web/utils/RZTHttpUtils.java b/ruoyi-admin/src/main/java/org/dromara/web/utils/RZTHttpUtils.java new file mode 100644 index 0000000..6f43350 --- /dev/null +++ b/ruoyi-admin/src/main/java/org/dromara/web/utils/RZTHttpUtils.java @@ -0,0 +1,57 @@ +package org.dromara.web.utils; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import lombok.extern.slf4j.Slf4j; +import me.zhyd.oauth.utils.RandomUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.security.MessageDigest; +import java.util.Map; + +@Component +@Slf4j +public class RZTHttpUtils { + + @Value("${rzt.url}") + private String url; + + @Value("${rzt.paasid}") + private String paasid; + + @Value("${rzt.paastoken}") + private String paastoken; + + + public String sendGetRequest(String urlPath, Map<String, String> params) throws Exception { + + //鑾峰彇鏃堕棿鎴筹細 + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + + String nonce = RandomUtil.randomString(20); + //鑾峰彇绛惧悕锛� + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest((timestamp + paastoken + nonce + timestamp).getBytes()); + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + String signature = hexString.toString().toUpperCase(); + HttpRequest request = HttpRequest.get(url + urlPath) + .header("x-rio-paasid", paasid) + .header("x-rio-timestamp", timestamp) + .header("x-rio-nonce", nonce) + .header("x-rio-signature", signature); + if (params != null) { + request.formStr(params); + } + log.info(request.toString()); + return request.execute().body(); + + } +} diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 0eb547f..e15a869 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -43,9 +43,9 @@ driverClassName: com.mysql.cj.jdbc.Driver # jdbc 鎵�鏈夊弬鏁伴厤缃弬鑰� https://lionli.blog.csdn.net/article/details/122018562 # rewriteBatchedStatements=true 鎵瑰鐞嗕紭鍖� 澶у箙鎻愬崌鎵归噺鎻掑叆鏇存柊鍒犻櫎鎬ц兘(瀵规暟鎹簱鏈夋�ц兘鎹熻�� 浣跨敤鎵归噺鎿嶄綔搴旇�冭檻鎬ц兘闂) - url: jdbc:mysql://127.0.0.1:3306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true + url: jdbc:mysql://42.193.1.25:3306/qysp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true username: root - password: 123456 + password: 321$YcYl@1970! # 浠庡簱鏁版嵁婧� slave: lazy: true @@ -95,11 +95,10 @@ --- # redis 鍗曟満閰嶇疆(鍗曟満涓庨泦缇ゅ彧鑳藉紑鍚竴涓彟涓�涓渶瑕佹敞閲婃帀) spring.data: redis: - # 鍦板潃 - host: 127.0.0.1 - # 绔彛锛岄粯璁や负6379 + host: 42.193.1.25 port: 6379 -# password: 234#Wersdf! + password: ycl2018 + # password: 234#Wersdf! # 鏁版嵁搴撶储寮� database: 0 # 瀵嗙爜(濡傛病鏈夊瘑鐮佽娉ㄩ噴鎺�) @@ -250,3 +249,8 @@ client-id: 10**********6 client-secret: 1f7d08**********5b7**********29e redirect-uri: ${justauth.address}/social-callback?source=gitlab + +rzt: + url: https://rio.rztcd.com:10443/ebus/dzptcs + paasid: dzptcs + paastoken: 69b986d3c2450454c22d99a9653c97d2 diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 41d5fc6..d4afcce 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -272,3 +272,8 @@ username: admin #鏈満锛歠tpup passwd: 234#Wersdf! path: / + +rzt: + url: https://rio.rztcd.com:10443/ebus/dzpt + paasid: dzpt + paastoken: 69b986d3c2450454c22d99a9653c97d2 -- Gitblit v1.8.0