whyclxw
2024-04-28 b25b814a949d2065a61fd3167206ffb51a57af65
src/main/java/com/whyc/service/InterfaceService.java
@@ -1,5 +1,6 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -22,6 +23,8 @@
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.util.*;
@@ -77,7 +80,7 @@
        if (flag == 1) {
            //分页信息
            PageHelper.startPage(pageNum, pageSize);
            List list = battInfMapper.selectList(null);
            List list = battInfMapper.selectList((Wrapper<Battinf>) ActionUtil.objeNull);
            PageInfo pageInfo = new PageInfo(list);
            return new Response().set(1, pageInfo);
        } else {
@@ -91,7 +94,7 @@
        if (flag == 1) {
            //分页信息
            PageHelper.startPage(pageNum, pageSize);
            List list = powerInfMapper.selectList(null);
            List list = powerInfMapper.selectList((Wrapper<PowerInf>) ActionUtil.objeNull);
            PageInfo pageInfo = new PageInfo(list);
            return new Response().set(1, pageInfo);
        } else {
@@ -280,7 +283,7 @@
    //获取所有第三方码的信息
    public Response getInterface(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Interface> list = interfaceMapper.selectList(null);
        List<Interface> list = interfaceMapper.selectList((Wrapper<Interface>) ActionUtil.objeNull);
        if (list != null && list.size() > 0) {
            for (Interface iface : list) {
                String random = iface.getInterfaceNumber();
@@ -292,7 +295,7 @@
    }
    //生成第三方验证码
    public Response createInterface(String interfaceName) {
    public Response createInterface(String interfaceName) throws NoSuchAlgorithmException {
        String random = getRandomString(25);
        //rsa加密
        String encryptRandom = RSAUtil.encrypt(random, RSAUtil.getPublicKey());
@@ -310,7 +313,7 @@
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.set("enable", enable);
        wrapper.eq("num", num);
        interfaceMapper.update(null, wrapper);
        interfaceMapper.update((Interface) ActionUtil.objeNull, wrapper);
        return new Response().set(1, true, "编辑是否可用");
    }
@@ -333,9 +336,11 @@
    }
    //length用户要求产生字符串的长度
    public static String getRandomString(int length) {
    public static String getRandomString(int length) throws NoSuchAlgorithmException {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        //Random random = new Random();
        SecureRandom  random = SecureRandom.getInstance("SHA1PRNG");
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(62);