浏览代码

添加苍南

wwh 2 年之前
父节点
当前提交
a7f0edfd01
共有 14 个文件被更改,包括 708 次插入9 次删除
  1. 69 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/config/OauthConfigBaseInfo03.java
  2. 67 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/config/OauthConfigUserPwdInfoTest03.java
  3. 2 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/manager/IOauthIntegrationManager.java
  4. 13 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/manager/impl/OauthIntegrationManager.java
  5. 179 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/BaseRequest03.java
  6. 36 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/GetPublicKeyRequest03.java
  7. 88 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/GetTokenRequestTest03.java
  8. 61 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/OauthRefreshTokenRequest03.java
  9. 25 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/response/OauthRefreshTokenResponse03.java
  10. 16 4
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/schedule/UpdateTokenSchedule.java
  11. 19 5
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/service/impl/OauthService.java
  12. 36 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/user/UserPasswordConfigInfoTest03.java
  13. 48 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/utils/HttpURLConnectionUtil.java
  14. 49 0
      huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/utils/HttpsURLConnectionUtil.java

+ 69 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/config/OauthConfigBaseInfo03.java

@@ -0,0 +1,69 @@
+package com.huimv.video.dhicc.test.config;
+
+import com.dahuatech.icc.oauth.profile.GrantType;
+import com.huimv.video.dhicc.test.utils.HttpConfigInfo;
+import lombok.Data;
+
+/**
+ * 鉴权配置信息
+ * **/
+@Data
+public abstract class OauthConfigBaseInfo03 {
+
+    /** 申请认证ID */
+    protected String clientId;
+    /** 申请认证秘钥 */
+    protected String clientSecret;
+    /** 当前使用认证类型 */
+    protected GrantType grantType;
+    /**平台ip 端口信息*/
+    protected HttpConfigInfo httpConfigInfo;
+
+    public OauthConfigBaseInfo03(){
+
+    }
+
+    public OauthConfigBaseInfo03(String host, String clientId, String clientSecret, GrantType grantType){
+        this.httpConfigInfo = new HttpConfigInfo(host);
+        this.clientId = clientId;
+        this.clientSecret = clientSecret;
+        this.grantType = grantType;
+    }
+
+    public OauthConfigBaseInfo03(String host, String clientId, String clientSecret, GrantType grantType, boolean isEnableHttpTest, String httpsPort, String httpPort){
+        this(host,clientId,clientSecret,grantType);
+        this.httpConfigInfo = new HttpConfigInfo(host,isEnableHttpTest,httpsPort,httpPort);
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+
+    public String getClientSecret() {
+        return clientSecret;
+    }
+
+    public void setClientSecret(String clientSecret) {
+        this.clientSecret = clientSecret;
+    }
+
+    public GrantType getGrantType() {
+        return grantType;
+    }
+
+    public void setGrantType(GrantType grantType) {
+        this.grantType = grantType;
+    }
+
+    public HttpConfigInfo getHttpConfigInfo() {
+        return httpConfigInfo;
+    }
+
+    public void setHttpConfigInfo(HttpConfigInfo httpConfigInfo) {
+        this.httpConfigInfo = httpConfigInfo;
+    }
+}

+ 67 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/config/OauthConfigUserPwdInfoTest03.java

@@ -0,0 +1,67 @@
+package com.huimv.video.dhicc.test.config;
+
+import com.dahuatech.icc.oauth.profile.GrantType;
+import com.huimv.video.dhicc.test.schedule.UpdateTokenSchedule;
+
+import java.util.Map;
+
+/**
+ * 用户密码模式配置信息
+ */
+public class OauthConfigUserPwdInfoTest03 extends OauthConfigBaseInfo03{
+    /** 密码认证用户名 */
+    public String username;//登录平台的用户名,
+    /** 认证密码 明文 */
+    public String password;
+
+    public OauthConfigUserPwdInfoTest03(){}
+    /**
+     * 使用默认端口、默认协议构造
+     * @param host
+     * @param clientId
+     * @param clientSecret
+     */
+    public OauthConfigUserPwdInfoTest03(String host, String clientId, String clientSecret, String username, String password){
+        super(host,clientId,clientSecret, GrantType.password);
+        this.username = username;
+        this.password = password;
+        //创建用户名密码模式信息时,将客户端信息进行缓存
+        cacheClientInfo();
+    }
+
+    /**
+     * 使用指定端口、指定协议构造
+     * @param host
+     * @param clientId
+     * @param clientSecret
+     */
+    public OauthConfigUserPwdInfoTest03(String host, String clientId, String clientSecret, String username, String password, boolean isEnableHttpTest, String httpsPort, String httpPort){
+        super(host,clientId,clientSecret, GrantType.password,isEnableHttpTest,httpsPort,httpPort);
+        this.username = username;
+        this.password = password;
+        cacheClientInfo();
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public void cacheClientInfo(){
+        Map<String, OauthConfigBaseInfo03> clientInfoMap =  UpdateTokenSchedule.httpConfigMap3;
+        String clientKey = UpdateTokenSchedule.getKey3(this);
+        //缓存客户端信息
+        clientInfoMap.put(clientKey, this);
+    }
+}

+ 2 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/manager/IOauthIntegrationManager.java

@@ -22,4 +22,6 @@ public interface IOauthIntegrationManager {
 
     GetTokenResponse getTokenTest02();
 
+    GetTokenResponse getTokenTest03();
+
 }

+ 13 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/manager/impl/OauthIntegrationManager.java

@@ -3,11 +3,13 @@ package com.huimv.video.dhicc.test.manager.impl;
 
 import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo;
 import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
 import com.huimv.video.dhicc.test.manager.IOauthIntegrationManager;
 import com.huimv.video.dhicc.test.other.BaseIntegrationManager;
 import com.huimv.video.dhicc.test.request.GetPublicKeyRequest;
 import com.huimv.video.dhicc.test.request.GetTokenRequestTest01;
 import com.huimv.video.dhicc.test.request.GetTokenRequestTest02;
+import com.huimv.video.dhicc.test.request.GetTokenRequestTest03;
 import com.huimv.video.dhicc.test.response.GetPublicKeyResponse;
 import com.huimv.video.dhicc.test.response.GetTokenResponse;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +25,9 @@ public class OauthIntegrationManager extends BaseIntegrationManager implements I
     public OauthConfigBaseInfo oauthConfigBaseInfo;
     @Autowired
     public OauthConfigBaseInfo02 oauthConfigBaseInfo02;
+    @Autowired
+    public OauthConfigBaseInfo03 oauthConfigBaseInfo03;
+
 
     /**
      * 获取公钥
@@ -61,4 +66,12 @@ public class OauthIntegrationManager extends BaseIntegrationManager implements I
         GetTokenResponse getTokenResponse = request.doAction();
         return getTokenResponse;
     }
+
+    @Override
+    public GetTokenResponse getTokenTest03() {
+        logger.info("OauthController,getToken");
+        GetTokenRequestTest03 request = new GetTokenRequestTest03(oauthConfigBaseInfo03);
+        GetTokenResponse getTokenResponse = request.doAction();
+        return getTokenResponse;
+    }
 }

+ 179 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/BaseRequest03.java

@@ -0,0 +1,179 @@
+package com.huimv.video.dhicc.test.request;
+
+
+import com.dahuatech.icc.oauth.profile.GrantType;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
+import com.huimv.video.dhicc.test.response.GetTokenResponse;
+import com.huimv.video.dhicc.test.schedule.UpdateTokenSchedule;
+import com.huimv.video.dhicc.test.token.*;
+import lombok.Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 请求基类
+ */
+@Data
+@Component
+public abstract class BaseRequest03<T> {
+    public static final Logger logger = LoggerFactory.getLogger(BaseRequest03.class);
+
+    //客户端信息
+    private OauthConfigBaseInfo03 oauthConfigBaseInfo;
+    //请求方式
+    private String method;
+    //请求url
+    private String url;
+    //请求头
+    private Map<String, String> header = new HashMap<String, String>();
+    //请求体
+    protected String body;
+    //支持常见的form表单类型:application/x-www-form-urlencoded;multipart/form-data
+    protected Map<String, Object> form;
+    //是否需要鉴权,默认需要
+    private boolean needAuth = true;
+
+    private TokenStore tokenStore = UpdateTokenSchedule.tokenStore;
+
+    public abstract T doAction();
+
+    public BaseRequest03(){}
+
+    public BaseRequest03(OauthConfigBaseInfo03 oauthConfigBaseInfo, String method, String url, boolean needAuth){
+        this.oauthConfigBaseInfo = oauthConfigBaseInfo;
+        this.method = method;
+        this.url = url;
+        this.needAuth = needAuth;
+        this.header();
+        //TODO:暂时不开启刷新token任务
+        //UpdateTokenSchedule.getInstance();
+    }
+
+    public void header(){
+       //从缓存获取access_token
+        if(this.needAuth){
+            Token token = getToken();
+            if(token == null)return;
+            header.put("Authorization", "bearer " + (token != null ? token.getAccess_token() : ""));
+            if(GrantType.password == oauthConfigBaseInfo.getGrantType()){
+                header.put("User-Id", (token != null ? token.getUserId() : "1"));
+            }
+        }
+    }
+
+    public Token getToken(){
+        Token token = null;
+        if(tokenStore instanceof LocalTokenStore){
+            LocalTokenStore localTokenStore = (LocalTokenStore)tokenStore;
+            Map<String, Token> tokenMap = localTokenStore.getTokenMap();
+            String key = UpdateTokenSchedule.getKey3(this.oauthConfigBaseInfo);
+            if(!CollectionUtils.isEmpty(tokenMap)){
+                token = tokenMap.get(key);
+                if(token != null){
+                    //token是否过期,过期则删除,重新获取
+                    if(System.currentTimeMillis() / 1000 >= token.getTtl()){
+                        tokenMap.remove(key);
+                    }else{
+                        logger.info("Get token from Local Story Cache...");
+                        return token;
+                    }
+                }
+                //掉接口获取token
+                token = getTokenFromRemote();
+                if(token != null){
+                    //缓存token到本地
+                    tokenMap.put(key, token);
+                }
+            }else {
+                //掉接口获取token
+                token = getTokenFromRemote();
+                if(token != null){
+                    //缓存token到本地
+                    tokenMap.put(key, token);
+                }
+            }
+        }
+        if(tokenStore instanceof MysqlTokenStore){
+            MysqlTokenStore mysqlTokenStore = (MysqlTokenStore)tokenStore;
+            Map<String, Token> tokens =  mysqlTokenStore.getToken();
+            String key = UpdateTokenSchedule.getKey3(this.oauthConfigBaseInfo);
+            if(!CollectionUtils.isEmpty(tokens)){
+                token = tokens.get(key);
+                if (token != null){
+                    //token是否过期,过期则删除,重新获取
+                    if(System.currentTimeMillis() / 1000 >= token.getTtl()){
+                        tokens.remove(key);
+                    }else{
+                        logger.info("Get token from Mysql Cache...");
+                        return token;
+                    }
+                }
+                //掉接口获取token
+                token = getTokenFromRemote();
+                if(token != null){
+                    //缓存token到Mysql
+                    mysqlTokenStore.tokenStore(key, token);
+                }
+            }else {
+                //掉接口获取token
+                token = getTokenFromRemote();
+                if(token != null){
+                    //缓存token到Mysql
+                    mysqlTokenStore.tokenStore(key, token);
+                }
+            }
+        }
+        if(tokenStore instanceof RedisTokenStore){
+            RedisTokenStore redisTokenStore = (RedisTokenStore)tokenStore;
+            Map<String, Token> tokens = redisTokenStore.getToken();
+            String key = UpdateTokenSchedule.getKey3(this.oauthConfigBaseInfo);
+            if(!CollectionUtils.isEmpty(tokens)){
+                token = tokens.get(key);
+                if(token != null){
+                    //token是否过期,过期则删除,重新获取
+                    if(System.currentTimeMillis() / 1000 >= token.getTtl()){
+                        tokens.remove(key);
+                    }else{
+                        logger.info("Get token from Redis Cache...");
+                        return token;
+                    }
+                }
+                //掉接口获取token
+                token = getTokenFromRemote();
+                //缓存token到Redis
+                if(token != null){
+                    redisTokenStore.tokenStore(key, token);
+                }
+            }else{
+                //掉接口获取token
+                token = getTokenFromRemote();
+                if(token != null){
+                    //缓存token到Redis
+                    redisTokenStore.tokenStore(key, token);
+                }
+            }
+
+        }
+        return token;
+    }
+
+    public Token getTokenFromRemote(){
+        logger.info("Get token from remote...");
+        //获取公钥
+        GetTokenRequestTest03 request = new GetTokenRequestTest03(oauthConfigBaseInfo);
+        GetTokenResponse getTokenResponse = request.doAction();
+        if(!getTokenResponse.isSuccess()){
+            logger.error("BaseRequest,getTokenFromRemote,get token error,error msg:{}",getTokenResponse.getErrMsg());
+            return null;
+        }
+        Token token = getTokenResponse.getData();
+        //设置ttl
+        token.setTtl(token.getExpires_in() + System.currentTimeMillis() / 1000);
+        return token;
+    }
+}

+ 36 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/GetPublicKeyRequest03.java

@@ -0,0 +1,36 @@
+package com.huimv.video.dhicc.test.request;
+
+import com.alibaba.fastjson.JSON;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
+import com.huimv.video.dhicc.test.constant.Constant;
+import com.huimv.video.dhicc.test.response.GetPublicKeyResponse;
+import com.huimv.video.dhicc.test.utils.HttpURLConnectionUtil;
+import com.huimv.video.dhicc.test.utils.HttpsURLConnectionUtil;
+import com.huimv.video.dhicc.test.utils.UrlUtil;
+
+
+/**
+ * 获取公钥
+ */
+public class GetPublicKeyRequest03 extends BaseRequest03<GetPublicKeyResponse> {
+
+    public GetPublicKeyRequest03(OauthConfigBaseInfo03 oauthConfigBaseInfo){
+        super(oauthConfigBaseInfo, Constant.HTTP_GET, oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.GET_PUBLIC_KEY, false);
+    }
+
+    @Override
+    public GetPublicKeyResponse doAction(){
+        //重置url信息,替换版本号
+        this.setUrl(UrlUtil.dealVersion(this.getUrl()));
+        //发送请求
+        String res = isEnableHttpTest() ? HttpURLConnectionUtil.doGet03(this) : HttpsURLConnectionUtil.doGet03(this);
+        //获取响应
+        GetPublicKeyResponse getPublicKeyResponse = JSON.parseObject(res, GetPublicKeyResponse.class);
+
+        return getPublicKeyResponse;
+    }
+
+    public boolean isEnableHttpTest(){
+        return super.getOauthConfigBaseInfo().getHttpConfigInfo().isEnableHttpTest();
+    }
+}

+ 88 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/GetTokenRequestTest03.java

@@ -0,0 +1,88 @@
+package com.huimv.video.dhicc.test.request;
+
+import com.alibaba.fastjson.JSON;
+import com.dahuatech.icc.util.SignUtil;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
+import com.huimv.video.dhicc.test.config.OauthConfigUserPwdInfoTest02;
+import com.huimv.video.dhicc.test.config.OauthConfigUserPwdInfoTest03;
+import com.huimv.video.dhicc.test.constant.Constant;
+import com.huimv.video.dhicc.test.response.GetPublicKeyResponse;
+import com.huimv.video.dhicc.test.response.GetTokenResponse;
+import com.huimv.video.dhicc.test.utils.HttpURLConnectionUtil;
+import com.huimv.video.dhicc.test.utils.HttpsURLConnectionUtil;
+import com.huimv.video.dhicc.test.utils.UrlUtil;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 获取token请求类
+ */
+@Data
+public class GetTokenRequestTest03 extends BaseRequest03<GetTokenResponse> {
+    //授权类型
+    private String grant_type;
+    //用户名
+    private String username;
+    //通过RSA加密密码,详见获取公钥接口
+    private String password;
+    //客户端id,由鉴权中心下发
+    private String client_id;
+    //客户端secret,由鉴权中心下发
+    private String client_secret;
+    //公钥,由鉴权中心下发
+    private String public_key;
+    //默认关闭验证码校验,即无需关注verifyCodeFlag和code参数
+    private Integer verifyCodeFlag = 0;
+    private String code;
+
+    public GetTokenRequestTest03(){}
+
+    public GetTokenRequestTest03(OauthConfigBaseInfo03 oauthConfigBaseInfo){
+        super(oauthConfigBaseInfo, Constant.HTTP_POST,oauthConfigBaseInfo.getHttpConfigInfo().getPrefixUrl() + Constant.GET_TOKEN , false);
+        OauthConfigUserPwdInfoTest03 oauthConfigUserPwdInfo = (OauthConfigUserPwdInfoTest03) oauthConfigBaseInfo;
+        this.grant_type = oauthConfigUserPwdInfo.getGrantType().name();
+        this.username = oauthConfigUserPwdInfo.getUsername();
+        this.client_id = oauthConfigUserPwdInfo.getClientId();
+        this.client_secret = oauthConfigUserPwdInfo.getClientSecret();
+        GetPublicKeyRequest03 request = new GetPublicKeyRequest03(oauthConfigBaseInfo);
+        GetPublicKeyResponse getPublicKeyResponse = request.doAction();
+        this.public_key = getPublicKeyResponse.getData().getPublicKey();
+        String enPassword = SignUtil.encryptRSA(oauthConfigUserPwdInfo.getPassword(), this.public_key);
+        this.password = enPassword;
+    }
+
+    public GetTokenResponse doAction(){
+        //重置url信息,替换版本号
+        this.setUrl(UrlUtil.dealVersion(this.getUrl()));
+        //设置请求参数
+        setBody();
+        //发送请求
+        String res = isEnableHttpTest() ? HttpURLConnectionUtil.doPost(this.getUrl(), this.getBody(), this.getHeader()) : HttpsURLConnectionUtil.doPost(this.getUrl(), this.getBody(), this.getHeader());
+        //获取响应
+        GetTokenResponse getTokenResponse = JSON.parseObject(res, GetTokenResponse.class);
+        return getTokenResponse;
+    }
+
+    /**
+     * 设置请求参数
+     * **/
+    public void setBody(){
+        //设置请求参数
+        Map<String, String> paramsMap = new HashMap();
+        paramsMap.put("grant_type", this.grant_type);
+        paramsMap.put("username", this.username);
+        paramsMap.put("password", this.password);
+        paramsMap.put("client_id", this.client_id);
+        paramsMap.put("client_secret", this.client_secret);
+        paramsMap.put("public_key", this.public_key);
+        paramsMap.put("verifyCodeFlag", String.valueOf(this.verifyCodeFlag));
+        this.setBody(JSON.toJSONString(paramsMap));
+    }
+
+    public boolean isEnableHttpTest(){
+        return super.getOauthConfigBaseInfo().getHttpConfigInfo().isEnableHttpTest();
+    }
+}

+ 61 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/request/OauthRefreshTokenRequest03.java

@@ -0,0 +1,61 @@
+package com.huimv.video.dhicc.test.request;
+
+import com.alibaba.fastjson.JSON;
+import com.dahuatech.icc.oauth.profile.GrantType;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
+import com.huimv.video.dhicc.test.constant.Constant;
+import com.huimv.video.dhicc.test.response.OauthRefreshTokenResponse;
+import com.huimv.video.dhicc.test.utils.HttpURLConnectionUtil;
+import com.huimv.video.dhicc.test.utils.UrlUtil;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 刷新token请求
+ */
+@Data
+public class OauthRefreshTokenRequest03 extends BaseRequest03<OauthRefreshTokenResponse> {
+    private String grant_type;
+    private String client_id;
+    private String client_secret;
+    private String refresh_token;
+
+    OauthRefreshTokenRequest03(){}
+
+    public OauthRefreshTokenRequest03(OauthConfigBaseInfo03 oauthConfigBaseInfo, String refresh_token){
+        super(oauthConfigBaseInfo, Constant.HTTP_POST, Constant.REFRESH_TOKEN, true);
+        this.grant_type = GrantType.refresh_token.name();
+        this.client_id = oauthConfigBaseInfo.getClientId();
+        this.client_secret = oauthConfigBaseInfo.getClientSecret();
+        this.refresh_token = refresh_token;
+        setBody();
+    }
+
+    public OauthRefreshTokenResponse doAction(){
+        //重置url信息,替换版本号
+        this.setUrl(UrlUtil.dealVersion(this.getUrl()));
+        //设置请求参数
+        setBody();
+        //发送请求
+        String res = HttpURLConnectionUtil.doPost(this.getBody(), this.getUrl(), this.getHeader());
+        //获取响应
+        OauthRefreshTokenResponse oauthRefreshTokenResponse = JSON.parseObject(res, OauthRefreshTokenResponse.class);
+        return oauthRefreshTokenResponse;
+    }
+
+    /**
+     * 设置请求参数
+     * **/
+    public void setBody(){
+        //设置请求参数
+        Map<String, String> paramsMap = new HashMap();
+        paramsMap.put("grant_type", this.grant_type);
+        paramsMap.put("client_id", this.client_id);
+        paramsMap.put("client_secret", this.client_secret);
+        paramsMap.put("refresh_token", this.refresh_token);
+        this.setBody(JSON.toJSONString(paramsMap));
+    }
+}

+ 25 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/response/OauthRefreshTokenResponse03.java

@@ -0,0 +1,25 @@
+package com.huimv.video.dhicc.test.response;
+
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * 刷新token响应
+ */
+@Data
+@ToString
+public class OauthRefreshTokenResponse03 extends BaseResponse {
+    private IccReFreshToken data;
+
+    @Data
+    @ToString
+    public class IccReFreshToken{
+        private String access_token;
+        private String refresh_token;
+        private Long expires_in;
+        private String scope;
+        private String userId;
+        private String magicId;
+        private String token_type;
+    }
+}

+ 16 - 4
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/schedule/UpdateTokenSchedule.java

@@ -3,10 +3,7 @@ package com.huimv.video.dhicc.test.schedule;
 import com.alibaba.fastjson.JSON;
 import com.dahuatech.icc.oauth.model.v202010.OauthRefreshTokenResponse;
 import com.dahuatech.icc.oauth.profile.GrantType;
-import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo;
-import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo02;
-import com.huimv.video.dhicc.test.config.OauthConfigUserPwdInfoTest01;
-import com.huimv.video.dhicc.test.config.OauthConfigUserPwdInfoTest02;
+import com.huimv.video.dhicc.test.config.*;
 import com.huimv.video.dhicc.test.request.OauthRefreshTokenRequest;
 import com.huimv.video.dhicc.test.token.LocalTokenStore;
 import com.huimv.video.dhicc.test.token.RedisTokenStore;
@@ -36,6 +33,7 @@ public class UpdateTokenSchedule {
     private static UpdateTokenSchedule instance;
     public static final Map<String, OauthConfigBaseInfo> httpConfigMap = new ConcurrentHashMap<String, OauthConfigBaseInfo>();
     public static final Map<String, OauthConfigBaseInfo02> httpConfigMap2 = new ConcurrentHashMap<String, OauthConfigBaseInfo02>();
+    public static final Map<String, OauthConfigBaseInfo03> httpConfigMap3 = new ConcurrentHashMap<String, OauthConfigBaseInfo03>();
     //2分钟刷新一次过期token
     private static final Long expireTime = 120 * 1000L;
     //线程刷新token和保活
@@ -235,4 +233,18 @@ public class UpdateTokenSchedule {
         }
         return null;
     }
+
+    public static String getKey3(OauthConfigBaseInfo03 oauthConfigBaseInfo) {
+        if (oauthConfigBaseInfo.getGrantType() == GrantType.password) {
+            String host = oauthConfigBaseInfo.getHttpConfigInfo().getHost();
+            String grantType = oauthConfigBaseInfo.getGrantType().name();
+            String userName = null;
+            OauthConfigUserPwdInfoTest03 oauthConfigUserPwdInfo = (OauthConfigUserPwdInfoTest03) oauthConfigBaseInfo;
+            userName = oauthConfigUserPwdInfo.getUsername();
+            String key = host + "_" + grantType + "_" + userName;
+            logger.info("UpdateTokenSchedule,getKey, key:{}", key);
+            return key;
+        }
+        return null;
+    }
 }

+ 19 - 5
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/service/impl/OauthService.java

@@ -56,6 +56,7 @@ public class OauthService extends BaseService implements IOauthService {
     public String getTokenTest01(Map<String,String> paramsMap) {
         String type = paramsMap.get("type");
         if ("1".equals(type)) {
+            System.out.println("曙光");
             GetTokenResponse response = oauthIntegrationManager.getTokenTest01();
             if(response.isSuccess()){
                 //处理成功逻辑
@@ -66,17 +67,30 @@ public class OauthService extends BaseService implements IOauthService {
             GetTokenResponse res = new GetTokenResponse();
             BeanUtils.copyProperties(response,res);
             return ("token:"+access_token);
-        } else {
+        } else if ("2".equals(type)) {
+            System.out.println("海宁");
             GetTokenResponse response = oauthIntegrationManager.getTokenTest02();
-            if(response.isSuccess()){
+            if (response.isSuccess()) {
                 //处理成功逻辑
-            }else{
+            } else {
                 //处理异常逻辑
             }
             String access_token = response.getData().getAccess_token();
             GetTokenResponse res = new GetTokenResponse();
-            BeanUtils.copyProperties(response,res);
-            return ("token:"+access_token);
+            BeanUtils.copyProperties(response, res);
+            return ("token:" + access_token);
+        } else {
+            System.out.println("苍南");
+            GetTokenResponse response = oauthIntegrationManager.getTokenTest03();
+            if (response.isSuccess()) {
+                //处理成功逻辑
+            } else {
+                //处理异常逻辑
+            }
+            String access_token = response.getData().getAccess_token();
+            GetTokenResponse res = new GetTokenResponse();
+            BeanUtils.copyProperties(response, res);
+            return ("token:" + access_token);
         }
 
     }

+ 36 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/user/UserPasswordConfigInfoTest03.java

@@ -0,0 +1,36 @@
+package com.huimv.video.dhicc.test.user;
+
+
+
+import com.huimv.video.dhicc.test.config.OauthConfigBaseInfo03;
+import com.huimv.video.dhicc.test.config.OauthConfigUserPwdInfoTest03;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 用户名密码模式全局配置类,测试时需改为自己的配置信息,可在此进行修改
+ */
+@Configuration
+public class UserPasswordConfigInfoTest03 {
+    //主机地址 默认是联调环境
+    private static String host = "61.153.47.93";
+    //用户名
+    private static String username = "system";
+    //密码
+    private static String password = "Admin123";
+    //客户端id
+    private static String clientId = "huimv";
+    //客户端秘钥
+    private static String clientSecret = "52975dac-37aa-46c4-b8ba-1e0cea483135";
+    //https端口
+    private static String https = "447";//https 默认端口443,做了内外网映射 9021
+    //http端口
+    private static String http = "83";//http http调试模式端口默认是83,未作外网映射,此环境不支持83端口调试
+    //http请求协议 是否开启http调试模式,开启需登录运维中心 系统管理-》安全设置-》调试模式 开启;开启后端口是固定83端口
+    private static boolean isEnableHttpTest = false;
+
+    @Bean
+    public OauthConfigBaseInfo03 getOauthConfigBaseInfoInstance03(){
+        return new OauthConfigUserPwdInfoTest03(host,clientId,clientSecret,username,password,isEnableHttpTest,https,http);
+    }
+}

+ 48 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/utils/HttpURLConnectionUtil.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.huimv.video.dhicc.test.constant.Constant;
 import com.huimv.video.dhicc.test.request.BaseRequest;
 import com.huimv.video.dhicc.test.request.BaseRequest02;
+import com.huimv.video.dhicc.test.request.BaseRequest03;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.CollectionUtils;
@@ -128,7 +129,54 @@ public class HttpURLConnectionUtil {
         }
         return response.toString();
     }
+    public static String doGet03(BaseRequest03 request){
+        String httpUrl = request.getUrl();
+        Map<String, String> headers = request.getHeader();
+        logger.info("HttpURLConnectionUtil,doGet,URL:{}, headers:{}", httpUrl, headers);
+        StringBuilder response = new StringBuilder();
+        BufferedReader bufferedReader = null;
+
+        try{
+            //创建连接
+            URL url = new URL(httpUrl);
+            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
 
+            //设置请求方式
+            connection.setRequestMethod(Constant.HTTP_GET);
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
+            //设置自定义请求头信息
+            setCustomHeader(connection, headers);
+
+            //设置请求超时时间:10秒
+            connection.setConnectTimeout(10 * 1000);
+            //设置读取超时时间:10秒
+            connection.setReadTimeout(10 * 1000);
+            //开始连接
+            connection.connect();
+            if(connection.getResponseCode() == 404){
+                JSONObject result = new JSONObject();
+                result.put("code","404");
+                result.put("errMsg","子系统未安装或接口与版本不匹配");
+                return result.toJSONString();
+            }
+            //获取响应数据
+            String readLine = null;
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+            while((readLine = bufferedReader.readLine()) != null){
+                response.append(readLine);
+            }
+            bufferedReader.close();
+        }catch (MalformedURLException e){
+            logger.error("HttpURLConnectionUtil,doGet,request error:{}", e.getMessage());
+            e.printStackTrace();
+        }catch (IOException e){
+            logger.error("HttpURLConnectionUtil,doGet,request error:{}", e.getMessage());
+            e.printStackTrace();
+        }
+        return response.toString();
+    }
 
     /**
      * @param httpUrl 请求地址

+ 49 - 0
huimv-farm-video/src/main/java/com/huimv/video/dhicc/test/utils/HttpsURLConnectionUtil.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.huimv.video.dhicc.test.constant.Constant;
 import com.huimv.video.dhicc.test.request.BaseRequest;
 import com.huimv.video.dhicc.test.request.BaseRequest02;
+import com.huimv.video.dhicc.test.request.BaseRequest03;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.CollectionUtils;
@@ -170,7 +171,55 @@ public class HttpsURLConnectionUtil {
         return response.toString();
     }
 
+    public static String doGet03(BaseRequest03 request){
+        String httpUrl = request.getUrl();
+        Map<String, String> headers = request.getHeader();
+        logger.info("HttpsURLConnectionUtil,doGet,URL:{}, headers:{}", httpUrl, headers);
+        StringBuilder response = new StringBuilder();
+        BufferedReader bufferedReader = null;
+
+        try{
+            //创建连接
+            URL url = new URL(httpUrl);
+            HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
+            //忽略ssl验证
+            //disableSslVerification(connection);
+            //设置请求方式
+            connection.setRequestMethod(Constant.HTTP_GET);
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
+            //设置自定义请求头信息
+            setCustomHeader(connection, headers);
 
+            //设置请求超时时间:10秒
+            connection.setConnectTimeout(10 * 1000);
+            //设置读取超时时间:10秒
+            connection.setReadTimeout(10 * 1000);
+            //开始连接
+            connection.connect();
+            if(connection.getResponseCode() == 404){
+                JSONObject result = new JSONObject();
+                result.put("code","404");
+                result.put("errMsg","子系统未安装或接口与版本不匹配");
+                return result.toJSONString();
+            }
+            //获取响应数据
+            String readLine = null;
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+            while((readLine = bufferedReader.readLine()) != null){
+                response.append(readLine);
+            }
+            bufferedReader.close();
+        }catch (MalformedURLException e){
+            logger.error("HttpsURLConnectionUtil,doGet,request error:{}", e.getMessage());
+            e.printStackTrace();
+        }catch (IOException e){
+            logger.error("HttpsURLConnectionUtil,doGet,request error:{}", e.getMessage());
+            e.printStackTrace();
+        }
+        return response.toString();
+    }
     /**
      * @param httpUrl 请求地址
      * @param jsonStr json字符串格式的请求数据