WechatMsgNotifyImpl.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. package com.java110.job.msgNotify.wechat;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.java110.core.client.RestTemplate;
  5. import com.java110.core.log.LoggerFactory;
  6. import com.java110.dto.mapping.Mapping;
  7. import com.java110.dto.owner.OwnerAppUserDto;
  8. import com.java110.dto.user.StaffAppAuthDto;
  9. import com.java110.dto.wechat.Content;
  10. import com.java110.dto.wechat.PropertyFeeTemplateMessage;
  11. import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
  12. import com.java110.intf.user.IStaffAppAuthInnerServiceSMO;
  13. import com.java110.job.msgNotify.IMsgNotify;
  14. import com.java110.job.msgNotify.IWechatTemplate;
  15. import com.java110.job.msgNotify.MsgNotifyFactory;
  16. import com.java110.utils.cache.MappingCache;
  17. import com.java110.utils.constant.MappingConstant;
  18. import com.java110.utils.util.DateUtil;
  19. import com.java110.utils.util.StringUtil;
  20. import com.java110.vo.ResultVo;
  21. import org.slf4j.Logger;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.http.ResponseEntity;
  24. import org.springframework.stereotype.Service;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. @Service("wechatMsgNotifyImpl")
  29. public class WechatMsgNotifyImpl implements IMsgNotify {
  30. private static final Logger logger = LoggerFactory.getLogger(WechatMsgNotifyImpl.class);
  31. private static final String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
  32. public static final String SPEC_CD_TOKEN = "33001";//token
  33. public static final String SPEC_CD_OWE_FEE_TEMPLATE = "33002";//欠费推送模板
  34. public static final String SPEC_CD_WECHAT_TEMPLATE = "33003";//欠费推送模板、装修跟踪记录通知
  35. public static final String SPEC_CD_WECHAT_SUCCESS_TEMPLATE = "33004";//业主缴费成功推送模板
  36. public static final String SPEC_CD_WECHAT_EXPIRE_TEMPLATE = "33005";//业主费用到期通知推送模板
  37. public static final String SPEC_CD_WECHAT_PROCESS_TEMPLATE = "33006";//办公系统审批通知
  38. public static final String SPEC_CD_WECHAT_ROOM_STATE_TEMPLATE = "33007";//空置房验房状态(通过和不通过)、审批状态(通过和不通过)模板
  39. public static final String SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE = "33008";//报修工单提醒模板
  40. public static final String SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE = "33009";//报修工单派单和转单提醒给维修师傅
  41. public static final String SPEC_CD_WECHAT_SCHEDULE_TEMPLATE = "33010";//报修工单派单和抢单提醒给业主,安排师傅维修(进度提醒)
  42. public static final String SPEC_CD_WECHAT_WORK_ORDER_END_TEMPLATE = "33011";//报修工单维修完成提醒给业主
  43. public static final String SPEC_CD_WECHAT_HOUSE_DECORATION_APPLY_TEMPLATE = "33012";//装修申请提醒给业主
  44. public static final String SPEC_CD_WECHAT_HOUSE_DECORATION_CHECK_TEMPLATE = "33013";//装修审核/完成提醒给物业管理人员
  45. public static final String SPEC_CD_WECHAT_HOUSE_DECORATION_CHECK_RESULT_TEMPLATE = "33014";//装修审核结果提醒给业主
  46. public static final String SPEC_CD_WECHAT_HOUSE_DECORATION_COMPLETED_TEMPLATE = "33015";//装修验收结果提醒给业主
  47. public static final String SPEC_CD_WECHAT_REPAIR_CHARGE_SCENE_TEMPLATE = "33016";//报修通知-上门维修现场收费通知业主
  48. public static final String SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_TEMPLATE = "33017";//流程待审批通知
  49. public static final String SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_FINISH_TEMPLATE = "33018";//流程待审批完成通知
  50. private static final Map<String, String[]> templateKeys = new HashMap<>();
  51. static {
  52. templateKeys.put(SPEC_CD_OWE_FEE_TEMPLATE, new String[]{"缴费类型", "房号", "总金额", "缴费周期"});
  53. templateKeys.put(SPEC_CD_WECHAT_PROCESS_TEMPLATE, new String[]{"流程名称", "发起时间", "发起人"});
  54. templateKeys.put(SPEC_CD_WECHAT_SUCCESS_TEMPLATE, new String[]{"缴费房间", "费用类型", "费用周期", "缴费金额"});
  55. templateKeys.put(SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE, new String[]{"报修类型", "报修地址", "报修问题"});
  56. templateKeys.put(SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE, new String[]{"联系人", "手机号", "报修时间", "维修地址"});
  57. templateKeys.put(SPEC_CD_WECHAT_SCHEDULE_TEMPLATE, new String[]{"平台受理人", "联系电话", "受理时间"});
  58. templateKeys.put(SPEC_CD_WECHAT_WORK_ORDER_END_TEMPLATE, new String[]{"房屋地址", "维修工程师", "维修完成时间"});
  59. templateKeys.put(SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_TEMPLATE, new String[]{"流程名称", "发起人", "发起时间"});
  60. templateKeys.put(SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_FINISH_TEMPLATE, new String[]{"流程名称", "流程状态"});
  61. }
  62. @Autowired
  63. private IWechatTemplate wechatTemplateImpl;
  64. @Autowired
  65. private IStaffAppAuthInnerServiceSMO staffAppAuthInnerServiceSMOImpl;
  66. @Autowired
  67. private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
  68. @Autowired
  69. private RestTemplate outRestTemplate;
  70. /**
  71. * 发送退费申请
  72. *
  73. * @param communityId
  74. * @param userId
  75. * @param content
  76. * @return
  77. */
  78. @Override
  79. public ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
  80. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  81. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  82. staffAppAuthDto.setStaffId(userId);
  83. staffAppAuthDto.setAppType("WECHAT");
  84. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  85. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  86. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  87. }
  88. String openId = staffAppAuthDtos.get(0).getOpenId();
  89. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_PROCESS_TEMPLATE);
  90. if (mapping == null) {
  91. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_PROCESS_TEMPLATE);
  92. }
  93. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_PROCESS_TEMPLATE));
  94. String url = sendMsgUrl + accessToken;
  95. JSONObject data = new JSONObject();
  96. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  97. templateMessage.setTemplate_id(templateId);
  98. templateMessage.setTouser(openId);
  99. data.put("thing2", new Content("退费申请审批"));
  100. data.put("time10", new Content(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B)));
  101. data.put("thing9", new Content(content.getString("name")));
  102. templateMessage.setData(data);
  103. //获取员工公众号地址
  104. String wechatUrl = MappingCache.getValue(MappingConstant.URL_DOMAIN, "STAFF_WECHAT_URL");
  105. templateMessage.setUrl(wechatUrl);
  106. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  107. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  108. logger.info("微信模板返回内容:{}", responseEntity);
  109. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  110. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  111. }
  112. /**
  113. * 欠费通知
  114. *
  115. * @param communityId 小区
  116. * @param userId 用户
  117. * @param contents [{
  118. * "feeTypeName",
  119. * "payerObjName",
  120. * "billAmountOwed",
  121. * "date",
  122. * url
  123. * }]
  124. * @return
  125. */
  126. @Override
  127. public ResultVo sendOweFeeMsg(String communityId, String userId, String ownerId, List<JSONObject> contents) {
  128. if (StringUtil.isEmpty(userId) || userId.startsWith("-")) {
  129. throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
  130. }
  131. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  132. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  133. ownerAppUserDto.setCommunityId(communityId);
  134. ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
  135. ownerAppUserDto.setUserId(userId);
  136. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  137. if (ownerAppUserDtos == null || ownerAppUserDtos.isEmpty()) {
  138. throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
  139. }
  140. String openId = ownerAppUserDtos.get(0).getOpenId();
  141. if (StringUtil.isEmpty(openId) || openId.startsWith("-")) {
  142. throw new IllegalArgumentException("没有获取到微信openId");
  143. }
  144. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_OWE_FEE_TEMPLATE);
  145. if (mapping == null) {
  146. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_OWE_FEE_TEMPLATE);
  147. }
  148. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_OWE_FEE_TEMPLATE));
  149. String url = sendMsgUrl + accessToken;
  150. JSONObject paramOut = null;
  151. for (JSONObject content : contents) {
  152. JSONObject data = new JSONObject();
  153. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  154. templateMessage.setTemplate_id(templateId);
  155. templateMessage.setTouser(openId);
  156. data.put("thing2", new Content(content.getString("feeTypeName")));
  157. String payerObjName = content.getString("payerObjName");
  158. if (!StringUtil.isEmpty(payerObjName) && payerObjName.length() > 20) {
  159. payerObjName = payerObjName.substring(0, 20);
  160. }
  161. data.put("thing12", new Content(payerObjName));
  162. data.put("amount3", new Content(content.getString("billAmountOwed")));
  163. data.put("time19", new Content(content.getString("date")));
  164. templateMessage.setData(data);
  165. templateMessage.setUrl(content.getString("url") + "&wAppId=" + wechatTemplateImpl.getAppId(communityId));
  166. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  167. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  168. logger.info("微信模板返回内容:{}", responseEntity);
  169. paramOut = JSONObject.parseObject(responseEntity.getBody());
  170. if (paramOut.getIntValue("errcode") != 0) {
  171. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  172. }
  173. }
  174. return new ResultVo(ResultVo.CODE_OK, "成功");
  175. }
  176. @Override
  177. public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
  178. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  179. String url = sendMsgUrl + accessToken;
  180. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_SUCCESS_TEMPLATE);
  181. if (mapping == null) {
  182. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_SUCCESS_TEMPLATE);
  183. }
  184. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_SUCCESS_TEMPLATE));
  185. String openId = "";
  186. if (MsgNotifyFactory.ROLE_OWNER.equals(role)) {
  187. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  188. ownerAppUserDto.setCommunityId(communityId);
  189. ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
  190. ownerAppUserDto.setUserId(userId);
  191. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  192. if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
  193. throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
  194. }
  195. openId = ownerAppUserDtos.get(0).getOpenId();
  196. } else {
  197. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  198. staffAppAuthDto.setStaffId(userId);
  199. staffAppAuthDto.setAppType("WECHAT");
  200. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  201. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  202. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  203. }
  204. openId = staffAppAuthDtos.get(0).getOpenId();
  205. }
  206. JSONObject data = new JSONObject();
  207. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  208. templateMessage.setTemplate_id(templateId);
  209. templateMessage.setTouser(openId);
  210. // data.put("thing2", new Content(content.getString("feeTypeCdName")));
  211. data.put("thing2", new Content(content.getString("feeName")));
  212. data.put("thing10", new Content(content.getString("payFeeRoom")));
  213. data.put("time18", new Content(content.getString("payFeeTime")));
  214. data.put("amount6", new Content(content.getString("receivedAmount")));
  215. templateMessage.setData(data);
  216. templateMessage.setUrl(content.getString("url"));
  217. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  218. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  219. logger.info("微信模板返回内容:{}", responseEntity);
  220. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  221. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  222. }
  223. /**
  224. * 业主报修时
  225. *
  226. * @param communityId 小区
  227. * @param userId 用户
  228. * @param content {
  229. * repairTypeName,
  230. * repairObjName,
  231. * repairName,
  232. * url
  233. * }
  234. * @return
  235. */
  236. @Override
  237. public ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
  238. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  239. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  240. staffAppAuthDto.setStaffId(userId);
  241. staffAppAuthDto.setAppType("WECHAT");
  242. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  243. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  244. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  245. }
  246. String openId = staffAppAuthDtos.get(0).getOpenId();
  247. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE);
  248. if (mapping == null) {
  249. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE);
  250. }
  251. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE));
  252. String url = sendMsgUrl + accessToken;
  253. JSONObject data = new JSONObject();
  254. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  255. templateMessage.setTemplate_id(templateId);
  256. templateMessage.setTouser(openId);
  257. data.put("thing8", new Content(content.getString("repairTypeName")));
  258. data.put("thing11", new Content(content.getString("repairObjName")));
  259. String context = content.getString("context");
  260. if (!StringUtil.isEmpty(context) && context.length() > 20) {
  261. context = context.substring(0, 20);
  262. }
  263. data.put("thing10", new Content(context));
  264. templateMessage.setData(data);
  265. templateMessage.setUrl(content.getString("url"));
  266. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  267. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  268. logger.info("微信模板返回内容:{}", responseEntity);
  269. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  270. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  271. }
  272. /**
  273. * 派单给维修师傅
  274. *
  275. * @param communityId 小区
  276. * @param userId 用户
  277. * @param content {
  278. * repairName,
  279. * tel,
  280. * time,
  281. * address
  282. * }
  283. * @return
  284. */
  285. @Override
  286. public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
  287. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  288. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  289. staffAppAuthDto.setStaffId(userId);
  290. staffAppAuthDto.setAppType("WECHAT");
  291. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  292. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  293. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  294. }
  295. String openId = staffAppAuthDtos.get(0).getOpenId();
  296. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
  297. if (mapping == null) {
  298. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE);
  299. }
  300. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_DISPATCH_REMIND_TEMPLATE));
  301. String url = sendMsgUrl + accessToken;
  302. JSONObject data = new JSONObject();
  303. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  304. templateMessage.setTemplate_id(templateId);
  305. templateMessage.setTouser(openId);
  306. data.put("thing7", new Content(content.getString("repairName")));
  307. data.put("phone_number3", new Content(content.getString("tel")));
  308. data.put("time13", new Content(content.getString("time")));
  309. data.put("thing9", new Content(content.getString("address")));
  310. templateMessage.setData(data);
  311. templateMessage.setUrl(content.getString("url"));
  312. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  313. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  314. logger.info("微信模板返回内容:{}", responseEntity);
  315. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  316. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  317. }
  318. /**
  319. * 派单给业主通知
  320. *
  321. * @param communityId 小区
  322. * @param userId 用户
  323. * @param content {
  324. * name,
  325. * tel,
  326. * time,
  327. * url
  328. * }
  329. * @return
  330. */
  331. @Override
  332. public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
  333. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  334. String url = sendMsgUrl + accessToken;
  335. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
  336. if (mapping == null) {
  337. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_SCHEDULE_TEMPLATE);
  338. }
  339. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_SCHEDULE_TEMPLATE));
  340. String openId = "";
  341. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  342. ownerAppUserDto.setCommunityId(communityId);
  343. ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
  344. ownerAppUserDto.setUserId(userId);
  345. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  346. if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
  347. throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
  348. }
  349. openId = ownerAppUserDtos.get(0).getOpenId();
  350. JSONObject data = new JSONObject();
  351. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  352. templateMessage.setTemplate_id(templateId);
  353. templateMessage.setTouser(openId);
  354. data.put("thing6", new Content(content.getString("name")));
  355. data.put("phone_number9", new Content(content.getString("tel")));
  356. data.put("time3", new Content(content.getString("time")));
  357. templateMessage.setData(data);
  358. templateMessage.setUrl(content.getString("url"));
  359. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  360. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  361. logger.info("微信模板返回内容:{}", responseEntity);
  362. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  363. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  364. }
  365. /**
  366. * 报修完成给业主通知
  367. *
  368. * @param communityId 小区
  369. * @param userId 用户
  370. * @param content {
  371. * repairObjName,
  372. * staffName,
  373. * time,
  374. * url
  375. * }
  376. * @return
  377. */
  378. @Override
  379. public ResultVo sendFinishRepairOwnerMsg(String communityId, String userId, JSONObject content) {
  380. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  381. String url = sendMsgUrl + accessToken;
  382. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_WORK_ORDER_END_TEMPLATE);
  383. if (mapping == null) {
  384. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_WORK_ORDER_END_TEMPLATE);
  385. }
  386. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_WORK_ORDER_END_TEMPLATE));
  387. String openId = "";
  388. OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
  389. ownerAppUserDto.setCommunityId(communityId);
  390. ownerAppUserDto.setAppType(OwnerAppUserDto.APP_TYPE_WECHAT);
  391. ownerAppUserDto.setUserId(userId);
  392. List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
  393. if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
  394. throw new IllegalArgumentException("业主未绑定,没有获取到微信openId");
  395. }
  396. openId = ownerAppUserDtos.get(0).getOpenId();
  397. JSONObject data = new JSONObject();
  398. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  399. templateMessage.setTemplate_id(templateId);
  400. templateMessage.setTouser(openId);
  401. data.put("thing9", new Content(content.getString("repairObjName")));
  402. data.put("thing10", new Content(content.getString("staffName")));
  403. data.put("time5", new Content(content.getString("time")));
  404. templateMessage.setData(data);
  405. templateMessage.setUrl(content.getString("url"));
  406. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  407. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  408. logger.info("微信模板返回内容:{}", responseEntity);
  409. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  410. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  411. }
  412. @Override
  413. public ResultVo sendReturnRepairMsg(String communityId, String userId, JSONObject content) {
  414. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  415. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  416. staffAppAuthDto.setStaffId(userId);
  417. staffAppAuthDto.setAppType("WECHAT");
  418. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  419. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  420. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  421. }
  422. String openId = staffAppAuthDtos.get(0).getOpenId();
  423. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE);
  424. if (mapping == null) {
  425. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE);
  426. }
  427. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_WORK_ORDER_REMIND_TEMPLATE));
  428. String url = sendMsgUrl + accessToken;
  429. JSONObject data = new JSONObject();
  430. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  431. templateMessage.setTemplate_id(templateId);
  432. templateMessage.setTouser(openId);
  433. data.put("thing8", new Content(content.getString("repairTypeName")));
  434. data.put("thing11", new Content(content.getString("repairObjName")));
  435. data.put("thing10", new Content(content.getString("repairName")));
  436. templateMessage.setData(data);
  437. templateMessage.setUrl(content.getString("url"));
  438. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  439. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  440. logger.info("微信模板返回内容:{}", responseEntity);
  441. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  442. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  443. }
  444. /**
  445. * oa 流程待审批通知
  446. *
  447. * @param communityId 小区
  448. * @param userId 用户
  449. * @param content {
  450. * flowName,
  451. * create_user_name,
  452. * create_time,
  453. * url
  454. * }
  455. * @return
  456. */
  457. @Override
  458. public ResultVo sendOaDistributeMsg(String communityId, String userId, JSONObject content) {
  459. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  460. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  461. staffAppAuthDto.setStaffId(userId);
  462. staffAppAuthDto.setAppType("WECHAT");
  463. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  464. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  465. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  466. }
  467. String openId = staffAppAuthDtos.get(0).getOpenId();
  468. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_TEMPLATE);
  469. if (mapping == null) {
  470. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_TEMPLATE);
  471. }
  472. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_TEMPLATE));
  473. String url = sendMsgUrl + accessToken;
  474. JSONObject data = new JSONObject();
  475. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  476. templateMessage.setTemplate_id(templateId);
  477. templateMessage.setTouser(openId);
  478. data.put("thing2", new Content(content.getString("flowName")));
  479. data.put("thing9", new Content(content.getString("create_user_name")));
  480. data.put("time10", new Content(content.getString("create_time")));
  481. templateMessage.setData(data);
  482. templateMessage.setUrl(content.getString("url"));
  483. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  484. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  485. logger.info("微信模板返回内容:{}", responseEntity);
  486. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  487. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  488. }
  489. /**
  490. * oa 流程通知发起人
  491. *
  492. * @param communityId 小区
  493. * @param userId 用户
  494. * @param content {
  495. * flowName,
  496. * staffName,
  497. * url
  498. * }
  499. * @return
  500. */
  501. @Override
  502. public ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content) {
  503. String accessToken = wechatTemplateImpl.getAccessToken(communityId);
  504. StaffAppAuthDto staffAppAuthDto = new StaffAppAuthDto();
  505. staffAppAuthDto.setStaffId(userId);
  506. staffAppAuthDto.setAppType("WECHAT");
  507. List<StaffAppAuthDto> staffAppAuthDtos = staffAppAuthInnerServiceSMOImpl.queryStaffAppAuths(staffAppAuthDto);
  508. if (staffAppAuthDtos == null || staffAppAuthDtos.size() < 1) {
  509. throw new IllegalArgumentException("员工未认证,没有获取到微信openId");
  510. }
  511. String openId = staffAppAuthDtos.get(0).getOpenId();
  512. Mapping mapping = MappingCache.getMapping(MappingConstant.WECHAT_DOMAIN, SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_FINISH_TEMPLATE);
  513. if (mapping == null) {
  514. throw new IllegalArgumentException("开发者账户编码映射未配置域为=" + MappingConstant.WECHAT_DOMAIN + ",键为=" + SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_FINISH_TEMPLATE);
  515. }
  516. String templateId = wechatTemplateImpl.getTemplateId(communityId, mapping.getValue(), mapping.getName(), templateKeys.get(SPEC_CD_WECHAT_OA_WORKFLOW_AUDIT_FINISH_TEMPLATE));
  517. String url = sendMsgUrl + accessToken;
  518. JSONObject data = new JSONObject();
  519. PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage();
  520. templateMessage.setTemplate_id(templateId);
  521. templateMessage.setTouser(openId);
  522. data.put("thing2", new Content(content.getString("flowName")));
  523. data.put("thing6", new Content(content.getString("staffName")));
  524. templateMessage.setData(data);
  525. templateMessage.setUrl(content.getString("url"));
  526. logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage));
  527. ResponseEntity<String> responseEntity = outRestTemplate.postForEntity(url, JSON.toJSONString(templateMessage), String.class);
  528. logger.info("微信模板返回内容:{}", responseEntity);
  529. JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody());
  530. return new ResultVo(paramOut.getIntValue("errcode"), paramOut.getString("errmsg"));
  531. }
  532. }