| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.annotation.AddOrgId; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.dx.MessageSend; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.HttpUtil; |
| | | import com.ruoyi.common.utils.RSAPublicKeyExample; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | @AddOrgId |
| | | @PostMapping("/sendYunMasSms") |
| | | public AjaxResult sendYunMasSms(@RequestBody smsVO vo) throws Exception { |
| | | // String yunMasConfig = configService.selectConfigByKey("ls.msg.yunmas",vo.getOrgid()); |
| | | SmsUtils.YunMasConfig yunMasConfig = new SmsUtils.YunMasConfig(); |
| | | String yunMasConfigJson = configService.selectConfigByKey("ls.msg.yunmas", vo.getOrgid()); |
| | | SmsUtils.YunMasConfig yunMasConfig = SmsUtils.YunMasConfig.of(yunMasConfigJson); |
| | | SmsUtils.SmsResult smsResult = SmsUtils.sendYunMasSms(yunMasConfig, vo.getPhone(), vo.getContent()); |
| | | return AjaxResult.success(smsResult); |
| | | } |
| | | |
| | | /** |
| | | * 丽水妇幼 微信消息发送 |
| | | * <p> |
| | | * 外部系统传入患者信息和通知内容,由本系统统一获取 token、解析模板并调用丽水微信 sendMessage 接口。 |
| | | * |
| | | * @param request 微信消息请求 |
| | | * @return 发送结果 |
| | | */ |
| | | @Anonymous |
| | | @ApiOperation(value = "丽水妇幼 微信消息发送", notes = "供丽水市妇幼保健院外部调用") |
| | | @Log(title = "丽水妇幼微信消息发送", businessType = BusinessType.OTHER) |
| | | @PostMapping("/sendChatFuyou") |
| | | public AjaxResult sendChatFuyou(@RequestBody LishuiFuyouWxChatRequest request) { |
| | | if (request == null) { |
| | | return AjaxResult.error("请求参数不能为空"); |
| | | } |
| | | try { |
| | | SmsUtils.LsWxConfig config = SmsUtils.LsWxConfig.defaultLishui(); |
| | | |
| | | SmsUtils.LsWxMessage message = new SmsUtils.LsWxMessage(); |
| | | message.setId(request.getTemplateId()); |
| | | message.setPatientId(request.getPatientId()); |
| | | message.setPatientName(request.getPatientName()); |
| | | message.setIdCard(request.getIdCard()); |
| | | message.setMobile(request.getMobile()); |
| | | message.setMedCardNo(request.getMedCardNo()); |
| | | message.setTitleName(request.getTitleName()); |
| | | message.setContent(request.getContent()); |
| | | message.setUrl(request.getUrl()); |
| | | |
| | | log.info("【丽水妇幼微信】收到外部调用,手机号:{},模板ID:{}", |
| | | request.getMobile(), request.getTemplateId()); |
| | | String resp = SmsUtils.sendChatLs(config, message); |
| | | log.info("【丽水妇幼微信】外部调用结果:{}", resp); |
| | | |
| | | JSONObject result; |
| | | try { |
| | | result = JSON.parseObject(resp); |
| | | } catch (Exception e) { |
| | | log.error("【丽水妇幼微信】第三方响应不是合法JSON:{}", resp, e); |
| | | return AjaxResult.error("丽水妇幼微信发送失败:第三方响应异常", resp); |
| | | } |
| | | if (result == null) { |
| | | return AjaxResult.error("丽水妇幼微信发送失败:第三方响应为空", resp); |
| | | } |
| | | if (result.getIntValue("code") != 0) { |
| | | String msg = result.getString("msg"); |
| | | return AjaxResult.error("丽水妇幼微信发送失败:" |
| | | + (StringUtils.isEmpty(msg) ? "第三方接口返回失败" : msg), result); |
| | | } |
| | | return AjaxResult.success("发送成功", result); |
| | | } catch (Exception e) { |
| | | log.error("【丽水妇幼微信】外部调用异常,手机号:{}", request.getMobile(), e); |
| | | return AjaxResult.error("丽水妇幼微信发送异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |