Browse Source

add:提供直接认证接口,并自动生成账号

xuexiaobo 6 years ago
parent
commit
0c528169fe

+ 5 - 0
core/src/main/java/com/mooctest/crowd/domain/factory/UserFactory.java

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.domain.factory;
 package com.mooctest.crowd.domain.factory;
 
 
+import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.domain.domainobject.User;
 
 
 /**
 /**
@@ -11,4 +12,8 @@ public class UserFactory {
     public static User createUser() {
     public static User createUser() {
         return new User();
         return new User();
     }
     }
+
+    public static EvaluationAgency defaultAgency() {
+        return new EvaluationAgency();
+    }
 }
 }

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/model/UserToRolePO.java

@@ -1,6 +1,8 @@
 package com.mooctest.crowd.domain.model;
 package com.mooctest.crowd.domain.model;
 
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 
 import javax.persistence.*;
 import javax.persistence.*;
 import java.sql.Timestamp;
 import java.sql.Timestamp;

+ 22 - 8
core/src/main/java/com/mooctest/crowd/domain/repository/UserRepo.java

@@ -8,6 +8,7 @@ import com.mooctest.crowd.domain.exception.RoleNotFoundException;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.util.Converter;
 import com.mooctest.crowd.domain.util.Converter;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
@@ -192,23 +193,30 @@ public class UserRepo implements IUserRepo {
      * @throws RoleNotFoundException
      * @throws RoleNotFoundException
      */
      */
     private User saveRoleAndPermissionAndEvaluationAgencyByUser(User user) throws RoleNotFoundException {
     private User saveRoleAndPermissionAndEvaluationAgencyByUser(User user) throws RoleNotFoundException {
-        userDao.save(Converter.convert(UserPO.class, user));
+        UserPO userPO = userDao.save(Converter.convert(UserPO.class, user));
         List<Role> roleList = user.getRoleList();
         List<Role> roleList = user.getRoleList();
+        if (roleList==null || roleList.size()==0){
+            UserToRolePO u2r = new UserToRolePO();
+            u2r.setUserId(userPO.getId());
+            u2r.setRoleId(1L);
+            userToRoleDao.save(u2r);
+        }
+        List<UserToRolePO> userToRolePOList = userToRoleDao.findByUserId(userPO.getId());
         for(Role role : roleList){
         for(Role role : roleList){
-            RolePO rolePO = Converter.convert(RolePO.class, role);
-            roleDao.save(rolePO);
-            List<Permission> permissionList = role.getPermissionList();
-            for(Permission permission : permissionList){
-                PermissionPO permissionPO = Converter.convert(PermissionPO.class, permission);
-                permissionDao.save(permissionPO);
+            if (!userToRolePOList.stream().filter(userToRolePO -> userToRolePO.getRoleId() == role.getId()).findFirst().isPresent()) {
+                UserToRolePO userToRolePO = new UserToRolePO();
+                userToRolePO.setRoleId(role.getId());
+                userToRolePO.setUserId(userPO.getId());
+                userToRoleDao.save(userToRolePO);
             }
             }
         }
         }
         EvaluationAgency evaluationAgency = user.getEvaluationAgency();
         EvaluationAgency evaluationAgency = user.getEvaluationAgency();
         if(evaluationAgency != null){
         if(evaluationAgency != null){
             EvaluationAgencyPO evaluationAgencyPO = Converter.convert(EvaluationAgencyPO.class, evaluationAgency);
             EvaluationAgencyPO evaluationAgencyPO = Converter.convert(EvaluationAgencyPO.class, evaluationAgency);
+            evaluationAgencyPO.setUserId(userPO.getId());
             evaluationAgencyDao.save(evaluationAgencyPO);
             evaluationAgencyDao.save(evaluationAgencyPO);
         }
         }
-        return user;
+        return getByID(userPO.getId());
     }
     }
 
 
     /**
     /**
@@ -306,4 +314,10 @@ public class UserRepo implements IUserRepo {
         userResult.setRegionalManager(regionalManager);
         userResult.setRegionalManager(regionalManager);
         return userResult;
         return userResult;
     }
     }
+
+    public Role getRole(String roleName){
+        Role role = new Role();
+        BeanUtils.copyProperties(roleDao.findByName(roleName), role);
+        return role;
+    }
 }
 }

+ 3 - 0
site/src/main/java/com/mooctest/crowd/site/anticorruption/UserAntiCorruption.java

@@ -1,9 +1,12 @@
 package com.mooctest.crowd.site.anticorruption;
 package com.mooctest.crowd.site.anticorruption;
 
 
+import com.mooctest.crowd.domain.domainobject.User;
+
 /**
 /**
  * @author: Diors.Po
  * @author: Diors.Po
  * @Email: 171256175@qq.com
  * @Email: 171256175@qq.com
  * @date 2019-08-08 23:40
  * @date 2019-08-08 23:40
  */
  */
 public interface UserAntiCorruption {
 public interface UserAntiCorruption {
+    User register(String name, String mobile, String password);
 }
 }

+ 46 - 0
site/src/main/java/com/mooctest/crowd/site/anticorruption/impl/UserAntiCorruptionImpl.java

@@ -1,7 +1,23 @@
 package com.mooctest.crowd.site.anticorruption.impl;
 package com.mooctest.crowd.site.anticorruption.impl;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.mooctest.crowd.domain.domainobject.User;
+import com.mooctest.crowd.domain.factory.UserFactory;
+import com.mooctest.crowd.domain.repository.UserRepo;
 import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
 import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
+import com.mooctest.crowd.site.anticorruption.impl.data.UserInfo;
+import com.mooctest.crowd.site.util.EncryptionUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
 /**
  * @author: Diors.Po
  * @author: Diors.Po
@@ -10,4 +26,34 @@ import org.springframework.stereotype.Component;
  */
  */
 @Component
 @Component
 public class UserAntiCorruptionImpl implements UserAntiCorruption {
 public class UserAntiCorruptionImpl implements UserAntiCorruption {
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Autowired
+    private UserRepo userRepo;
+
+    @Value("${user.service.baseUrl}")
+    private String userServiceUrl;
+
+    @Override
+    public User register(String name, String mobile, String password) {
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+        JSONObject params = new JSONObject();
+        params.put("name", name);
+        params.put("mobile", mobile);
+        params.put("email", name+"@mooctest.net");
+        params.put("password", EncryptionUtil.encryptMD5(password));
+        params.put("createTime", System.currentTimeMillis());
+
+        HttpEntity<String> entity = new HttpEntity<>(params.toString() , httpHeaders);
+        UserInfo userInfo = restTemplate.exchange(userServiceUrl + "/api/user", HttpMethod.POST, entity, UserInfo.class).getBody();
+        User user = UserFactory.createUser();
+        user.setId(userInfo.getId());
+        user.setName(userInfo.getName());
+        user.setUserName(userInfo.getName());
+        user.setMobile(mobile);
+        user.setPassword(userInfo.getPassword());
+        return user;
+    }
 }
 }

+ 25 - 0
site/src/main/java/com/mooctest/crowd/site/anticorruption/impl/data/UserInfo.java

@@ -0,0 +1,25 @@
+package com.mooctest.crowd.site.anticorruption.impl.data;
+
+import lombok.Data;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:47
+ */
+@Data
+public class UserInfo {
+    private Long id;
+    private String email;
+    private String name;
+    private String mobile;
+    private String password;
+    private Long createTime;
+    private String school;
+    private String photoUrl;
+    private String province;
+    private String city;
+    private Boolean manualCheckValid;
+    private Integer availability;
+    private Long integral;
+}

+ 40 - 0
site/src/main/java/com/mooctest/crowd/site/command/ApplyAgencyAuthCommand.java

@@ -0,0 +1,40 @@
+package com.mooctest.crowd.site.command;
+
+import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
+import com.mooctest.crowd.domain.factory.UserFactory;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:05
+ */
+@Data
+public class ApplyAgencyAuthCommand {
+
+    @NotNull(message = "手机号不可为空")
+    private String mobile;
+    @NotNull(message = "机构名称不可为空")
+    private String evaluationAgencyName;
+    @NotNull(message = "银行卡号不可为空")
+    private String bankAccount;
+    @NotNull(message = "机构地址不可为空")
+    private String address;
+    @NotNull(message = "评测能力不可为空")
+    private String abilities;
+    @NotNull(message = "机构资源不可为空")
+    private String resources;
+    @NotNull(message = "LOGO不可为空")
+    private String agencyPhoto;
+
+    public EvaluationAgency toAgency(){
+        EvaluationAgency agency = UserFactory.defaultAgency();
+        BeanUtils.copyProperties(this, agency);
+        agency.setIsDeleted(0);
+        agency.setIsAuthentication(0);
+        return agency;
+    }
+}

+ 28 - 0
site/src/main/java/com/mooctest/crowd/site/configuration/RestTemplateConfiguration.java

@@ -0,0 +1,28 @@
+package com.mooctest.crowd.site.configuration;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.client.ClientHttpRequestFactory;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:25
+ */
+@Configuration
+public class RestTemplateConfiguration {
+    @Bean
+    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
+        return new RestTemplate(factory);
+    }
+
+    @Bean
+    public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
+        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
+        factory.setConnectTimeout(15000);
+        factory.setReadTimeout(5000);
+        return factory;
+    }
+}

+ 28 - 0
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -0,0 +1,28 @@
+package com.mooctest.crowd.site.controller;
+
+import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
+import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.service.AgencyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:02
+ */
+@RestController
+@RequestMapping("/api")
+public class AgencyController {
+
+    @Autowired
+    private AgencyService agencyService;
+
+    @RequestMapping(value = "greenChannel/agency", method = RequestMethod.POST)
+    public UserDTO generateAgency(@RequestBody ApplyAgencyAuthCommand command){
+        return agencyService.generateAgency(command);
+    }
+}

+ 28 - 0
site/src/main/java/com/mooctest/crowd/site/controller/TestController.java

@@ -1,15 +1,24 @@
 package com.mooctest.crowd.site.controller;
 package com.mooctest.crowd.site.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.mooctest.crowd.site.annotation.LoginRequired;
 import com.mooctest.crowd.site.annotation.LoginRequired;
+import com.mooctest.crowd.site.anticorruption.impl.data.UserInfo;
 import com.mooctest.crowd.site.service.CrowdProjectService;
 import com.mooctest.crowd.site.service.CrowdProjectService;
 import com.mooctest.crowd.site.service.UploadService;
 import com.mooctest.crowd.site.service.UploadService;
 import com.mooctest.crowd.site.util.FileUtil;
 import com.mooctest.crowd.site.util.FileUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
 /**
  * @author: Diors.Po
  * @author: Diors.Po
@@ -23,6 +32,25 @@ public class TestController {
     @Autowired
     @Autowired
     private CrowdProjectService projectService;
     private CrowdProjectService projectService;
 
 
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @RequestMapping(value = "/test/rest", method = RequestMethod.POST)
+    public Object restTemplateTest() throws IOException {
+        String url = "http://111.231.143.6:8081/api/user";
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+        JSONObject params = new JSONObject();
+        params.put("name", "xxb");
+        params.put("mobile", "32112321331");
+        params.put("email", "name@q.com");
+        params.put("password", "111111");
+        params.put("createTime", System.currentTimeMillis());
+
+        HttpEntity<String> entity = new HttpEntity<>(params.toString() , httpHeaders);
+        return restTemplate.exchange(url, HttpMethod.POST,entity, UserInfo.class).getBody();
+    }
+
     @RequestMapping(value = "/test", method = RequestMethod.POST)
     @RequestMapping(value = "/test", method = RequestMethod.POST)
     public Object exceptionTest(MultipartFile file) throws IOException {
     public Object exceptionTest(MultipartFile file) throws IOException {
         return FileUtil.checkFile(file.getInputStream());
         return FileUtil.checkFile(file.getInputStream());

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/UserDTO.java

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.data.dto;
 package com.mooctest.crowd.site.data.dto;
 
 
+import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.CrowdProjectVO;
 import com.mooctest.crowd.site.data.vo.CrowdProjectVO;
 import com.mooctest.crowd.site.data.vo.UserVO;
 import com.mooctest.crowd.site.data.vo.UserVO;
 import com.mooctest.crowd.domain.domainobject.Permission;
 import com.mooctest.crowd.domain.domainobject.Permission;
@@ -18,6 +19,7 @@ import java.util.List;
 @AllArgsConstructor
 @AllArgsConstructor
 public class UserDTO {
 public class UserDTO {
     private UserVO userVO;
     private UserVO userVO;
+    private AgencyVO agencyVO;
     private List<Permission> permissions;
     private List<Permission> permissions;
     private List<CrowdProjectVO> crowdProjectVOS;
     private List<CrowdProjectVO> crowdProjectVOS;
 
 

+ 27 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/AgencyVO.java

@@ -0,0 +1,27 @@
+package com.mooctest.crowd.site.data.vo;
+
+import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.beans.BeanUtils;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 02:59
+ */
+@Data
+@NoArgsConstructor
+public class AgencyVO {
+    private Long userId;
+    private String evaluationAgencyName;
+    private String bankAccount;
+    private String address;
+    private String abilities;
+    private String resources;
+    private String agencyPhoto;
+
+    public AgencyVO(EvaluationAgency agency){
+        BeanUtils.copyProperties(agency, this);
+    }
+}

+ 1 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/UserVO.java

@@ -20,6 +20,7 @@ public class UserVO {
     private String userName;
     private String userName;
     private String gender;
     private String gender;
     private String mobileNum;
     private String mobileNum;
+    private String password;
     private String province;
     private String province;
     private String city;
     private String city;
     private String photoUrl;
     private String photoUrl;

+ 15 - 0
site/src/main/java/com/mooctest/crowd/site/service/AgencyService.java

@@ -0,0 +1,15 @@
+package com.mooctest.crowd.site.service;
+
+import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
+import com.mooctest.crowd.site.data.dto.UserDTO;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:18
+ */
+public interface AgencyService {
+    UserDTO applyAgency(Long userId, ApplyAgencyAuthCommand command);
+
+    UserDTO generateAgency(ApplyAgencyAuthCommand command);
+}

+ 59 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -0,0 +1,59 @@
+package com.mooctest.crowd.site.service.impl;
+
+import com.fasterxml.jackson.databind.ser.Serializers;
+import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
+import com.mooctest.crowd.domain.domainobject.Role;
+import com.mooctest.crowd.domain.domainobject.User;
+import com.mooctest.crowd.domain.exception.BaseException;
+import com.mooctest.crowd.domain.factory.UserFactory;
+import com.mooctest.crowd.domain.repository.UserRepo;
+import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
+import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
+import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.data.vo.AgencyVO;
+import com.mooctest.crowd.site.data.vo.UserVO;
+import com.mooctest.crowd.site.service.AgencyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:20
+ */
+@Service
+public class AgencyServiceImpl implements AgencyService {
+
+    @Autowired
+    private UserAntiCorruption userAnti;
+
+    @Autowired
+    private UserRepo userRepo;
+
+    @Override
+    public UserDTO applyAgency(Long userId, ApplyAgencyAuthCommand command) {
+        return null;
+    }
+
+    @Override
+    public UserDTO generateAgency(ApplyAgencyAuthCommand command) {
+        if (userRepo.getByMobileNum(command.getMobile()) != null)
+            throw new BaseException("该电话已存在");
+        User user = userAnti.register(command.getEvaluationAgencyName(), command.getMobile(), command.getMobile());
+        EvaluationAgency agency = command.toAgency();
+        List<Role> roles = new ArrayList<>();
+        roles.add(userRepo.getRole("evaluationAgency"));
+        roles.add(userRepo.getRole("generalUser"));
+        user.setRoleList(roles);
+        agency.setUserId(user.getId());
+        user.setEvaluationAgency(agency);
+        user = userRepo.saveUser(user);
+        UserDTO userDTO = new UserDTO();
+        userDTO.setUserVO(new UserVO(userRepo.getByID(user.getId())));
+        userDTO.setAgencyVO(new AgencyVO(userRepo.getByID(user.getId()).getEvaluationAgency()));
+        return userDTO;
+    }
+}

+ 147 - 0
site/src/main/java/com/mooctest/crowd/site/util/EncryptionUtil.java

@@ -0,0 +1,147 @@
+package com.mooctest.crowd.site.util;
+
+import lombok.extern.slf4j.Slf4j;
+import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:32
+ */
+@Slf4j
+public class EncryptionUtil {
+    // 定义 加密算法,可用 DES,DESede,Blowfish
+    private static String Algorithm = "DES";
+    private static String defaultKey = "witest.net";
+
+
+    public static String encryptMD5(String str) {
+        String s = str;
+        if (s == null) {
+            return "";
+        } else {
+            String value = null;
+            MessageDigest md5 = null;
+            try {
+                md5 = MessageDigest.getInstance("MD5");
+            } catch (NoSuchAlgorithmException ex) {
+                log.error("", ex);
+            }
+            sun.misc.BASE64Encoder baseEncoder = new sun.misc.BASE64Encoder();
+            try {
+                value = baseEncoder.encode(md5.digest(s.getBytes("utf-8")));
+            } catch (Exception ex) {
+            }
+            return value;
+        }
+    }
+
+    public static String encryptDES(String content) throws Exception {
+        return encryptDES(content, defaultKey);
+    }
+
+    public static String decryptDES(String content) throws Exception {
+        return decryptDES(content, defaultKey);
+    }
+
+
+    /**
+     * Description 根据键值进行加密
+     *
+     * @param data
+     * @param key  加密键byte数组
+     * @return
+     * @throws Exception
+     */
+    public static String encryptDES(String data, String key) throws Exception {
+        byte[] bt = encryptDES(data.getBytes(), key.getBytes());
+        String strs = new BASE64Encoder().encode(bt);
+        return strs;
+    }
+
+    /**
+     * Description 根据键值进行解密
+     *
+     * @param data
+     * @param key  加密键byte数组
+     * @return
+     * @throws IOException
+     * @throws Exception
+     */
+    public static String decryptDES(String data, String key) throws IOException,
+            Exception {
+        if (data == null)
+            return null;
+        BASE64Decoder decoder = new BASE64Decoder();
+        byte[] buf = decoder.decodeBuffer(data);
+        byte[] bt = decryptDES(buf, key.getBytes());
+        return new String(bt);
+    }
+
+    /**
+     * Description 根据键值进行加密
+     *
+     * @param data
+     * @param key  加密键byte数组
+     * @return
+     * @throws Exception
+     */
+    private static byte[] encryptDES(byte[] data, byte[] key) throws Exception {
+        // 生成一个可信任的随机数源
+        SecureRandom sr = new SecureRandom();
+
+        // 从原始密钥数据创建DESKeySpec对象
+        DESKeySpec dks = new DESKeySpec(key);
+
+        // 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(Algorithm);
+        SecretKey securekey = keyFactory.generateSecret(dks);
+
+        // Cipher对象实际完成加密操作
+        Cipher cipher = Cipher.getInstance(Algorithm);
+
+        // 用密钥初始化Cipher对象
+        cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
+
+        return cipher.doFinal(data);
+    }
+
+
+    /**
+     * Description 根据键值进行解密
+     *
+     * @param data
+     * @param key  加密键byte数组
+     * @return
+     * @throws Exception
+     */
+    private static byte[] decryptDES(byte[] data, byte[] key) throws Exception {
+        // 生成一个可信任的随机数源
+        SecureRandom sr = new SecureRandom();
+
+        // 从原始密钥数据创建DESKeySpec对象
+        DESKeySpec dks = new DESKeySpec(key);
+
+        // 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(Algorithm);
+        SecretKey securekey = keyFactory.generateSecret(dks);
+
+        // Cipher对象实际完成解密操作
+        Cipher cipher = Cipher.getInstance(Algorithm);
+
+        // 用密钥初始化Cipher对象
+        cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
+
+        return cipher.doFinal(data);
+    }
+}

+ 3 - 0
site/src/main/resources/application.yml

@@ -46,3 +46,6 @@ oss:
   accessKeySecret: dYml7rvT8stQkoSjMYlfRTxNj9dEsI
   accessKeySecret: dYml7rvT8stQkoSjMYlfRTxNj9dEsI
   endPoint: oss-cn-hangzhou.aliyuncs.com
   endPoint: oss-cn-hangzhou.aliyuncs.com
   bucketName: mooctest-crowd-service
   bucketName: mooctest-crowd-service
+user:
+  service:
+    baseUrl: http://111.231.143.6:8081