9 changed files with 281 additions and 7 deletions
-
100src/main/java/com/example/demo/Util/BaseDES3.java
-
10src/main/java/com/example/demo/controller/Temporary/RedController.java
-
28src/main/java/com/example/demo/domain/vo/RedList.java
-
2src/main/java/com/example/demo/domain/vo/coin/ConsumeUser.java
-
6src/main/java/com/example/demo/service/Temporary/RedService.java
-
138src/main/java/com/example/demo/serviceImpl/Temporary/RedServiceImpl.java
-
2src/main/java/com/example/demo/serviceImpl/coin/ConsumeServiceImpl.java
-
1src/main/resources/application-prod.yml
-
1src/main/resources/application-test.yml
@ -0,0 +1,100 @@ |
|||||
|
package com.example.demo.Util; |
||||
|
|
||||
|
|
||||
|
import javax.crypto.Cipher; |
||||
|
import java.security.Key; |
||||
|
|
||||
|
|
||||
|
public class BaseDES3 { |
||||
|
private static String strDefaultKey = "98hltleg"; |
||||
|
|
||||
|
private Cipher encryptCipher = null; |
||||
|
|
||||
|
private Cipher decryptCipher = null; |
||||
|
|
||||
|
public static String byteArr2HexStr(byte[] arrB) throws Exception { |
||||
|
int iLen = arrB.length; |
||||
|
|
||||
|
StringBuffer sb = new StringBuffer(iLen * 2); |
||||
|
for (int i = 0; i < iLen; i++) { |
||||
|
int intTmp = arrB[i]; |
||||
|
|
||||
|
while (intTmp < 0) { |
||||
|
intTmp = intTmp + 256; |
||||
|
} |
||||
|
|
||||
|
if (intTmp < 16) { |
||||
|
sb.append("0"); |
||||
|
} |
||||
|
sb.append(Integer.toString(intTmp, 16)); |
||||
|
} |
||||
|
return sb.toString(); |
||||
|
} |
||||
|
|
||||
|
public static byte[] hexStr2ByteArr(String strIn) { |
||||
|
byte[] arrB = strIn.getBytes(); |
||||
|
int iLen = arrB.length; |
||||
|
|
||||
|
byte[] arrOut = new byte[iLen / 2]; |
||||
|
for (int i = 0; i < iLen; i = i + 2) { |
||||
|
String strTmp = new String(arrB, i, 2); |
||||
|
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); |
||||
|
} |
||||
|
return arrOut; |
||||
|
} |
||||
|
|
||||
|
public BaseDES3() throws Exception { |
||||
|
this(strDefaultKey); |
||||
|
} |
||||
|
|
||||
|
public BaseDES3(String strKey) throws Exception { |
||||
|
|
||||
|
Key key = getKey(strKey.getBytes()); |
||||
|
|
||||
|
encryptCipher = Cipher.getInstance("DES"); |
||||
|
encryptCipher.init(Cipher.ENCRYPT_MODE, key); |
||||
|
|
||||
|
decryptCipher = Cipher.getInstance("DES"); |
||||
|
decryptCipher.init(Cipher.DECRYPT_MODE, key); |
||||
|
} |
||||
|
|
||||
|
public byte[] encrypt(byte[] arrB) throws Exception { |
||||
|
return encryptCipher.doFinal(arrB); |
||||
|
} |
||||
|
|
||||
|
public String encrypt(String strIn) throws Exception { |
||||
|
return byteArr2HexStr(encrypt(strIn.getBytes())); |
||||
|
} |
||||
|
|
||||
|
public byte[] decrypt(byte[] arrB) throws Exception { |
||||
|
return decryptCipher.doFinal(arrB); |
||||
|
} |
||||
|
|
||||
|
public String decrypt(String strIn) throws Exception { |
||||
|
return new String(decrypt(hexStr2ByteArr(strIn))); |
||||
|
} |
||||
|
|
||||
|
private Key getKey(byte[] arrBTmp) { |
||||
|
|
||||
|
byte[] arrB = new byte[8]; |
||||
|
|
||||
|
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) { |
||||
|
arrB[i] = arrBTmp[i]; |
||||
|
} |
||||
|
|
||||
|
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES"); |
||||
|
|
||||
|
return key; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static void main(String args[]) { |
||||
|
try { |
||||
|
BaseDES3 d = new BaseDES3(); |
||||
|
String encryptedText = d.encrypt("90035176"); |
||||
|
System.out.println("加密结果:" + encryptedText); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
package com.example.demo.domain.vo; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @program: GOLD |
||||
|
* @ClassName RedList |
||||
|
* @description: |
||||
|
* @author: huangqizhen |
||||
|
* @create: 2025−12-17 14:59 |
||||
|
* @Version 1.0 |
||||
|
**/ |
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class RedList { |
||||
|
private Integer id; |
||||
|
private String title; |
||||
|
private BigDecimal discount; |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
||||
|
private Date end_time; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue