Explorar o código

添加泰康 login 接口

wlq hai 1 ano
pai
achega
2ab187cd4d

+ 39 - 0
tenant/insurance/quotation-taikang/src/main/java/com/jzg/quotation/taikang/client/AESEncryption.java

@@ -0,0 +1,39 @@
+package com.jzg.quotation.taikang.client;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+public class AESEncryption {
+
+    /**
+     *
+     * @param word 要加密的字符串
+     * @param key 加密密钥
+     * @return
+     */
+    public static String encryptPassing(String word, String key) {
+        try {
+            // 要加密的字符串
+            String keyStr = word;
+
+            // 创建 AES 密钥
+            SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
+
+            // 创建 Cipher 实例,使用 AES/ECB/PKCS5Padding
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+
+            // 加密
+            byte[] encryptedBytes = cipher.doFinal(keyStr.getBytes(StandardCharsets.UTF_8));
+
+            // 返回 Base64 编码的加密结果
+            return Base64.getEncoder().encodeToString(encryptedBytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+}

+ 17 - 0
tenant/insurance/quotation-taikang/src/main/java/com/jzg/quotation/taikang/entity/LoginParam.java

@@ -0,0 +1,17 @@
+package com.jzg.quotation.taikang.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ *
+ * { "userName":"Tgengchenjie", "channelCode":"OffWeb", "password":"CI3NVut7IQUhVnsef1Cp8w==" }
+ *
+ */
+@Setter
+@Getter
+public class LoginParam {
+    private String channelCode;
+    private String userName;
+    private String password;
+}

+ 343 - 0
tenant/insurance/quotation-taikang/src/main/java/com/jzg/quotation/taikang/entity/LoginResult.java

@@ -0,0 +1,343 @@
+package com.jzg.quotation.taikang.entity;
+
+import com.jzg.quotation.taikang.client.BaseResponse;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class LoginResult {
+    @Setter
+    @Getter
+    public static class Response extends BaseResponse<LoginResult> {
+
+    }
+
+
+    /**
+     * 平台ID
+     */
+    private String tplatformId;
+
+    /**
+     * 用户信息
+     */
+    private WebsysUserVo websysUserVo;
+
+    /**
+     * 登录密钥
+     */
+    private String tplatLoginKey;
+
+    /**
+     * 登录状态
+     */
+    private String loginStatus;
+
+    /**
+     * 消息
+     */
+    private String message;
+
+    /**
+     * 用户ID
+     */
+    private String userId;
+
+    /**
+     * Token
+     */
+    private String token;
+
+    @Getter
+    @Setter
+    public static class WebsysUserVo {
+
+        /**
+         * 用户区域信息
+         */
+        private List<WebsysUserAreaVo> websysUserAreaVos;
+
+        /**
+         * 用户组区域信息
+         */
+        private List<Object> websysUserGroupAreaVos;
+
+        /**
+         * 生活车锁渠道
+         */
+        private String lifeCarLockChannel;
+
+        /**
+         * 来源ID
+         */
+        private String fromid;
+
+        /**
+         * 期望折扣
+         */
+        private String expectDiscount;
+
+        /**
+         * 用户网络订单信息
+         */
+        private List<Object> websysUserNetworkOrderVos;
+
+        /**
+         * 客户标识标志
+         */
+        private String customerIdentifierFlag;
+
+        /**
+         * 属性
+         */
+        private String property;
+
+        /**
+         * 税务分类
+         */
+        private String taxClassification;
+
+        /**
+         * 用户角色信息
+         */
+        private List<WebsysRoleVo> websysRoleVos;
+
+        /**
+         * 用户ID
+         */
+        private String id;
+
+        /**
+         * 用户中文名
+         */
+        private String usercnname;
+
+        /**
+         * 重复保险
+         */
+        private String repeatInsurance;
+
+        /**
+         * 用户菜单
+         */
+        private List<WebsysMenu> websysMenus;
+
+        /**
+         * 期望赔付比例
+         */
+        private String expectpayoutratio;
+
+        /**
+         * IP地址
+         */
+        private String ip;
+
+        /**
+         * 手机号
+         */
+        private String mobile;
+
+        /**
+         * 渠道名称
+         */
+        private String channelname;
+
+        /**
+         * 渠道代码
+         */
+        private String channelcode;
+
+        /**
+         * 用户渠道信息
+         */
+        private WebsysUserChannelVo websysUserChannelVo;
+
+        /**
+         * 用户组订单区域信息
+         */
+        private List<Object> websysUserGroupOrderAreaVos;
+
+        /**
+         * 匹配名称代码
+         */
+        private String matchingNameCode;
+
+        /**
+         * 活动配置
+         */
+        private String activeConfig;
+
+        /**
+         * 渠道列表
+         */
+        private List<ChannelVo> channelVoList;
+
+        /**
+         * 等级
+         */
+        private String gradeowns;
+
+        /**
+         * 软提示标志
+         */
+        private String softTipFlag;
+
+        /**
+         * 用户权限信息
+         */
+        private List<WebsysPermissionVo> websysPermissionVos;
+
+        /**
+         * 用户名
+         */
+        private String username;
+    }
+
+    @Getter
+    @Setter
+    public static class WebsysUserAreaVo {
+
+        /**
+         * 区域名称
+         */
+        private String areaname;
+
+        /**
+         * 区域代码
+         */
+        private String areacode;
+    }
+
+    @Getter
+    @Setter
+    public static class WebsysRoleVo {
+
+        /**
+         * 角色代码
+         */
+        private String roleCode;
+
+        /**
+         * 角色名称
+         */
+        private String roleName;
+
+        /**
+         * 描述
+         */
+        private String description;
+
+        /**
+         * 角色ID
+         */
+        private String id;
+
+        /**
+         * 角色权限信息
+         */
+        private List<WebsysPermissionVo> websysPermissionVos;
+    }
+
+    @Getter
+    @Setter
+    public static class WebsysPermissionVo {
+
+        /**
+         * 子权限
+         */
+        private List<WebsysPermissionVo> children;
+
+        /**
+         * 权限名称
+         */
+        private String name;
+
+        /**
+         * 权限ID
+         */
+        private String id;
+
+        /**
+         * 权限代码
+         */
+        private String permissionCode;
+    }
+
+    @Getter
+    @Setter
+    public static class WebsysMenu {
+
+        /**
+         * 子菜单
+         */
+        private List<WebsysMenu> children;
+
+        /**
+         * 菜单URL
+         */
+        private String menuUrl;
+
+        /**
+         * 发送URL
+         */
+        private String sendUrl;
+
+        /**
+         * 菜单代码
+         */
+        private Integer menuCode;
+
+        /**
+         * 菜单名称
+         */
+        private String name;
+
+        /**
+         * 菜单ID
+         */
+        private String id;
+    }
+
+    @Getter
+    @Setter
+    public static class WebsysUserChannelVo {
+
+        /**
+         * 中介中文名
+         */
+        private String intermediarycnname;
+
+        /**
+         * 中介代码
+         */
+        private String intermediarycode;
+
+        /**
+         * 来源ID
+         */
+        private String fromid;
+    }
+
+    @Getter
+    @Setter
+    public static class ChannelVo {
+
+        /**
+         * 中介中文名
+         */
+        private String intermediarycnname;
+
+        /**
+         * 中介代码
+         */
+        private String intermediarycode;
+
+        /**
+         * 来源ID
+         */
+        private String fromid;
+    }
+}

+ 31 - 5
tenant/insurance/quotation-taikang/src/main/java/com/jzg/quotation/taikang/service/TaiKangHttpService.java

@@ -1,10 +1,7 @@
 package com.jzg.quotation.taikang.service;
 
 import com.jzg.quotation.taikang.JsonUtil;
-import com.jzg.quotation.taikang.client.AESDecryptor;
-import com.jzg.quotation.taikang.client.HttpURL;
-import com.jzg.quotation.taikang.client.StringResponse;
-import com.jzg.quotation.taikang.client.TaiKangHttpClient;
+import com.jzg.quotation.taikang.client.*;
 import com.jzg.quotation.taikang.entity.*;
 import lombok.Setter;
 import org.slf4j.Logger;
@@ -31,6 +28,31 @@ public class TaiKangHttpService {
         throw new RuntimeException("token 为 null,请先登录!");
     }
 
+    /**
+     * 01 登录
+     * @param username
+     * @param password
+     * @return
+     */
+    public LoginResult login(String username, String password, String token) {
+        String key = "hh43jii5e954eD54";
+        String encrypted = AESEncryption.encryptPassing(password, key);
+
+        LoginParam param = new LoginParam();
+        param.setChannelCode("OffWeb");
+        param.setUserName(username);
+        param.setPassword(encrypted);
+
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.add("Authorization", token);
+        httpHeaders.add("actiontype", "queryClaimData");
+
+        LoginResult.Response response = client.requestUrl(HttpURL.login, param, LoginResult.Response.class, httpHeaders);
+
+        return response.getData();
+    }
+
+
     /**
      * 01 登录,获取 token
      *
@@ -39,9 +61,13 @@ public class TaiKangHttpService {
      */
     public String identityToken(String tplatformId) {
         IdentityTokenParam identityTokenParam = new IdentityTokenParam();
-        identityTokenParam.setTplatformId(tplatformId);
+
         identityTokenParam.setChannelCode("OffWeb");
 
+        if (tplatformId != null) {
+            identityTokenParam.setTplatformId(tplatformId);
+        }
+
         HttpHeaders httpHeaders = new HttpHeaders();
 
         IdentityTokenResult.Response response = client.requestUrl(HttpURL.identityToken, identityTokenParam, IdentityTokenResult.Response.class, httpHeaders);

+ 18 - 0
tenant/insurance/quotation-taikang/src/test/java/com/jzg/quotation/taikang/AESEncryptionTest.java

@@ -0,0 +1,18 @@
+package com.jzg.quotation.taikang;
+
+import com.jzg.quotation.taikang.client.AESEncryption;
+
+public class AESEncryptionTest {
+
+
+    public static void main(String[] args) {
+        try {
+            String word = "Gcj123456#";
+            String key = "hh43jii5e954eD54"; // 确保密钥是16字节(128位)
+            String encrypted = AESEncryption.encryptPassing(word, key);
+            System.out.println("Encrypted: " + encrypted);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 15 - 0
tenant/insurance/quotation-taikang/src/test/java/com/jzg/quotation/taikang/service/TaiKangHttpServiceTest.java

@@ -43,6 +43,21 @@ public class TaiKangHttpServiceTest {
     }
 
 
+    @Test
+    @Order(0)
+    public void login() {
+        String firstToken = taiKangHttpService.identityToken(null);
+
+        LoginResult result = taiKangHttpService.login("Tgengchenjie", "Gcj123456#", firstToken);
+
+        assertNotNull(result);
+        assertNotNull(result.getToken());
+        assertNotNull(result.getTplatLoginKey());
+        assertNotNull(result.getTplatformId());
+        assertNotNull(result.getUserId());
+        assertEquals("0", result.getLoginStatus());
+    }
+
     @Test
     @Order(1)
     public void identityToken() {