|
|
@ -8,9 +8,11 @@ import com.dingtalk.api.DingTalkClient; |
|
|
|
import com.dingtalk.api.request.OapiRobotSendRequest; |
|
|
|
import com.dingtalk.api.response.OapiRobotSendResponse; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.DingTalkTextMsg; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.ModuleConstant; |
|
|
|
import com.epmet.constant.ThirdRedisKeyConstant; |
|
|
|
import com.epmet.constant.ThirdRunTimeInfoConstant; |
|
|
@ -31,6 +33,7 @@ import com.fasterxml.jackson.core.JsonGenerator; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.taobao.api.ApiException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.dom4j.DocumentException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -38,11 +41,14 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.crypto.Mac; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
@ -156,17 +162,15 @@ public class WarrantServiceImpl implements WarrantService { |
|
|
|
switch (event) { |
|
|
|
case ModuleConstant.WEAPP_AUDIT_SUCCESS: |
|
|
|
codeResult = ModuleConstant.AUDIT_SUCCESS; |
|
|
|
this.dingDingRobot(reason,null,customerName,client); |
|
|
|
break; |
|
|
|
case ModuleConstant.WEAPP_AUDIT_FAIL: |
|
|
|
codeResult = ModuleConstant.AUDIT_FAILED; |
|
|
|
this.dingDingRobot(reason,codeResult,customerName,client); |
|
|
|
break; |
|
|
|
case ModuleConstant.WEAPP_AUDIT_DELAY: |
|
|
|
codeResult = ModuleConstant.DELAY; |
|
|
|
this.dingDingRobot(reason,codeResult,customerName,client); |
|
|
|
break; |
|
|
|
} |
|
|
|
this.dingDingRobot(reason,codeResult,customerName,client); |
|
|
|
String codeCustomerId = codeCustomerDao.selectCodeCustomerId(codeAuditRecord); |
|
|
|
codeAuditResultDao.updateAuditResult(customerId, codeCustomerId, codeResult); |
|
|
|
log.info("消息与事件接收URL【代码审核结果】结束......"); |
|
|
@ -190,18 +194,12 @@ public class WarrantServiceImpl implements WarrantService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*public static void main(String[] args) { |
|
|
|
WarrantServiceImpl w = new WarrantServiceImpl(); |
|
|
|
w.dingDingRobot("haha","weapp_audit_fail","haha","jumian"); |
|
|
|
}*/ |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 钉钉机器人报警 |
|
|
|
* @author zxc |
|
|
|
* @date 2020/8/5 4:33 下午 |
|
|
|
*/ |
|
|
|
public void dingDingRobot(String result,String event,String customerName,String clientType){ |
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=2438902efbcc15909deb7076963c5cbe2d6fdbfdb9d66750faab2f2cce6eb09f"); |
|
|
|
OapiRobotSendRequest request = new OapiRobotSendRequest(); |
|
|
|
request.setMsgtype("markdown"); |
|
|
|
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); |
|
|
@ -227,12 +225,37 @@ public class WarrantServiceImpl implements WarrantService { |
|
|
|
} |
|
|
|
request.setMarkdown(markdown); |
|
|
|
try { |
|
|
|
OapiRobotSendResponse response = client.execute(request); |
|
|
|
} catch (ApiException e) { |
|
|
|
String url = "https://oapi.dingtalk.com/robot/send?access_token=2438902efbcc15909deb7076963c5cbe2d6fdbfdb9d66750faab2f2cce6eb09f"; |
|
|
|
String secret = "SECe3c785dd254659608667a4a623acc5a0395636143411617f6e36838b48941e74"; |
|
|
|
this.sendCodeMsg(request,url,secret); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("机器人生病了......"); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
/* |
|
|
|
public static void main(String[] args) { |
|
|
|
WarrantServiceImpl w = new WarrantServiceImpl(); |
|
|
|
w.dingDingRobot("审核失败","weapp_audit_fail","机器人测试","居民端"); |
|
|
|
}*/ |
|
|
|
|
|
|
|
public Result<String> sendCodeMsg(OapiRobotSendRequest request,String url,String secret) { |
|
|
|
Long timestamp = System.currentTimeMillis(); |
|
|
|
|
|
|
|
try { |
|
|
|
String stringToSign = timestamp + "\n" + secret; |
|
|
|
Mac mac = Mac.getInstance("HmacSHA256"); |
|
|
|
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); |
|
|
|
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8")); |
|
|
|
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8"); |
|
|
|
url = url.concat("×tamp=" + timestamp + "&sign=" + sign); |
|
|
|
Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(request)); |
|
|
|
String data = stringResult.getData(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return new Result<String>().error(); |
|
|
|
} |
|
|
|
|
|
|
|
public String getClient(String clientType){ |
|
|
|
String result = clientType == "resi" ? "居民端" : "工作端"; |
|
|
|