!35 解决存在的npe

Merge pull request !35 from 丁新东/master
pull/26/head
Java3y 2 years ago committed by Gitee
commit ab7e97dcb8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -6,9 +6,9 @@ import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayOpenAppMiniTemplatemessageSendModel;
import com.alipay.api.request.AlipayOpenAppMiniTemplatemessageSendRequest;
import com.java3y.austin.common.constant.SendAccountConstant;
import com.java3y.austin.common.dto.account.AlipayMiniProgramAccount;
import com.java3y.austin.handler.alipay.AlipayMiniProgramAccountService;
import com.java3y.austin.handler.config.AlipayClientSingleton;
import com.java3y.austin.handler.domain.alipay.AlipayMiniProgramParam;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j;
@ -40,9 +40,9 @@ public class AlipayMiniProgramAccountServiceImpl implements AlipayMiniProgramAcc
public void send(AlipayMiniProgramParam miniProgramParam) throws AlipayApiException {
AlipayMiniProgramAccount miniProgramAccount = accountUtils.getAccountById(miniProgramParam.getSendAccount(), AlipayMiniProgramAccount.class);
AlipayClient client = initService(miniProgramAccount);
AlipayClient client = AlipayClientSingleton.getSingleton(miniProgramAccount);
List<AlipayOpenAppMiniTemplatemessageSendRequest> request = assembleReq(miniProgramParam, miniProgramAccount);
for(AlipayOpenAppMiniTemplatemessageSendRequest req : request){
for (AlipayOpenAppMiniTemplatemessageSendRequest req : request) {
client.execute(req);
}
}
@ -67,20 +67,20 @@ public class AlipayMiniProgramAccountServiceImpl implements AlipayMiniProgramAcc
return requestList;
}
/**
*
*/
private AlipayClient initService(AlipayMiniProgramAccount alipayMiniProgramAccount) throws AlipayApiException {
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
alipayConfig.setAppId(alipayMiniProgramAccount.getAppId());
alipayConfig.setPrivateKey(alipayMiniProgramAccount.getPrivateKey());
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(alipayMiniProgramAccount.getAlipayPublicKey());
alipayConfig.setCharset("utf-8");
alipayConfig.setSignType("RSA2");
return new DefaultAlipayClient(alipayConfig);
}
// /**
// * 初始化支付宝小程序
// */
// private AlipayClient initService(AlipayMiniProgramAccount alipayMiniProgramAccount) throws AlipayApiException {
// AlipayConfig alipayConfig = new AlipayConfig();
// alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
// alipayConfig.setAppId(alipayMiniProgramAccount.getAppId());
// alipayConfig.setPrivateKey(alipayMiniProgramAccount.getPrivateKey());
// alipayConfig.setFormat("json");
// alipayConfig.setAlipayPublicKey(alipayMiniProgramAccount.getAlipayPublicKey());
// alipayConfig.setCharset("utf-8");
// alipayConfig.setSignType("RSA2");
// return new DefaultAlipayClient(alipayConfig);
// }
}

@ -0,0 +1,46 @@
package com.java3y.austin.handler.config;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.java3y.austin.common.dto.account.AlipayMiniProgramAccount;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author
* @date 2022-12-07
*/
public class AlipayClientSingleton {
private static volatile DefaultAlipayClient alipayClientSingleton;
private static Map<String, DefaultAlipayClient> alipayClientMap = new HashMap<>();
private AlipayClientSingleton() {
}
public static DefaultAlipayClient getSingleton(AlipayMiniProgramAccount alipayMiniProgramAccount) throws AlipayApiException {
if (!alipayClientMap.containsKey(alipayMiniProgramAccount.getAppId())) {
synchronized (DefaultAlipayClient.class) {
if (!alipayClientMap.containsKey(alipayMiniProgramAccount.getAppId())) {
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
alipayConfig.setAppId(alipayMiniProgramAccount.getAppId());
alipayConfig.setPrivateKey(alipayMiniProgramAccount.getPrivateKey());
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(alipayMiniProgramAccount.getAlipayPublicKey());
alipayConfig.setCharset("utf-8");
alipayConfig.setSignType("RSA2");
alipayClientSingleton = new DefaultAlipayClient(alipayConfig);
alipayClientMap.put(alipayMiniProgramAccount.getAppId(), alipayClientSingleton);
return alipayClientSingleton;
}
}
}
return alipayClientMap.get(alipayMiniProgramAccount.getAppId());
}
}

@ -12,7 +12,7 @@ import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ -56,7 +56,7 @@ public class SlideWindowLimitService extends AbstractLimitService {
String key = LIMIT_TAG + deduplicationSingleKey(service, taskInfo, receiver);
String scoreValue = String.valueOf(IdUtil.getSnowflake().nextId());
String score = String.valueOf(nowTime);
if (redisUtils.execLimitLua(redisScript, Arrays.asList(key), String.valueOf(param.getDeduplicationTime() * 1000), score, String.valueOf(param.getCountNum()), scoreValue)) {
if (redisUtils.execLimitLua(redisScript, Collections.singletonList(key), String.valueOf(param.getDeduplicationTime() * 1000), score, String.valueOf(param.getCountNum()), scoreValue)) {
filterReceiver.add(receiver);
}

@ -170,13 +170,14 @@ public class RedisUtils {
try {
Long execute = redisTemplate.execute(redisScript, keys, args);
if (execute == null) {
return false;
}
return CommonConstant.TRUE.equals(execute.intValue());
} catch (Exception e) {
log.error("redis execLimitLua fail! e:{}", Throwables.getStackTraceAsString(e));
}
return false;
}

Loading…
Cancel
Save