diff --git a/src/com/customization/sendtodo/HttpReqUtils.java b/src/com/customization/sendtodo/HttpReqUtils.java index 68424c79..b2b473da 100644 --- a/src/com/customization/sendtodo/HttpReqUtils.java +++ b/src/com/customization/sendtodo/HttpReqUtils.java @@ -35,7 +35,7 @@ public class HttpReqUtils extends BaseBean{ try { Response response = client.newCall(request).execute(); int code = response.code(); - String bodyMsg = msgData = response.body().string(); + String bodyMsg = response.body().string(); bb.writeLog("response.code():"+code); bb.writeLog("response.body():"+bodyMsg); if(code == 200){ diff --git a/src/com/customization/sendtodo/HttpRequestUtil.java b/src/com/customization/sendtodo/HttpRequestUtil.java index 3d03baf8..1a57aac8 100644 --- a/src/com/customization/sendtodo/HttpRequestUtil.java +++ b/src/com/customization/sendtodo/HttpRequestUtil.java @@ -37,7 +37,7 @@ public class HttpRequestUtil extends BaseBean{ Response response = client.newCall(request).execute(); int code = response.code(); - String bodyMsg = msgData = response.body().string(); + String bodyMsg = response.body().string(); bb.writeLog("response.code():"+code); bb.writeLog("response.body():"+bodyMsg); if(code == 200){ diff --git a/src/com/customization/sendtodo/SendPortalTodoUtil.java b/src/com/customization/sendtodo/SendPortalTodoUtil.java index 3f7696ab..4e296813 100644 --- a/src/com/customization/sendtodo/SendPortalTodoUtil.java +++ b/src/com/customization/sendtodo/SendPortalTodoUtil.java @@ -31,7 +31,7 @@ public class SendPortalTodoUtil { BaseBean bb = new BaseBean(); RecordSet rs = new RecordSet(); - JSONArray emailArray = new JSONArray(); + String emailArray = ""; String requestname = ""; String requestremark = "" ; @@ -128,7 +128,7 @@ public class SendPortalTodoUtil { bb.writeLog("email1:"+email); Matcher matcher = regex.matcher(email); if(matcher.matches()){ - emailArray.add(email); + emailArray += StringUtils.isEmpty(emailArray) ? email : ","+email ; } } @@ -146,12 +146,12 @@ public class SendPortalTodoUtil { String resultCode = msgObject.getString("resultCode"); if("0".equals(resultCode)){ - bb.writeLog("emailArray:"+emailArray.toJSONString()); - if(emailArray.size() > 0) + bb.writeLog("emailArray:"+emailArray); + if(StringUtils.isNotEmpty(emailArray)) { String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; - sendMailUtil.sendMail(requestId,emailArray.toJSONString(),notificationSubject,notificationContent); + sendMailUtil.sendMail(requestId,emailArray,notificationSubject,notificationContent); } }else{ @@ -183,7 +183,7 @@ public class SendPortalTodoUtil { String requestremark = "" ; JSONObject requestObject = new JSONObject(); - JSONArray emailArray = new JSONArray(); + String emailArray = ""; Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); BaseBean bb = new BaseBean(); @@ -282,7 +282,7 @@ public class SendPortalTodoUtil { bb.writeLog("email2:"+email); Matcher matcher = regex.matcher(email); if(matcher.matches()){ - emailArray.add(email); + emailArray += StringUtils.isEmpty(emailArray) ? email : ","+email ; } } @@ -299,12 +299,12 @@ public class SendPortalTodoUtil { String resultCode = msgObject.getString("resultCode"); if("0".equals(resultCode)){ - bb.writeLog("emailArray:"+emailArray.toJSONString()); - if(emailArray.size() > 0) + bb.writeLog("emailArray:"+emailArray); + if(StringUtils.isNotEmpty(emailArray)) { String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; - sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); + sendMailUtil.sendMail(requestid,emailArray,notificationSubject,notificationContent); } }else{ sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); @@ -342,7 +342,7 @@ public class SendPortalTodoUtil { String objectId = "" ; String requestname = "" ; - JSONArray emailArray = new JSONArray(); + String emailArray = ""; Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); try { @@ -509,7 +509,7 @@ public class SendPortalTodoUtil { bb.writeLog("email3:"+email); Matcher matcher = regex.matcher(email); if(matcher.matches()){ - emailArray.add(email); + emailArray += StringUtils.isEmpty(emailArray) ? email : ","+email ; } } requestObject.put("taskObjectList",taskObjectList); @@ -526,15 +526,14 @@ public class SendPortalTodoUtil { String resultCode = msgObject.getString("resultCode"); if("0".equals(resultCode)){ - bb.writeLog("emailArray:"+emailArray.toJSONString()); - if(emailArray.size() > 0) + bb.writeLog("emailArray:"+emailArray); + if(StringUtils.isNotEmpty(emailArray)) { String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; - sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); + sendMailUtil.sendMail(requestid,emailArray,notificationSubject,notificationContent); } - }else{ sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); } @@ -560,7 +559,7 @@ public class SendPortalTodoUtil { SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil(); JSONObject requestObject = new JSONObject(); - JSONArray emailArray = new JSONArray(); + String emailArray = ""; Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); BaseBean bb = new BaseBean(); @@ -659,9 +658,8 @@ public class SendPortalTodoUtil { bb.writeLog("email4:"+email); Matcher matcher = regex.matcher(email); if(matcher.matches()){ - emailArray.add(email); + emailArray += StringUtils.isEmpty(emailArray) ? email : ","+email ; } - } requestObject.put("taskObjectList",taskObjectList); @@ -677,12 +675,12 @@ public class SendPortalTodoUtil { String resultCode = msgObject.getString("resultCode"); if("0".equals(resultCode)){ - bb.writeLog("emailArray:"+emailArray.toJSONString()); - if(emailArray.size() > 0) + bb.writeLog("emailArray:"+emailArray); + if(StringUtils.isNotEmpty(emailArray)) { String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; - sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); + sendMailUtil.sendMail(requestid,emailArray,notificationSubject,notificationContent); } }else{ sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); diff --git a/src/weaver/interfaces/util/SendMailUtil.java b/src/weaver/interfaces/util/SendMailUtil.java index b7de5590..db42f825 100644 --- a/src/weaver/interfaces/util/SendMailUtil.java +++ b/src/weaver/interfaces/util/SendMailUtil.java @@ -1,5 +1,6 @@ package weaver.interfaces.util; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import okhttp3.*; import org.apache.commons.lang.StringUtils; @@ -15,79 +16,78 @@ public class SendMailUtil{ public static BaseBean baseBean = new BaseBean(); String emailenable = baseBean.getPropValue("PORTAL_INFO","emailenable"); - public void sendMail(String requestid,String emails,String notificationSubject,String notificationContent){ + public void sendMail(String requestid, String emails, String notificationSubject, String notificationContent){ baseBean.writeLog("emailenable:"+emailenable); - if(!"1".equals(emailenable)){ - return; - } - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); - String emailUrl = baseBean.getPropValue("PORTAL_INFO","emailUrl"); - String emailMethod = baseBean.getPropValue("PORTAL_INFO","emailMethod"); - String emailEventCode = baseBean.getPropValue("PORTAL_INFO","emailEventCode"); - String emailNotificationType = baseBean.getPropValue("PORTAL_INFO","emailNotificationType"); - String emailChannel = baseBean.getPropValue("PORTAL_INFO","emailChannel"); - String emailVersion = baseBean.getPropValue("PORTAL_INFO","emailVersion"); - String triggerTime = sdf.format(new Date()); - - JSONObject requestJson = new JSONObject(); - requestJson.put("eventCode",emailEventCode); - requestJson.put("triggerTime",triggerTime); - requestJson.put("notificationType",emailNotificationType); - requestJson.put("email",emails); - requestJson.put("channel",emailChannel); - requestJson.put("notificationSubject",notificationSubject); - requestJson.put("notificationContent",notificationContent); - - try{ - String responseData = doGetAccessToken(); - baseBean.writeLog("responseData:"+responseData); - String accessToken = "" ; - if(StringUtils.isNotEmpty(responseData)){ - JSONObject responseObject = JSONObject.parseObject(responseData); - if(responseObject.containsKey("resCode") && responseObject.containsKey("data")){ - String resCode = responseObject.getString("resCode"); - if("00000".equals(resCode)){ - JSONObject dataObject = responseObject.getJSONObject("data"); - if(dataObject.containsKey("accessToken")){ - accessToken = dataObject.getString("accessToken"); + if("1".equals(emailenable)) + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String emailUrl = baseBean.getPropValue("PORTAL_INFO","emailUrl"); + String emailMethod = baseBean.getPropValue("PORTAL_INFO","emailMethod"); + String emailEventCode = baseBean.getPropValue("PORTAL_INFO","emailEventCode"); + String emailNotificationType = baseBean.getPropValue("PORTAL_INFO","emailNotificationType"); + String emailChannel = baseBean.getPropValue("PORTAL_INFO","emailChannel"); + String emailVersion = baseBean.getPropValue("PORTAL_INFO","emailVersion"); + String triggerTime = sdf.format(new Date()); + + JSONObject requestJson = new JSONObject(); + requestJson.put("eventCode",emailEventCode); + requestJson.put("triggerTime",triggerTime); + requestJson.put("notificationType",emailNotificationType); + requestJson.put("email",emails); + requestJson.put("channel",emailChannel); + requestJson.put("notificationSubject",notificationSubject); + requestJson.put("notificationContent",notificationContent); + + try{ + String responseData = doGetAccessToken(); + baseBean.writeLog("responseData:"+responseData); + String accessToken = "" ; + if(StringUtils.isNotEmpty(responseData)){ + JSONObject responseObject = JSONObject.parseObject(responseData); + if(responseObject.containsKey("resCode") && responseObject.containsKey("data")){ + String resCode = responseObject.getString("resCode"); + if("00000".equals(resCode)){ + JSONObject dataObject = responseObject.getJSONObject("data"); + if(dataObject.containsKey("accessToken")){ + accessToken = dataObject.getString("accessToken"); + } } } } - } - if(StringUtils.isNotEmpty(accessToken)){ + if(StringUtils.isNotEmpty(accessToken)){ - JSONObject jsonObject = new JSONObject(); - jsonObject.put("access_token",accessToken); - jsonObject.put("method",emailMethod); - jsonObject.put("version",emailVersion); - jsonObject.put("content",requestJson); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("access_token",accessToken); + jsonObject.put("method",emailMethod); + jsonObject.put("version",emailVersion); + jsonObject.put("content",requestJson); // "{\r\n \"access_token\": \"\",\r\n \"method\": \"sendNotification\",\r\n \"version\": \"1.0\",\r\n \"content\": {\"eventCode\":\"\", \r\n \"transId\":\"\", \r\n \"triggerTime\":\"20221020094013\",\r\n \"notificationType\":\"EMAIL\",\r\n \"email\":\"798989044@qq.com\", \r\n \"channel\":\"OA\", \r\n \"notificationSubject\":\"新待办到达\",\r\n \"notificationContent\":\"新待办到达,清及时处理\" }\r\n}" - baseBean.writeLog("jsonObject:"+jsonObject.toJSONString()); - - OkHttpClient client = new OkHttpClient().newBuilder().build(); - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType,jsonObject.toJSONString()); - Request request = new Request.Builder() - .url(emailUrl) - .method("POST", body) - .addHeader("Content-Type", "application/json") - .build(); - Response response = client.newCall(request).execute(); - baseBean.writeLog("response.code():"+response.code()); - baseBean.writeLog("response.body():"+response.body().string()); - - if(response!=null && response.code() != 200){ - baseBean.writeLog(response.body().string()); + baseBean.writeLog("jsonObject:"+jsonObject.toJSONString()); + + OkHttpClient client = new OkHttpClient().newBuilder().build(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType,jsonObject.toJSONString()); + Request request = new Request.Builder() + .url(emailUrl) + .method("POST", body) + .addHeader("Content-Type", "application/json") + .build(); + Response response = client.newCall(request).execute(); + int code = response.code(); + String bodyMsg = response.body().string(); + baseBean.writeLog("response.code():"+code); + baseBean.writeLog("response.body():"+bodyMsg); } + }catch (IOException e) { + e.printStackTrace(); + baseBean.writeLog(e); + }catch (Exception e){ + baseBean.writeLog(e); } - }catch (IOException e) { - e.printStackTrace(); - baseBean.writeLog(e); - }catch (Exception e){ - baseBean.writeLog(e); } + } /*** @@ -96,6 +96,7 @@ public class SendMailUtil{ */ public String doGetAccessToken(){ + baseBean.writeLog("doGetAccessToken == "); String responseData = "" ; RSAUtils RSAUtils = new RSAUtils(); @@ -105,6 +106,8 @@ public class SendMailUtil{ String emailResponseType = baseBean.getPropValue("PORTAL_INFO","emailResponseType") ; //token String emailPrivateKey = baseBean.getPropValue("PORTAL_INFO","emailPrivateKey") ; + baseBean.writeLog("emainAppCode == "+emainAppCode); + //String privateKey = "MIIEvA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wv0oe0s37Sgz9IRMe/2UwKBgGQCGUnGR80TANAHg5xx8TsaXhXacAqzHaXeHEB/ZMtrA4AIXnB3MTKA0yPy9dFcvGAyvO+KFiFAGjInBqhYPNFgvgLKuEed4sFyXiT2RhtW4V4VpO3y8Zv84VDoOZSOTL2DdYfRVG2jHGM2pCxN9uFDWKzeNN6+RQg8ouY9nLkbAoGACme1IwbatTgEx2KrK3jkjcN4A8iwbM8f5HMoPZHqaPht1S1R0xQBvRFa9hNiBExtn63wnEYyim5lUl5xVjBYXd8ZgDPbzjvGR3H+PI2ZVJShO78P9Id0IEc0E2L/kvUH/wXlhF4ozO1/aQ3CYgiaUgJOkRqmqSe5Bm5ir7GY+xkCgYBkfmFhBI9m8AxljI3oJAGv43EGw2s6wZkrQXFBStYBSxTkkS9JHMbkNrKgKvsuzPLUCD0hmdTPREh/miO/0VNXZaa05L7xhgvakezI4f2BSY6tCMXHiBmnRXE8JL4+rEvWAKUaMCTynoyGRetl+JmooLZ5Fez1250hw5vWdSUudA=="; //"{\"appCode\":\""+appCode+"\",\r\n\t\"appSecret\":\"9f5a519622a8790b\",\r\n\t\"responseType\":\"token\",\r\n\t\"timestamp\":\"1592212221795\",\r\n\t\"sign\":\"LE4MPesIy8BCxOa958cQxX0cW1ObvOfCn2dDUK6AzCukcvyS6EvFMLzSBFiCgcMT1w9cYAbSIOWL2SENvpC2qxXrgtWJd6B3J1dUmL5ZBtOEGZ6ymRz7IAQraA1TG82Y0ZTgVFhOGS/TtbTjdEhurwcclWdbSPEy6uZesoQpyF7MAW+hb5Y5ioqe1ky7RE15W/gwJDONgLifUoZnXhowjsJHBJ/xCwdfQi48/wu0CX+G46C+fSYHKncGbeeg7hFyaltNWsco0ScWLB/JjKA1qZv+pPFGaWGidfoTErq7Ux8fIYH3cRjRoSNknOcawi+zjy8GMBDjxIk9lX7+Oz1wYA==\"\r\n}" @@ -130,13 +133,20 @@ public class SendMailUtil{ .addHeader("Content-Type", "application/json") .build(); Response response = client.newCall(request).execute(); - baseBean.writeLog("response.code():"+response.code()); - baseBean.writeLog("response.body():"+response.body().string()); - responseData = response.body().string(); + + int code = response.code(); + String bodyMsg = response.body().string(); + baseBean.writeLog("response.code():"+code); + baseBean.writeLog("response.body():"+bodyMsg); + if(code == 200){ + responseData = bodyMsg; + } } catch (IOException e) { e.printStackTrace(); + baseBean.writeLog(e); } catch (Exception e) { e.printStackTrace(); + baseBean.writeLog(e); } return responseData; }