Commit 121dc2b4 by ddx

请求404推送异常信息

parent 719a1c3d
......@@ -509,4 +509,15 @@ public final class JSONHelper {
}
return invList;
}
public static boolean isJSONObject(String str) {
boolean isJSONObject = false;
if(StringUtil.isNotEmpty(str)) {
str = str.trim();
if(str.startsWith("{") && str.endsWith("}")) {
isJSONObject = true;
}
}
return isJSONObject;
}
}
......@@ -73,6 +73,9 @@ public class TokenConstants {
public static String NUONUO_TOKEN = "7176fb23bbca56e0d822ef0vwiatikls";
public static String NUONUO_TAXNUM = "339901123456789";
public static String LOGIN_DING_URL = null;
public static String LOGIN_KEYWORDS = null;
static {
urlMap = new HashMap<String, String>();
urlMap.put("1100", "https://fpdk.bjsat.gov.cn/");
......@@ -204,6 +207,15 @@ public class TokenConstants {
PUSH_COOKIE_URL = pushCookieUrl;
}
@Value("${token.loginDingUrl}")
public void setLoginDingUrl(String loginDingUrl) {
LOGIN_DING_URL = loginDingUrl;
}
@Value("${token.loginKeywords}")
public void setLoginKeywords(String loginKeywords) {
LOGIN_KEYWORDS = loginKeywords;
}
/**用户类型 0-小号 1-正常 2-人工 start*/
/**
......
......@@ -6,6 +6,7 @@ import com.tax.token.model.TkServer;
import com.tax.token.model.TkToken;
import com.tax.token.model.TkZoneInfo;
import com.tax.token.thirdService.TokenThirdServiceI;
import com.tax.token.utils.DingdingUtil;
import com.yxcheng.token.utils.*;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpException;
......@@ -49,6 +50,7 @@ public class GetTokenFromEleJsonTax implements TokenThirdServiceI {
ResponseContent ret = HttpHelper.postJsonEntity(url,json.toString(), 30000, 90000);
String resultStr = ret.getContent();
logger.info(uuIdFlag + " GetTokenFromEleJsonTax taxno is " + taxno + ",result is " + resultStr);
DingdingUtil.sendLoginErrorNotice(uuIdFlag, tokenEntity, resultStr);
if(StringUtils.isNotEmpty(resultStr)) {
Map<String, Object> resultStrMap = JSONHelper.parserToMap(resultStr);
resultMap.put("code", ObjectUtil.fixNull(resultStrMap.get("code")));
......
package com.tax.token.utils;
import com.alibaba.fastjson.JSONObject;
import com.tax.token.constants.TokenConstants;
import com.tax.token.model.TkToken;
import com.yxcheng.token.utils.HttpHelper;
import com.yxcheng.token.utils.JSONHelper;
import com.yxcheng.token.utils.ResponseContent;
import com.yxcheng.token.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class DingdingUtil {
private static final Logger logger = LoggerFactory.getLogger(DingdingUtil.class);
public static String monitorLoginDingUrl = TokenConstants.LOGIN_DING_URL;
public static String monitorKeywords = TokenConstants.LOGIN_KEYWORDS;
public static String sendDingInfo(String url, String content) {
String result = "";
JSONObject dingJson = new JSONObject();
dingJson.put("msgtype", "text");
JSONObject contJson = new JSONObject();
contJson.put("content", content);
JSONObject atJson = new JSONObject();
atJson.put("atMobiles", new String[]{});
atJson.put("isAtAll", false);
dingJson.put("text", contJson);
dingJson.put("at", atJson);
try {
ResponseContent res = HttpHelper.postJsonEntity(url, dingJson.toString());
result = res.getContent();
} catch (Exception e) {
e.printStackTrace();
logger.error(content + " send message is error!" + e.getMessage());
}
return result;
}
public static void sendLoginErrorNotice(String uuIdFlag, TkToken tokenEntity, String content) {
try {
String result = "";
if(StringUtil.isNotEmpty(content) && !JSONHelper.isJSONObject(content)) {
CheckResult checkResult = checkContentErrorFlag(content);
if(checkResult.getNoticeFlag()) {
String sendContent = "【登录异常】:" + tokenEntity.getUserCode()
+ "," + tokenEntity.getTaxno() + "," + uuIdFlag + ",异常关键字:" + checkResult.getNoticeKeyword();
result = sendDingInfo(monitorLoginDingUrl, sendContent);
logger.info(uuIdFlag + " sendContent " + sendContent+ " send message result is " + result);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error(uuIdFlag + " sendLoginErrorNotice is error!" + e.getMessage());
}
}
public static CheckResult checkContentErrorFlag(String content) {
CheckResult checkResult = new CheckResult();
String[] keywordArr = monitorKeywords.split(",");
for(String keyword:keywordArr) {
if(content.contains(keyword)) {
checkResult.setNoticeFlag(true);
checkResult.setNoticeKeyword(keyword);
break;
}
}
return checkResult;
}
static class CheckResult {
private boolean noticeFlag = false;
private String noticeKeyword;
public boolean getNoticeFlag() {
return noticeFlag;
}
public void setNoticeFlag(boolean noticeFlag) {
this.noticeFlag = noticeFlag;
}
public String getNoticeKeyword() {
return noticeKeyword;
}
public void setNoticeKeyword(String noticeKeyword) {
this.noticeKeyword = noticeKeyword;
}
}
}
......@@ -65,15 +65,7 @@ public class TokenController extends BaseClientController {
if(cookieReq.checkParamNull() || !ZoneUtil.dqList.contains(cookieReq.getZoneCode())) {
return JsonResult.errorResult(ResultEnum.param_error.getCode(), ResultEnum.param_error.getMessage());
}
// if (tokenService.checkTokenRealRequestCount(cookieReq.getAccessKeyID(), cookieReq.getTaxno())) {
// int realRequestCount = tokenService.getTokenRealRequestCount(cookieReq.getAccessKeyID(), cookieReq.getTaxno());
// if(realRequestCount>60) {
// return JsonResult.errorResult(ResultEnum.system_error.getCode(), "请求太频繁,请20分钟后重试!");
// }
// }
String uuId = UUIDGenerator.generate();
// tokenService.setTokenRealRequestCount(cookieReq.getAccessKeyID(), cookieReq.getTaxno());
return tokenService.getRealCookie(uuId, cookieReq.getTaxno(), cookieReq.getZoneCode(), cookieReq.getAccessKeyID(), true, TokenConstants.FUNCTION_NO_FPY, cookieReq.getUserInfoJson(), cookieReq.getCheckType(), cookieReq.getSite(), cookieReq.getTarget());
}
......
......@@ -12,9 +12,9 @@ import java.util.Map;
public class TokenUnitTest {
// static String host = "http://47.94.208.133:8762";
static String host = "http://127.0.0.1:8762";
// static String host = "https://api.taxservices.cn";
static String host = "https://api.xfapiao.com";
// static String host = "https://api.xfapiao.com";
String accessKeyID = "eyongyou";
static String accessKeySecret = "yongyou!@#566ccd";
......@@ -131,8 +131,8 @@ public class TokenUnitTest {
param.put("timeStamp",timeStamp);
param.put("version","1.0");
param.put("signature",getSign(signStr));
param.put("taxno","92370203MA3R2F3Q03");
param.put("zoneCode","3702");
param.put("taxno","92220203MA3R2F3Q03");
param.put("zoneCode","2200");
// param.put("userInfo",Base64Util.encode("刘志怡021323[a%b@q]Lzy672672[a%b@q]"));
Map userparam = new HashMap<>();
......
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