Merge branch 'test/stable' into release/3.0

# Conflicts:
#	src/main/java/com/ai/da/service/impl/AccountServiceImpl.java
This commit is contained in:
2024-05-28 10:59:34 +08:00
86 changed files with 1874 additions and 363 deletions

View File

@@ -154,63 +154,63 @@ public class GenerateConsumer {
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer1(Message msg, Channel channel) {
generate(msg, channel, "consumer 1");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer2(Message msg, Channel channel) {
generate(msg, channel, "consumer 2");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer3(Message msg, Channel channel) {
generate(msg, channel, "consumer 3");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer4(Message msg, Channel channel) {
generate(msg, channel, "consumer 4");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer5(Message msg, Channel channel) {
generate(msg, channel, "consumer 5");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer6(Message msg, Channel channel) {
generate(msg, channel, "consumer 6");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer7(Message msg, Channel channel) {
generate(msg, channel, "consumer 7");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer8(Message msg, Channel channel) {
generate(msg, channel, "consumer 8");
}
@RabbitListener(queues = MQConfig.GENERATE_QUEUE)
@RabbitHandler
public void generateConsumer9(Message msg, Channel channel) {
generate(msg, channel, "consumer 9");
}
@RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE)
@RabbitHandler
public void getGenerateResult(Message msg, Channel channel) {
processGenerateResult(msg, channel);
}
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer1(Message msg, Channel channel) {
// generate(msg, channel, "consumer 1");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer2(Message msg, Channel channel) {
// generate(msg, channel, "consumer 2");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer3(Message msg, Channel channel) {
// generate(msg, channel, "consumer 3");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer4(Message msg, Channel channel) {
// generate(msg, channel, "consumer 4");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer5(Message msg, Channel channel) {
// generate(msg, channel, "consumer 5");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer6(Message msg, Channel channel) {
// generate(msg, channel, "consumer 6");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer7(Message msg, Channel channel) {
// generate(msg, channel, "consumer 7");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer8(Message msg, Channel channel) {
// generate(msg, channel, "consumer 8");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler
// public void generateConsumer9(Message msg, Channel channel) {
// generate(msg, channel, "consumer 9");
// }
//
// @RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE)
// @RabbitHandler
// public void getGenerateResult(Message msg, Channel channel) {
// processGenerateResult(msg, channel);
// }
}

View File

@@ -12,16 +12,16 @@ public class MQConfig {
// public static final String GENERATE_QUEUE = "generate-queue-test";
// ==================================================================
// public static final String GENERATE_QUEUE = "generate-queue-local";
public static final String GENERATE_QUEUE = "generate-queue-prod";
public static final String GENERATE_QUEUE = "generate-queue-dev";
// public static final String SR_QUEUE = "SR-queue-local";
public static final String SR_QUEUE = "SR-queue-prod";
public static final String SR_QUEUE = "SR-queue-dev";
// public static final String SR_RESULT_QUEUE = "SuperResolution-local";
public static final String SR_RESULT_QUEUE = "SuperResolution-prod";
public static final String SR_RESULT_QUEUE = "SuperResolution-dev";
// public static final String GENERATE_RESULT_QUEUE = "GenerateImage-local";
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-prod";
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-dev";
public MQConfig() {
}

View File

@@ -218,17 +218,17 @@ public class SRConsumer {
taskListService.updateTaskStatusOrOutputRedis(uniqueId, "fail", null);
}
@RabbitListener(queues = MQConfig.SR_QUEUE)
@RabbitHandler
public void SRConsumer1(Message msg, Channel channel) {
superResolution(msg, channel, "consumer 1");
}
@RabbitListener(queues = MQConfig.SR_RESULT_QUEUE)
@RabbitHandler
public void SRResultConsumer1(Message msg, Channel channel) {
getSRResult(msg, channel, "consumer 1");
}
// @RabbitListener(queues = MQConfig.SR_QUEUE)
// @RabbitHandler
// public void SRConsumer1(Message msg, Channel channel) {
// superResolution(msg, channel, "consumer 1");
// }
//
//
// @RabbitListener(queues = MQConfig.SR_RESULT_QUEUE)
// @RabbitHandler
// public void SRResultConsumer1(Message msg, Channel channel) {
// getSRResult(msg, channel, "consumer 1");
// }
}

View File

@@ -34,7 +34,7 @@ public class MyTaskScheduler {
// 定时任务,每十五天执行一次
// @Scheduled(cron = "0 0 0 ? * MON")
@Scheduled(cron = "0 0 0 */15 * ?")
// @Scheduled(cron = "0 0 0 */15 * ?")
public void checkExpiry() {
// 检测正式用户是否快要过期
QueryWrapper<Account> qw = new QueryWrapper<>();
@@ -68,7 +68,7 @@ public class MyTaskScheduler {
}
}
}
@Scheduled(cron = "0 0 8 * * ?")
// @Scheduled(cron = "0 0 8 * * ?")
public void sendTrialOrderExcelToManagements() {
// 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1);

View File

@@ -0,0 +1,20 @@
package com.ai.da.common.constant;
public class AlipayHKConstant {
// 服务名
public static final String CREATE_ORDER = "create_order";
public static final String ORDER_DETAILS = "order_details";
public static final String TRANSACTION_DETAILS = "transaction_details";
public static final String GET_FILE = "get_file";
public static final String CREATE_AUTO_DEBIT = "create_auto_debit";
public static final String REFRESH_TRANSACTION_STATUS = "refresh_transaction_status";
public static final String REFUND_TRANSACTION = "refund_transaction";
// 订单状态
public static final String STATUS_NEW = "new";
public static final String STATUS_WAIT = "wait";
public static final String STATUS_PAID = "paid";
public static final String STATUS_EXPIRED = "expired";
public static final String STATUS_LIQUIDATED = "liquidated";
}

View File

@@ -27,7 +27,8 @@ public enum LibraryLevel1TypeEnum {
/**
* 模特
*/
MODELS("Models");
MODELS("Models"),
DESIGN_ELEMENTS("DesignElements");
private String realName;

View File

@@ -19,7 +19,12 @@ public enum PayTypeEnum {
/**
* PayPal
*/
PAYPAL("PayPal");
PAYPAL("PayPal"),
/**
* 香港支付宝
*/
ALIPAY_HK("Alipay-HK");
/**
* 类型

View File

@@ -49,7 +49,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
"/api/third/party/addNoLoginRequiredNew","/api/third/party/deleteNoLoginRequiredNew",
"/api/third/party/existNoLoginRequired","/api/third/party/getRedirectUrl",
// "/api/python/chatStream",
"/api/python/flush","/api/account/healthy","/api/ali-pay/trade/notify","/api/paypal/ipn/back"
"/api/python/flush","/api/account/healthy","/api/ali-pay/trade/notify","/api/paypal/ipn/back","/api/alipay-hk/trade/notify"
);
@Override

View File

@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
@Slf4j
public class GenerateTask {
@Scheduled(cron = "0 0 */1 * * ?")
// @Scheduled(cron = "0 0 */1 * * ?")
public void generateScheduled(){
log.info("测试定时器generate");

View File

@@ -23,7 +23,7 @@ public class PaypalTask {
@Resource
private PayPalCheckoutService payPalCheckoutService;
@Scheduled(cron = "0/30 * * * * ?")
// @Scheduled(cron = "0/30 * * * * ?")
public void orderConfirm() throws SerializeException {
log.info("PayPal orderConfirm 被执行......");

View File

@@ -6,9 +6,16 @@ import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.signers.RSADigestSigner;
import org.bouncycastle.crypto.util.PublicKeyFactory;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
@@ -25,22 +32,24 @@ import java.util.HashMap;
import java.util.UUID;
@Slf4j
@Component
public class AlipayHKEncryptionUtil {
@Value("${alipay.hk.merchant-id}")
private static String merchantId;
@Value("${alipayHK.merchantId}")
private String merchantId;
@Value("${alipay.hk.segment-id}")
private static String segmentId;
@Value("${alipayHK.segmentId}")
private String segmentId;
@Value("${alipay.hk.AESKey}")
private static String aesKey;
@Value("${alipayHK.AESKey}")
private String aesKey;
@Value("${alipay.hk.rsaPrivateKey}")
private static String privateKeyPath;
@Value("${alipayHK.rsaPrivateKey}")
private String privateKeyPath;
@Value("${alipayHK.rsaPublicKey}")
private String publicKeyPath;
@Value("${alipay.hk.rsaPublicKey}")
private static String publicKeyPath;
/**
* 加密
@@ -55,7 +64,7 @@ public class AlipayHKEncryptionUtil {
* @throws BadPaddingException
* @throws IOException
*/
public static AlipayHKRequestDTO AESCBCWithRSA(HashMap<String, Object> param, String serviceName) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException {
public AlipayHKRequestDTO AESCBCWithRSA(HashMap<String, Object> param, String serviceName) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException {
// Pre-shared secret key, DO NOT hardcode this key
String key = aesKey;
// The path to the rsa private key file, DO NOT save this key to a publicly accessible location
@@ -187,7 +196,7 @@ public class AlipayHKEncryptionUtil {
/**
* 使用 AES 密钥和随机向量进行解密
*/
public static String decryptAES(String encryptedText, String iv) throws Exception {
public String decryptAES(String encryptedText, String iv) throws Exception {
byte[] encryptedBytes = Base64.getDecoder().decode(encryptedText);
byte[] ivBytes = Base64.getDecoder().decode(iv);
@@ -201,7 +210,7 @@ public class AlipayHKEncryptionUtil {
return new String(decryptedBytes, StandardCharsets.UTF_8);
}
public static void test() throws Exception {
public void test() throws Exception {
// 加密数据
AlipayHKParametersDTO requestMessage = new AlipayHKParametersDTO();
requestMessage.setService("create_order");
@@ -326,4 +335,29 @@ public class AlipayHKEncryptionUtil {
random.nextBytes(iv);
return iv;
}
public Boolean signatureVerification(String data, String signatureBase64){
Base64.Decoder decoder = Base64.getDecoder();
// Verify key
try {
// PublicKey publicKey = readPublicKey(new File(publicKeyPath));
InputStreamReader isrPub = new InputStreamReader(new FileInputStream(publicKeyPath));
PEMParser pemParserPub = new PEMParser(isrPub);
SubjectPublicKeyInfo pubInfo = (SubjectPublicKeyInfo) pemParserPub.readObject();
AsymmetricKeyParameter pubKey = PublicKeyFactory.createKey(pubInfo);
// Verifying
RSADigestSigner verifier = new RSADigestSigner(new SHA256Digest());
verifier.init(false, pubKey);
byte[] signMessageForVerifing = data.getBytes();
byte[] signatureBase64ForVerifing = decoder.decode(signatureBase64);
verifier.update(signMessageForVerifing, 0, signMessageForVerifing.length);
Boolean verifyResult = verifier.verifySignature(signatureBase64ForVerifing);
return verifyResult;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -11,11 +11,13 @@ import java.time.Instant;
import java.util.concurrent.TimeUnit;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class AlipayHKRequestUtil {
public static String createOrder(AlipayHKRequestDTO alipayHKRequestDTO) throws IOException {
public String createOrder(AlipayHKRequestDTO alipayHKRequestDTO) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
@@ -32,22 +34,29 @@ public class AlipayHKRequestUtil {
RequestBody body = RequestBody.create(mediaType, jsonString);
Request request = new Request.Builder()
// .url("https://aqs-api.sandbox-codpayment.com")
.url("https://aqs-api.sandbox-codpayment.com/v1/service")
// .url("https://aqs-api.sandbox-codpayment.com/v1/service")
.url("https://aqs-api.codpayment.com/v1/service")
.method("POST", body)
.addHeader("Content-Type", "application/json;charset=utf-8")
.build();
Response response = null;
Response response;
String bodyString;
try {
// log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(alipayHKRequestDTO, SerializerFeature.WriteMapNullValue));
response = client.newCall(request).execute();
assert response.body() != null;
bodyString = response.body().string();
} catch (Exception e) {
// log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
// throw new BusinessException("generate.interface.error");
throw new BusinessException(e.getMessage());
}
return response.body().string();
JSONObject jsonObject = JSONObject.parseObject(bodyString);
boolean success = (boolean) jsonObject.get("success");
if (success){
return bodyString;
} else {
String message = jsonObject.get("error_code").toString() + ":" + jsonObject.get("error");
log.error("Alipay return message : {}", message);
throw new BusinessException("Alipay return message : " + message);
}
}
}

View File

@@ -16,6 +16,7 @@ import java.io.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -126,6 +127,26 @@ public class MinioUtil {
return names;
}
public String uploadImageFromBase64(String bucketName, String base64Image, String imageType) {
byte[] imageBytes = Base64.getDecoder().decode(base64Image);
String fileName = UUID.randomUUID().toString() + "." + imageType; // or any other image format
try (InputStream in = new ByteArrayInputStream(imageBytes)) {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(in, in.available(), -1)
.contentType("image/png") // Set the content type according to your image format
.build()
);
return bucketName + "/" + fileName;
} catch (Exception e) {
e.printStackTrace();
return null; // or throw an exception
}
}
/**
* description: 上传文件
*
@@ -415,6 +436,13 @@ public class MinioUtil {
return false;
}
}
public String base64Upload(String base64, String bucketName){
String[] parts = base64.split(",");
String imageType = parts[0].split("/")[1].split(";")[0];
String base64Data = parts[1];
return uploadImageFromBase64(bucketName, base64Data, imageType);
}
}

View File

@@ -362,7 +362,10 @@ public class SendEmailUtil {
}
private final static Long UPGRADE_NOTIFICATION_ID = 118855L;
public static void sendUpgradeNotification(Account account, String senderAddress) {
private final static Long UPGRADE_SUCCESS_NOTIFICATION_ID = 118856L;
private final static Long UPGRADE_NOTIFICATION_ID_CHINESE = 122898L;
private final static Long UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE = 122899L;
public static void sendUpgradeNotification(Account account, String senderAddress, Integer type) {
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
@@ -381,8 +384,20 @@ public class SendEmailUtil {
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
subject = "Upcoming AiDA 3.0 Launch and Scheduled Maintenance";
template.setTemplateID(UPGRADE_NOTIFICATION_ID);
// if (type == 1) {
// subject = "Upcoming System Upgrade for AiDA 3.0";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID);
// }else {
// subject = "即将到来的AiDA 3.0系统升级";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
// }
if (type == 1) {
subject = "Successful System Upgrade and New Features in AiDA 3.0";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
}else {
subject = "系统升级成功和AiDA 3.0新功能";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
}
template.setTemplateData(buildAccountData(account));
req.setSubject(subject);