Commit 66d3ed23 by 徐高华

调用次数限制

parent 187ece79
......@@ -8,6 +8,9 @@ import java.util.Random;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.redisson.api.RRateLimiter;
import org.redisson.api.RateIntervalUnit;
import org.redisson.api.RateType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -20,6 +23,7 @@ import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.haoban.common.utils.DingUtils;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.dto.hm.HmLinkDTO;
import com.gic.haoban.manage.api.dto.hm.HmLinkStoreDTO;
......@@ -46,6 +50,7 @@ import com.gic.haoban.manage.service.service.hm.HmQrcodeTempService;
import com.gic.member.api.dto.es.MemberDataDTO;
import com.gic.member.api.dto.es.MemberStoreClerkDataDTO;
import com.gic.member.api.service.MemberService;
import com.gic.redis.data.util.RedisUtil;
import com.gic.wechat.api.dto.qywx.welcome.QywxExternalcontactDTO;
import com.gic.wechat.api.dto.qywx.welcome.QywxExternalcontactResultDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
......@@ -299,10 +304,11 @@ public class HmLinkApiServiceImpl implements HmLinkApiService {
bo.setHmId(hm.getHmId());
String dthmKey = this.keyDataService.saveDataForLink(enterpriseId, bo);
if (null != dthmKey) {
ServiceResponse<Void> addResp = this.addQrcode(hm, dthmKey, wxEnterpriseDTO.getCorpid(), retDTO);
ServiceResponse<String> addResp = this.addQrcode(hm, dthmKey, wxEnterpriseDTO.getCorpid(), retDTO);
if (!addResp.isSuccess()) {
// 创建动态活码失败
return ServiceResponse.failure(HaoBanErrCode.ERR_OTHER.getCode(), addResp.getMessage());
retDTO.setHmQrcode(hm.getWxQrcode());
}else {
retDTO.setHmQrcode(addResp.getResult());
}
}
// 查询页面
......@@ -317,7 +323,11 @@ public class HmLinkApiServiceImpl implements HmLinkApiService {
}
// 创建活码
private ServiceResponse<Void> addQrcode(HmQrcodeBO hm, String key, String corpid, HmLinkWxaDTO retDTO) {
private ServiceResponse<String> addQrcode(HmQrcodeBO hm, String key, String corpid, HmLinkWxaDTO retDTO) {
String limitQrcode = this.limitIp(hm) ;
if(StringUtils.isNotEmpty(limitQrcode)) {
return ServiceResponse.failure(HaoBanErrCode.ERR_OTHER.getCode(), "超限制数");
}
QywxExternalcontactDTO paramsDTO = new QywxExternalcontactDTO();
// 联系方式类型,1-单人, 2-多人 场景,1-在小程序中联系,2-通过二维码联系
paramsDTO.setType(1);
......@@ -338,11 +348,25 @@ public class HmLinkApiServiceImpl implements HmLinkApiService {
qo.setWxQrcode(dto.getQr_code());
qo.setRelationId(key);
this.hmQrcodeTempService.save(qo);
return ServiceResponse.success();
return ServiceResponse.success(dto.getQr_code());
}
return ServiceResponse.failure(HaoBanErrCode.ERR_OTHER.getCode(), "企微错误:" + dto.getErrmsg());
}
private String limitIp(HmQrcodeBO hm) {
String ipKey = "hmadd:limit:ip" ;
int ipLimitCount = 1;
RRateLimiter rateLimiter = RedisUtil.getRedisClient().getRateLimiter(ipKey);
rateLimiter.trySetRate(RateType.OVERALL, ipLimitCount, 1, RateIntervalUnit.SECONDS);
if(rateLimiter.tryAcquire()) {
return null ;
}
String msg = "活码调用次数告警【ip】";
DingUtils.send(msg, false);
return hm.getWxQrcode() ;
}
private HmQrcodeBO getHmFromClerk(String clerkId, String wxEnterpriseId) {
if (StringUtils.isBlank(clerkId) || "-1".equals(clerkId)) {
return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment