1.建立标签:防止重复提交

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AvoidDuplicate {
}

2.建立切面,redis加锁

  @Around(value =  "@annotation(com.cloud.drore.eboos.common.annotation.AvoidDuplicate)")public Object excute(ProceedingJoinPoint joinPoint) throws Throwable{try {Object result = null;Object[] args = joinPoint.getArgs();//redis加锁result =  validation(joinPoint);return result;} catch (Exception e) {e.printStackTrace();return ResultMessage.error(8300,"请不要重复提交!!");}}

3.方法执行之后进行解锁

  public Object validation(ProceedingJoinPoint  joinPoint) throws Throwable {String cachekey =  getCacheKey(joinPoint.toLongString(),joinPoint.getArgs());//redis加锁boolean lock =  jedisUtils.tryGetDistributedLock(PARAM_TOKEN_FLAG+cachekey, cachekey, 60000);if(lock){//加锁成功//执行方法Object funcResult = joinPoint.proceed();//方法执行完之后进行解锁jedisUtils.releaseDistributedLock(PARAM_TOKEN_FLAG +  cachekey, cachekey);return funcResult;}else{//锁已存在return ResultMessage.error(8300,"请不要重复提交!!");}}

4.加锁和释放锁

package com.cloud.drore.eboos.common.util;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;import java.util.Collections;/*** ** @Description: <br>* @Project: eboos <br>* @CreateDate: Created in 2018/4/18 14:18 <br>* @Author: */
@Component
public class JedisUtils {@AutowiredJedisPool jedisPool;private static final String LOCK_SUCCESS = "OK";private static final String SET_IF_NOT_EXIST = "NX";private static final String SET_WITH_EXPIRE_TIME = "PX";//PX表示超时时间是毫秒设置,EX表示超时时间是分钟设置private static final Long RELEASE_SUCCESS = 1L;/*** 尝试获取分布式锁* @param lockKey 锁* @param requestId 请求标识* @param expireTime 超期时间* @return 是否获取成功*/public boolean tryGetDistributedLock(String lockKey, String requestId, int expireTime) {//从连接池获取连接Jedis jedis = null;try{jedis = jedisPool.getResource();String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, expireTime);if (LOCK_SUCCESS.equals(result)) {return true;}return false;}catch(Exception e) {e.printStackTrace();return false;}finally{//归还连接到redis池中jedis.close();}}/*** 释放分布式锁* @param lockKey 锁* @param requestId 请求标识* @return 是否释放成功*/public boolean releaseDistributedLock(String lockKey, String requestId) {//从连接池获取连接Jedis jedis = null;try{jedis = jedisPool.getResource();String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";Object result = jedis.eval(script, Collections.singletonList(lockKey), Collections.singletonList(requestId));if (RELEASE_SUCCESS.equals(result)) {return true;}return false;}catch(Exception e) {e.printStackTrace();return false;}finally{//归还连接到redis池中jedis.close();}}}

5.用到的工具类

 private String getCacheKey(String targetName, Object[] arguments) {StringBuffer sb = new StringBuffer();UserInfo userInfo = LocalData.getCurrentUser();if(userInfo!=null)sb.append(userInfo.getId()+PARAM_LINE+LocalData.getCurrentUser().getUsername()).append(PARAM_POINT);sb.append(targetName);if ((arguments != null) && (arguments.length != 0)) {for (int i = 0; i < arguments.length; i++) {// 处理空指针 基本数据类型sb.append(PARAM_POINT).append(arguments[i] == null ? "" : getValue(arguments[i]));}}return Codec.encodeMd5(sb.toString());}public String getValue(Object obj) {if (obj.getClass().isArray()) {StringBuffer buf = new StringBuffer();Object[] array = (Object[]) obj;for (Object value : array) {if (value != null) {buf.append(value.toString()).append(",");}}return buf.toString();}return JSONObject.toJSONString(obj);}

6.codec

package com.cloud.drore.eboos.common.util.security;import java.security.MessageDigest;/*** Created by wcy on 2016/8/25.*/
public class Codec
{public static String encodeMd5(String keys){MessageDigest md5 = null;try{md5 = MessageDigest.getInstance("MD5");} catch (Exception e){e.printStackTrace();return "";}char[] charArray = keys.toCharArray();byte[] byteArray = new byte[charArray.length];for (int i = 0; i < charArray.length; i++)byteArray[i] = (byte) charArray[i];byte[] md5Bytes = md5.digest(byteArray);StringBuffer hexValue = new StringBuffer();for (int i = 0; i < md5Bytes.length; i++){int val = ((int) md5Bytes[i]) & 0xff;if (val < 16)hexValue.append("0");hexValue.append(Integer.toHexString(val));}return hexValue.toString();}
}
package com.cloud.drore.eboos.common.util.security;/*** Created by wcy on 2016/8/25.*/
public class DES
{private int[] subkey1 = new int[16];private int[] subkey2 = new int[16];private static final boolean[] ks ={ // key shiftfalse, false, true, true, true, true, true, true, false, true, true, true, true, true, true, false };private static final int kp[][] ={{ // key permutation0x00000000, 0x00040000, 0x01000000, 0x01040000, 0x00000400, 0x00040400, 0x01000400, 0x01040400, 0x00200000, 0x00240000, 0x01200000, 0x01240000, 0x00200400, 0x00240400, 0x01200400,0x01240400, 0x00000001, 0x00040001, 0x01000001, 0x01040001, 0x00000401, 0x00040401, 0x01000401, 0x01040401, 0x00200001, 0x00240001, 0x01200001, 0x01240001, 0x00200401, 0x00240401,0x01200401, 0x01240401, 0x02000000, 0x02040000, 0x03000000, 0x03040000, 0x02000400, 0x02040400, 0x03000400, 0x03040400, 0x02200000, 0x02240000, 0x03200000, 0x03240000, 0x02200400,0x02240400, 0x03200400, 0x03240400, 0x02000001, 0x02040001, 0x03000001, 0x03040001, 0x02000401, 0x02040401, 0x03000401, 0x03040401, 0x02200001, 0x02240001, 0x03200001, 0x03240001,0x02200401, 0x02240401, 0x03200401, 0x03240401 },{ 0x00000000, 0x00000002, 0x00000800, 0x00000802, 0x08000000, 0x08000002, 0x08000800, 0x08000802, 0x00010000, 0x00010002, 0x00010800, 0x00010802, 0x08010000, 0x08010002, 0x08010800,0x08010802, 0x00000100, 0x00000102, 0x00000900, 0x00000902, 0x08000100, 0x08000102, 0x08000900, 0x08000902, 0x00010100, 0x00010102, 0x00010900, 0x00010902, 0x08010100, 0x08010102,0x08010900, 0x08010902, 0x00000010, 0x00000012, 0x00000810, 0x00000812, 0x08000010, 0x08000012, 0x08000810, 0x08000812, 0x00010010, 0x00010012, 0x00010810, 0x00010812, 0x08010010,0x08010012, 0x08010810, 0x08010812, 0x00000110, 0x00000112, 0x00000910, 0x00000912, 0x08000110, 0x08000112, 0x08000910, 0x08000912, 0x00010110, 0x00010112, 0x00010910, 0x00010912,0x08010110, 0x08010112, 0x08010910, 0x08010912 },{ 0x00000000, 0x00000004, 0x00001000, 0x00001004, 0x10000000, 0x10000004, 0x10001000, 0x10001004, 0x00000020, 0x00000024, 0x00001020, 0x00001024, 0x10000020, 0x10000024, 0x10001020,0x10001024, 0x00080000, 0x00080004, 0x00081000, 0x00081004, 0x10080000, 0x10080004, 0x10081000, 0x10081004, 0x00080020, 0x00080024, 0x00081020, 0x00081024, 0x10080020, 0x10080024,0x10081020, 0x10081024, 0x20000000, 0x20000004, 0x20001000, 0x20001004, 0x30000000, 0x30000004, 0x30001000, 0x30001004, 0x20000020, 0x20000024, 0x20001020, 0x20001024, 0x30000020,0x30000024, 0x30001020, 0x30001024, 0x20080000, 0x20080004, 0x20081000, 0x20081004, 0x30080000, 0x30080004, 0x30081000, 0x30081004, 0x20080020, 0x20080024, 0x20081020, 0x20081024,0x30080020, 0x30080024, 0x30081020, 0x30081024 },{ 0x00000000, 0x00100000, 0x00000008, 0x00100008, 0x00000200, 0x00100200, 0x00000208, 0x00100208, 0x04000000, 0x04100000, 0x04000008, 0x04100008, 0x04000200, 0x04100200, 0x04000208,0x04100208, 0x00002000, 0x00102000, 0x00002008, 0x00102008, 0x00002200, 0x00102200, 0x00002208, 0x00102208, 0x04002000, 0x04102000, 0x04002008, 0x04102008, 0x04002200, 0x04102200,0x04002208, 0x04102208, 0x00020000, 0x00120000, 0x00020008, 0x00120008, 0x00020200, 0x00120200, 0x00020208, 0x00120208, 0x04020000, 0x04120000, 0x04020008, 0x04120008, 0x04020200,0x04120200, 0x04020208, 0x04120208, 0x00022000, 0x00122000, 0x00022008, 0x00122008, 0x00022200, 0x00122200, 0x00022208, 0x00122208, 0x04022000, 0x04122000, 0x04022008, 0x04122008,0x04022200, 0x04122200, 0x04022208, 0x04122208 },{ 0x00000000, 0x00000200, 0x00020000, 0x00020200, 0x00000001, 0x00000201, 0x00020001, 0x00020201, 0x08000000, 0x08000200, 0x08020000, 0x08020200, 0x08000001, 0x08000201, 0x08020001,0x08020201, 0x00200000, 0x00200200, 0x00220000, 0x00220200, 0x00200001, 0x00200201, 0x00220001, 0x00220201, 0x08200000, 0x08200200, 0x08220000, 0x08220200, 0x08200001, 0x08200201,0x08220001, 0x08220201, 0x00000002, 0x00000202, 0x00020002, 0x00020202, 0x00000003, 0x00000203, 0x00020003, 0x00020203, 0x08000002, 0x08000202, 0x08020002, 0x08020202, 0x08000003,0x08000203, 0x08020003, 0x08020203, 0x00200002, 0x00200202, 0x00220002, 0x00220202, 0x00200003, 0x00200203, 0x00220003, 0x00220203, 0x08200002, 0x08200202, 0x08220002, 0x08220202,0x08200003, 0x08200203, 0x08220003, 0x08220203 },{ 0x00000000, 0x00000010, 0x20000000, 0x20000010, 0x00100000, 0x00100010, 0x20100000, 0x20100010, 0x00000800, 0x00000810, 0x20000800, 0x20000810, 0x00100800, 0x00100810, 0x20100800,0x20100810, 0x04000000, 0x04000010, 0x24000000, 0x24000010, 0x04100000, 0x04100010, 0x24100000, 0x24100010, 0x04000800, 0x04000810, 0x24000800, 0x24000810, 0x04100800, 0x04100810,0x24100800, 0x24100810, 0x00000004, 0x00000014, 0x20000004, 0x20000014, 0x00100004, 0x00100014, 0x20100004, 0x20100014, 0x00000804, 0x00000814, 0x20000804, 0x20000814, 0x00100804,0x00100814, 0x20100804, 0x20100814, 0x04000004, 0x04000014, 0x24000004, 0x24000014, 0x04100004, 0x04100014, 0x24100004, 0x24100014, 0x04000804, 0x04000814, 0x24000804, 0x24000814,0x04100804, 0x04100814, 0x24100804, 0x24100814 },{ 0x00000000, 0x00001000, 0x00010000, 0x00011000, 0x02000000, 0x02001000, 0x02010000, 0x02011000, 0x00000020, 0x00001020, 0x00010020, 0x00011020, 0x02000020, 0x02001020, 0x02010020,0x02011020, 0x00040000, 0x00041000, 0x00050000, 0x00051000, 0x02040000, 0x02041000, 0x02050000, 0x02051000, 0x00040020, 0x00041020, 0x00050020, 0x00051020, 0x02040020, 0x02041020,0x02050020, 0x02051020, 0x00002000, 0x00003000, 0x00012000, 0x00013000, 0x02002000, 0x02003000, 0x02012000, 0x02013000, 0x00002020, 0x00003020, 0x00012020, 0x00013020, 0x02002020,0x02003020, 0x02012020, 0x02013020, 0x00042000, 0x00043000, 0x00052000, 0x00053000, 0x02042000, 0x02043000, 0x02052000, 0x02053000, 0x00042020, 0x00043020, 0x00052020, 0x00053020,0x02042020, 0x02043020, 0x02052020, 0x02053020 },{ 0x00000000, 0x00000400, 0x01000000, 0x01000400, 0x00000100, 0x00000500, 0x01000100, 0x01000500, 0x10000000, 0x10000400, 0x11000000, 0x11000400, 0x10000100, 0x10000500, 0x11000100,0x11000500, 0x00080000, 0x00080400, 0x01080000, 0x01080400, 0x00080100, 0x00080500, 0x01080100, 0x01080500, 0x10080000, 0x10080400, 0x11080000, 0x11080400, 0x10080100, 0x10080500,0x11080100, 0x11080500, 0x00000008, 0x00000408, 0x01000008, 0x01000408, 0x00000108, 0x00000508, 0x01000108, 0x01000508, 0x10000008, 0x10000408, 0x11000008, 0x11000408, 0x10000108,0x10000508, 0x11000108, 0x11000508, 0x00080008, 0x00080408, 0x01080008, 0x01080408, 0x00080108, 0x00080508, 0x01080108, 0x01080508, 0x10080008, 0x10080408, 0x11080008, 0x11080408,0x10080108, 0x10080508, 0x11080108, 0x11080508 } };private static final int spbox[][] ={{ // s boxes and p box0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000,0x00000002, 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202,0x00008202, 0x00800000, 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200, 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200,0x00000002, 0x00800202, 0x00008202, 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200, 0x00000202, 0x00800200, 0x00800200, 0x00000000,0x00008002, 0x00008200, 0x00000000, 0x00808002 },{ 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010,0x40080010, 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000,0x40080000, 0x00004010, 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000, 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010,0x00000010, 0x00004000, 0x40000000, 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010, 0x00084000, 0x00000000, 0x40004000, 0x00004010,0x40000000, 0x40080010, 0x40084010, 0x00084000 },{ 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000,0x00000104, 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104,0x00000100, 0x04000000, 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000, 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004,0x00000100, 0x00000000, 0x04010004, 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004, 0x04010000, 0x04000104, 0x00000104, 0x04010000,0x00010104, 0x00000004, 0x04010004, 0x00010100 },{ 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040,0x80400000, 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040,0x80401040, 0x80000040, 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000, 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000,0x80001040, 0x80001040, 0x00000040, 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040, 0x80001000, 0x00001040, 0x00400000, 0x80401000,0x00000040, 0x00400000, 0x00001000, 0x00401040 },{ 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080,0x20000000, 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000,0x21000000, 0x00040080, 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080, 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080,0x00000080, 0x01000000, 0x21040000, 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000, 0x00040080, 0x01000080, 0x20000080, 0x00040000,0x00000000, 0x20040000, 0x01040080, 0x20000080 },{ 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000,0x00002008, 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000,0x10202000, 0x10000000, 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008, 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008,0x10202008, 0x00202000, 0x10200000, 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008, 0x00002000, 0x00200008, 0x10002008, 0x00000000,0x10202000, 0x10000000, 0x00200008, 0x10002008 },{ 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001,0x00000401, 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001,0x02000000, 0x00100400, 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001, 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400,0x00000401, 0x00100401, 0x02100400, 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401, 0x00000000, 0x00100401, 0x02100000, 0x00000400,0x02000001, 0x02000400, 0x00000400, 0x00100001 },{ 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800,0x00000020, 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800,0x00020820, 0x00020000, 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820, 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020,0x08000000, 0x00020000, 0x08000820, 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000, 0x08020820, 0x00020800, 0x00020800, 0x00000820,0x00000820, 0x00020020, 0x08000000, 0x08020800 } };/*** * 按照key进行初始化本算法*/public DES(long key){setKey(key);}/*** * 将一个8字节数组转变成一个长整形。*/public long bytes2long(byte[] rd){long dd = 0;for (int i = 0; i <= 7; i++)dd = (dd << 8) | ((long) rd[i] & 0xff);return dd;}/*** 解密* * @param long d 密文* @return long 明文*/public long decrypt(long d){d = ip(d);int l = (int) (d >>> 32);int r = (int) d;for (int i = 15; i >= 0; i--){int t = l;l = r;r = t;int t1 = ((r >>> 3) | (r << 29)) ^ subkey1[i];int t2 = ((r << 1) | (r >>> 31)) ^ subkey2[i];l ^= spbox[0][(t1 >>> 24) & 0x3f] | spbox[1][(t2 >>> 24) & 0x3f] | spbox[2][(t1 >>> 16) & 0x3f] | spbox[3][(t2 >>> 16) & 0x3f] | spbox[4][(t1 >>> 8) & 0x3f] | spbox[5][(t2 >>> 8) & 0x3f]| spbox[6][(t1) & 0x3f] | spbox[7][(t2) & 0x3f];}d = ((long) l << 32) | ((long) r & 0xffffffffL);return rip(d);}/*** 加密* * @param long d 明文* @return long 密文*/public long encrypt(long d){d = ip(d);int l = (int) (d >>> 32);int r = (int) d;for (int i = 0; i <= 15; i++){int t1 = ((r >>> 3) | (r << 29)) ^ subkey1[i];int t2 = ((r << 1) | (r >>> 31)) ^ subkey2[i];l ^= spbox[0][(t1 >>> 24) & 0x3f] | spbox[1][(t2 >>> 24) & 0x3f] | spbox[2][(t1 >>> 16) & 0x3f] | spbox[3][(t2 >>> 16) & 0x3f] | spbox[4][(t1 >>> 8) & 0x3f] | spbox[5][(t2 >>> 8) & 0x3f]| spbox[6][(t1) & 0x3f] | spbox[7][(t2) & 0x3f];int t = l;l = r;r = t;}d = ((long) l << 32) | ((long) r & 0xffffffffL);return rip(d);}/*** initial permutation*/private long ip(long d){long t;t = ((d << 36) ^ d) & 0xf0f0f0f000000000L;d ^= (t >>> 36) | t;t = ((d << 48) ^ d) & 0xffff000000000000L;d ^= (t >>> 48) | t;t = ((d << 30) ^ d) & 0x3333333300000000L;d ^= (t >>> 30) | t;t = ((d << 24) ^ d) & 0x00ff00ff00000000L;d ^= (t >>> 24) | t;t = ((d << 33) ^ d) & 0xaaaaaaaa00000000L;d ^= (t >>> 33) | t;return d;}/*** * 将long sd变成一个数组*/public void long2bytes(long sd, byte[] dd){for (int i = 7; i >= 0; i--){dd[i] = (byte) sd;sd >>>= 8;}}/*** reverse initial permutation*/private long rip(long d){long t;t = ((d << 33) ^ d) & 0xaaaaaaaa00000000L;d ^= (t >>> 33) | t;t = ((d << 24) ^ d) & 0x00ff00ff00000000L;d ^= (t >>> 24) | t;t = ((d << 30) ^ d) & 0x3333333300000000L;d ^= (t >>> 30) | t;t = ((d << 48) ^ d) & 0xffff000000000000L;d ^= (t >>> 48) | t;t = ((d << 36) ^ d) & 0xf0f0f0f000000000L;d ^= (t >>> 36) | t;return d;}/*** 设置密钥*/public void setKey(long key){long t;t = ((key << 36) ^ key) & 0xf0f0f0f000000000L;key ^= (t >>> 36) | t;t = ((key << 18) ^ key) & 0xcccc0000cccc0000L;key ^= t | (t >>> 18);t = ((key << 9) ^ key) & 0xaa00aa00aa00aa00L;key ^= t | (t >>> 9);int d = (int) ((key >>> 28) & 0x0ffffff0 | (key >>> 24) & 0x0000000f);int c = (int) ((key << 20) & 0x0ff00000 | (key << 4) & 0x000ff000 | (key >>> 12) & 0x00000ff0 | (key >>> 28) & 0x0000000f);for (int i = 0; i < 16; i++){if (ks[i]){c = ((c << 2) | (c >>> 26)) & 0x0fffffff;d = ((d << 2) | (d >>> 26)) & 0x0fffffff;} else{c = ((c << 1) | (c >>> 27)) & 0x0fffffff;d = ((d << 1) | (d >>> 27)) & 0x0fffffff;}int t1 = kp[0][(c >>> 22) & 0x3f] | kp[1][(c >>> 16) & 0x30 | (c >>> 15) & 0x0f] | kp[2][(c >>> 9) & 0x3c | (c >>> 8) & 0x03] | kp[3][(c >>> 3) & 0x20 | (c >>> 1) & 0x18 | c & 0x07];int t2 = kp[4][(c >>> 22) & 0x3f] | kp[5][(c >>> 15) & 0x30 | (c >>> 14) & 0x0f] | kp[6][(c >>> 7) & 0x3f] | kp[7][(c >>> 1) & 0x3c | c & 0x03];subkey1[i] = (t1 & 0xff000000) | ((t1 & 0x0000ff00) << 8) | ((t2 & 0xff000000) >>> 16) | ((t2 & 0x0000ff00) >>> 8);subkey2[i] = ((t1 & 0x00ff0000) << 8) | ((t1 & 0x000000ff) << 16) | ((t2 & 0x00ff0000) >>> 8) | (t2 & 0x000000ff);}}
}
package com.cloud.drore.eboos.common.util.security;import java.text.SimpleDateFormat;
import java.util.Date;/*** Created by wcy on 2016/8/25.*/
public class Encode
{/** 密钥 */private static long key = 1231234234l;/*** 解密 第二个参数: 和登录注册相关的:传入"true" 需要解密,比如字符串传递的,传入 nul* * @param s* @return*/public static String decode(String s, String isLogin){String res = "";DES des = new DES(getKey());byte[] sBytes = s.getBytes();for (int i = 0; i < (sBytes.length / 16); i++){byte[] theBytes = new byte[8];for (int j = 0; j <= 7; j++){byte byte1 = (byte) (sBytes[16 * i + 2 * j] - 'a');byte byte2 = (byte) (sBytes[16 * i + 2 * j + 1] - 'a');theBytes[j] = (byte) (byte1 * 16 + byte2);}long x = des.bytes2long(theBytes);byte[] result = new byte[8];des.long2bytes(des.decrypt(x), result);res = res + (new String(result));}if (isLogin != null && isLogin.equals("true")){return Codec.encodeMd5(res.trim());}return res.trim();}/*** 加密 第二个参数:和登录注册相关的:传入"true" 需要解密,比如字符串传递的,传入 nul* * @param s* @return*/public static String encode(String s, String isLogin){String res = "";DES des = new DES(getKey());byte space = 0x20;byte[] sBytes = s.getBytes();int length = sBytes.length;int newLength = length + (8 - length % 8) % 8;byte[] newBytes = new byte[newLength];for (int i = 0; i < newLength; i++){if (i <= length - 1){newBytes[i] = sBytes[i];} else{newBytes[i] = space;}}for (int i = 0; i < (newLength / 8); i++){byte[] theBytes = new byte[8];for (int j = 0; j <= 7; j++){theBytes[j] = newBytes[8 * i + j];}long x = des.bytes2long(theBytes);byte[] result = new byte[8];des.long2bytes(des.encrypt(x), result);byte[] doubleResult = new byte[16];for (int j = 0; j < 8; j++){doubleResult[2 * j] = (byte) (((((char) result[j]) & 0xF0) >> 4) + 'a');doubleResult[2 * j + 1] = (byte) ((((char) result[j]) & 0x0F) + 'a');}res = res + new String(doubleResult);}if (isLogin != null && isLogin.equals("true")){return Codec.encodeMd5(res.trim());}return res;}/*** 获取Key* * @return long*/private static long getKey(){return key;}/*** 设置Key* * @return long*/public static void setKey(long enKey){key = enKey;}public static void main(String[] args){/** key */Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String datestr = sdf.format(date);System.out.println(Encode.encode("103261000000176F0B40," + datestr, null) + "    08");System.out.println(Encode.encode("1032810000022704A4B2," + datestr, null) + "   02");System.out.println(Encode.encode("a111111", null));System.out.println(Encode.encode("74e7d93ca4c6fda14baf667b85c28e29", null));System.out.println(Encode.decode("74e7d93ca4c6fda14baf667b85c28e29", "true"));System.out.println(Encode.encode("pnliiidgkneicjmb", null));System.out.println(Encode.encode("jfjerkaskafsf&,&111111", null));System.out.println(Codec.encodeMd5("123456"));}}

7.注意:使用场景必须在redis的环境中,是利用redis分布式锁进行二次拦截的

410508961@qq.com

后台利用aop注解的方式防止重复提交相关推荐

  1. 学习Java 采取令牌的方式避免重复提交

    重复提交原因 从提交页面到成功页面的跳转一般采用视图定位,由于视图定位是在服务端跳转的,如果用户在点击提交之后再次刷新页面,会导致重复提交,数据库的数据会有重复. 采用令牌措施 1.在转账展示页面生成 ...

  2. 利用redis实现分布式请求防重复提交

    2019独角兽企业重金招聘Python工程师标准>>> 1.自定义注解类Token @Target(ElementType.METHOD) @Retention(RetentionP ...

  3. ssm+redis 如何更简洁的利用自定义注解+AOP实现redis缓存

    基于 ssm + maven + redis 使用自定义注解 利用aop基于AspectJ方式 实现redis缓存 如何能更简洁的利用aop实现redis缓存,话不多说,上demo 需求: 数据查询时 ...

  4. SpringBoot自定义注解+AOP+redis实现防接口幂等性重复提交,从概念到实战

    一.前言 在面试中,经常会有一道经典面试题,那就是:怎么防止接口重复提交? 小编也是背过的,好几种方式,但是一直没有实战过,做多了管理系统,发现这个事情真的没有过多的重视. 最近在测试过程中,发现了多 ...

  5. Spring MVC拦截器+注解方式实现防止表单重复提交

    原理:在新建页面中Session保存token随机码,当保存时验证,通过后删除,当再次点击保存时由于服务器端的Session中已经不存在了,所有无法验证通过. 1.新建注解: /*** <p&g ...

  6. java spring aop 注解包_Spring AOP 注解配置实例

    Spring AOP注解例子 一:导入相关jar包. 首先导入Spring的相关包(这里就不多说了,我这里是3.2.4版本的) 然后导入AOP注解的相关包(不是spring的包)aspectjrt-1 ...

  7. 分布式锁防止订单重复提交_防止表单重复提交看这里!!!

    要解决重复提交这事,先要知道什么是重复提交 假如用户的网速慢,用户点击提交按钮,却因为网速慢,而没有跳转到新的页面,这时的用户会再次点击提交按钮,举个例子:用户点击订单页面,当点击提交按钮的时候,也许 ...

  8. 【精品】防止表单重复提交 方法汇总

    背景 表单重复提交会造成数据重复,增加服务器负载,严重甚至会造成服务器宕机等情况,有效防止表单重复提交有一定的必要性. 常见的防止表单重复提交解决方案有以下几种: 一.通过一个标识来控制表单提交之后, ...

  9. php防止订单重复计算,php防止用户重复提交表单

    我们提交表单的时候,不能忽视的一个限制是防止用户重复提交表单,因为有可能用户连续点击了提交按钮或者是攻击者恶意提交数据,那么我们在提交数据后的处理如修改或添加数据到数据库时就会惹上麻烦. 效果图: 那 ...

最新文章

  1. linux中的gun含义,linux中gun的含义
  2. NYOJ 467 中缀式变后缀式
  3. 第一周周日DailyReporting——PM(李忠)
  4. 函数setState是React的未来
  5. java求n个分数之和_N个快速提升分数的学习方法
  6. 如何在Mac上使用Memoji贴纸、屏幕效果、应用程序和Messages
  7. uCGUI 按键窗口切换机制(更新篇)
  8. NoSuchMethodError: No virtual method centerCrop()/glide
  9. C语言实现入门级小游戏——扫雷(排行榜+玩家自定义难度+递归展开一片+标记地雷)版本
  10. jdk15的安装与配置
  11. Sass 入门(基础知识点汇总)
  12. python猜拳游戏编程代码_Python实现猜拳小游戏
  13. 保姆级教学——Python+Pygame怎么实现吃豆豆游戏
  14. face_recognition人脸识别模块的使用教程
  15. 「杂谈」程序猿必备的1700个英语单词
  16. pci 数据捕获和信号处理控制器_大学毕业设计一席谈之十五 扩频信号的捕获 (1)...
  17. 字符串匹配算法(Sunday算法)
  18. 程序员是不是人均黑客?
  19. 今日头条移动APP 广告激活数据API对接实践
  20. vscode让html文件保存自动刷新浏览器

热门文章

  1. 学习yum info命令
  2. 北斗网络同步时钟与GPS卫星时钟同步设备的区别
  3. (转载)验证下载下来的文件的完整性的方法
  4. 第一章:计算机硬件知识
  5. Flutter之微信支付实战模板
  6. 怎样用ps做出3D分割效果海报图
  7. 【项目】多种方式统一登录入口的设计方案
  8. servu用户信息如何导出_用户如何增强信息安全防护意识
  9. 【UE4基础】UE4 垃圾回收
  10. 用html画布做扇形,html5 canvas元素扇形的绘制