| | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.smartor.domain.WeChatSendVo; |
| | | import com.smartor.service.WeChatService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import me.chanjar.weixin.common.exception.WxErrorException; |
| | |
| | | @Value("${appSecret}") |
| | | private String appSecret; |
| | | |
| | | @Autowired |
| | | private WeChatService weChatService; |
| | | |
| | | |
| | | /** |
| | | * 获取模板信息 |
| | |
| | | * @param weChatSendVo |
| | | * @return |
| | | */ |
| | | @ApiOperation("微信公众号信息发送") |
| | | @PostMapping("/sendMessageToFollowers") |
| | | public Boolean sendMessageToFollowers(@RequestBody WeChatSendVo weChatSendVo) { |
| | | WxMpService wxMpService; |
| | | wxMpService = new WxMpServiceImpl(); |
| | | wxMpService.setWxMpConfigStorage(new WxMpInMemoryConfigStorage()); |
| | | WxMpInMemoryConfigStorage wxMpConfigStorage = (WxMpInMemoryConfigStorage) wxMpService.getWxMpConfigStorage(); |
| | | wxMpConfigStorage.setAppId(appid); |
| | | wxMpConfigStorage.setSecret(appSecret); |
| | | try { |
| | | List<String> openIdList = wxMpService.getUserService().userList(null).getOpenids(); |
| | | for (String openId : openIdList) { |
| | | WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(openId).templateId(weChatSendVo.getTemplateId()).url(weChatSendVo.getUrl()).build(); |
| | | for (String key : weChatSendVo.getContent().keySet()) { |
| | | templateMessage.addData(new WxMpTemplateData(key, weChatSendVo.getContent().get(key).toString())); |
| | | } |
| | | wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); |
| | | } |
| | | } catch (WxErrorException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return true; |
| | | } |
| | | // @ApiOperation("微信公众号信息发送") |
| | | // @PostMapping("/sendMessageToFollowers") |
| | | // public AjaxResult sendMessageToFollowers(@RequestBody WeChatSendVo weChatSendVo) { |
| | | // return toAjax(weChatService.sendMessageToFollowers(weChatSendVo)); |
| | | // } |
| | | |
| | | |
| | | /** |