diff --git a/pigx-common/pigx-common-bom/pom.xml b/pigx-common/pigx-common-bom/pom.xml
index a9642b357..8232202fc 100644
--- a/pigx-common/pigx-common-bom/pom.xml
+++ b/pigx-common/pigx-common-bom/pom.xml
@@ -23,7 +23,7 @@
1.1.21
8.0.19
1.5.22
- 3.6.0
+ 3.7.0
1.2.0
1.2.67
3.0.52.ALL
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/MsgTypeEnum.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/MsgTypeEnum.java
new file mode 100644
index 000000000..5a2c51fb5
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/MsgTypeEnum.java
@@ -0,0 +1,35 @@
+package com.pig4cloud.pigx.mp.constant;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lengleng
+ * @date 2020/4/25
+ *
+ * 消息类型
+ */
+@Getter
+@AllArgsConstructor
+public enum MsgTypeEnum {
+
+ /**
+ * 用户发给公众号
+ */
+ USER2MP("1", "用户发给公众号"),
+
+ /**
+ * 公众号发给用户
+ */
+ MP2USER("2", "公众号发给用户");
+
+ /***
+ * 类型
+ */
+ private String type;
+
+ /**
+ * 描述
+ */
+ private String desc;
+}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyMateEnum.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyMateEnum.java
new file mode 100644
index 000000000..d5b7d39db
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyMateEnum.java
@@ -0,0 +1,36 @@
+package com.pig4cloud.pigx.mp.constant;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lengleng
+ * @date 2020/4/25
+ *
+ * 匹配类型
+ */
+@Getter
+@AllArgsConstructor
+public enum ReplyMateEnum {
+
+ /**
+ * 完全匹配
+ */
+ ALL("1", "完全匹配"),
+
+ /**
+ * 半匹配
+ */
+ LIKE("2", "半匹配");
+
+
+ /***
+ * 类型
+ */
+ private String type;
+
+ /**
+ * 描述
+ */
+ private String desc;
+}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyTypeEnum.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyTypeEnum.java
new file mode 100644
index 000000000..ad3d92cca
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/ReplyTypeEnum.java
@@ -0,0 +1,56 @@
+package com.pig4cloud.pigx.mp.constant;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lengleng
+ * @date 2020/4/25
+ *
+ * 回复类型
+ */
+@Getter
+@AllArgsConstructor
+public enum ReplyTypeEnum {
+
+ /**
+ * 关注自动回复
+ */
+ ATTENTION("1", "关注时回复"),
+
+ /**
+ * 用户消息回复
+ */
+ MSG("2", "消息回复"),
+
+ /**
+ * 关键字回复
+ */
+ KEYWORD("3", "关键词回复");
+
+ /***
+ * 类型
+ */
+ private String type;
+
+ /**
+ * 描述
+ */
+ private String desc;
+
+
+ /**
+ * 根据 type 查找枚举
+ *
+ * @param type
+ * @return
+ */
+ public static ReplyTypeEnum getEnumByType(String type) {
+ for (ReplyTypeEnum value : ReplyTypeEnum.values()) {
+ if (value.getType().equals(type)) {
+ return value;
+ }
+ }
+ return null;
+ }
+}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/SubStatusEnum.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/SubStatusEnum.java
new file mode 100644
index 000000000..036f3d5dc
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/constant/SubStatusEnum.java
@@ -0,0 +1,35 @@
+package com.pig4cloud.pigx.mp.constant;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lengleng
+ * @date 2020/4/26
+ *
+ * 公众号订阅状态
+ */
+@Getter
+@AllArgsConstructor
+public enum SubStatusEnum {
+ /**
+ * 已关注
+ */
+ SUBED("1", "已关注"),
+
+ /**
+ * 未关注
+ */
+ UNSUB("0", "关注");
+
+
+ /***
+ * 类型
+ */
+ private String type;
+
+ /**
+ * 描述
+ */
+ private String desc;
+}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxAutoReplyController.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxAutoReplyController.java
new file mode 100644
index 000000000..41d7749f1
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxAutoReplyController.java
@@ -0,0 +1,123 @@
+package com.pig4cloud.pigx.mp.controller;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.mp.constant.ReplyTypeEnum;
+import com.pig4cloud.pigx.mp.entity.WxAutoReply;
+import com.pig4cloud.pigx.mp.service.WxAutoReplyService;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 消息自动回复
+ *
+ * @author JL
+ * @date 2019-04-18 15:40:39
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/wxautoreply")
+public class WxAutoReplyController {
+
+ private final WxAutoReplyService wxAutoReplyService;
+
+ /**
+ * 分页查询
+ *
+ * @param page 分页对象
+ * @param wxAutoReply 消息自动回复
+ * @return
+ */
+ @GetMapping("/page")
+ public R getWxAutoReplyPage(Page page, WxAutoReply wxAutoReply) {
+ return R.ok(wxAutoReplyService.page(page, Wrappers.query(wxAutoReply)));
+ }
+
+
+ /**
+ * 通过id查询消息自动回复
+ *
+ * @param id id
+ * @return R
+ */
+ @GetMapping("/{id}")
+ public R getById(@PathVariable("id") String id) {
+ return R.ok(wxAutoReplyService.getById(id));
+ }
+
+ /**
+ * 新增消息自动回复
+ *
+ * @param wxAutoReply 消息自动回复
+ * @return R
+ */
+ @PostMapping
+ public R save(@RequestBody WxAutoReply wxAutoReply) {
+ this.jude(wxAutoReply);
+ return R.ok(wxAutoReplyService.save(wxAutoReply));
+ }
+
+ /**
+ * 修改消息自动回复
+ *
+ * @param wxAutoReply 消息自动回复
+ * @return R
+ */
+ @PutMapping
+ public R updateById(@RequestBody WxAutoReply wxAutoReply) {
+ this.jude(wxAutoReply);
+ return R.ok(wxAutoReplyService.updateById(wxAutoReply));
+ }
+
+ /**
+ * 通过id删除消息自动回复
+ *
+ * @param id id
+ * @return R
+ */
+ @DeleteMapping("/{id}")
+ public R removeById(@PathVariable String id) {
+ return R.ok(wxAutoReplyService.removeById(id));
+ }
+
+ /**
+ * //校验参数
+ *
+ * @param wxAutoReply
+ */
+ public void jude(WxAutoReply wxAutoReply) {
+ if (ReplyTypeEnum.MSG.getType().equals(wxAutoReply.getType())) {
+ Wrapper queryWrapper = Wrappers.lambdaQuery()
+ .eq(WxAutoReply::getReqType, wxAutoReply.getReqType());
+ List list = wxAutoReplyService.list(queryWrapper);
+ if (wxAutoReply.getId() != null) {
+ if (list != null && list.size() == 1) {
+ if (!list.get(0).getId().equals(wxAutoReply.getId())) {
+ throw new RuntimeException("请求消息类型重复");
+ }
+ }
+ if (list != null && list.size() > 1) {
+ throw new RuntimeException("请求消息类型重复");
+ }
+ }
+ }
+ if (ReplyTypeEnum.KEYWORD.getType().equals(wxAutoReply.getType())) {
+ Wrapper queryWrapper = Wrappers.lambdaQuery()
+ .eq(WxAutoReply::getReqKey, wxAutoReply.getReqKey())
+ .eq(WxAutoReply::getRepType, wxAutoReply.getRepMate());
+ List list = wxAutoReplyService.list(queryWrapper);
+ if (list != null && list.size() == 1) {
+ if (!list.get(0).getId().equals(wxAutoReply.getId())) {
+ throw new RuntimeException("关键词重复");
+ }
+ }
+ if (list != null && list.size() > 1) {
+ throw new RuntimeException("关键词重复");
+ }
+ }
+ }
+}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java
index e099a586c..43187605a 100755
--- a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java
@@ -16,17 +16,32 @@
*/
package com.pig4cloud.pigx.mp.controller;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
-import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
-import com.pig4cloud.pigx.common.log.annotation.SysLog;
-import com.pig4cloud.pigx.mp.entity.WxFansMsg;
-import com.pig4cloud.pigx.mp.service.WxFansMsgService;
+import com.pig4cloud.pigx.mp.config.WxMpConfiguration;
+import com.pig4cloud.pigx.mp.constant.MsgTypeEnum;
+import com.pig4cloud.pigx.mp.entity.WxAccountFans;
+import com.pig4cloud.pigx.mp.entity.WxMsg;
+import com.pig4cloud.pigx.mp.service.WxAccountFansService;
+import com.pig4cloud.pigx.mp.service.WxMsgService;
import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpKefuService;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* 微信粉丝消息管理
@@ -34,77 +49,154 @@ import org.springframework.web.bind.annotation.*;
* @author lengleng
* @date 2019-03-27 20:45:27
*/
+@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxfansmsg")
public class WxFansMsgController {
- private final WxFansMsgService wxFansMsgService;
+ private final WxAccountFansService wxAccountFansService;
+ private final WxMsgService wxMsgService;
/**
* 分页查询
*
- * @param page 分页对象
- * @param wxFansMsg 消息
- * @return
+ * @param page 分页对象
+ * @param msg 查询条件
*/
@GetMapping("/page")
- public R getWxFansMsgPage(Page page, WxFansMsg wxFansMsg) {
- wxFansMsg.setTenantId(TenantContextHolder.getTenantId());
- return R.ok(wxFansMsgService.page(page, Wrappers.query(wxFansMsg)));
+ public R getWxMsgPage(Page page, WxMsg msg) {
+ return R.ok(wxMsgService.page(page, Wrappers.query(msg)));
}
-
/**
- * 通过id查询消息
+ * 通过id查询微信消息
*
* @param id id
* @return R
*/
@GetMapping("/{id}")
public R getById(@PathVariable("id") Integer id) {
- return R.ok(wxFansMsgService.getById(id));
+ return R.ok(wxMsgService.getById(id));
}
/**
- * 新增消息
+ * 新增微信消息
*
- * @param wxFansMsg 消息
+ * @param wxMsg 微信消息
* @return R
*/
- @SysLog("新增消息")
@PostMapping
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_add')")
- public R save(@RequestBody WxFansMsg wxFansMsg) {
- wxFansMsg.setTenantId(TenantContextHolder.getTenantId());
- return R.ok(wxFansMsgService.save(wxFansMsg));
+ public R save(@RequestBody WxMsg wxMsg) {
+ try {
+ WxAccountFans wxUser = wxAccountFansService.getById(wxMsg.getWxUserId());
+ //入库
+ wxMsg.setNickName(wxUser.getNickname());
+ wxMsg.setHeadimgUrl(wxUser.getHeadimgUrl());
+ wxMsg.setCreateTime(LocalDateTime.now());
+ wxMsg.setType(MsgTypeEnum.MP2USER.getType());
+ WxMpKefuMessage wxMpKefuMessage = null;
+ if (WxConsts.KefuMsgType.TEXT.equals(wxMsg.getRepType())) {
+ wxMsg.setRepContent(wxMsg.getRepContent());
+ wxMpKefuMessage = WxMpKefuMessage.TEXT().build();
+ wxMpKefuMessage.setContent(wxMsg.getRepContent());
+ }
+ if (WxConsts.KefuMsgType.IMAGE.equals(wxMsg.getRepType())) {//图片
+ wxMsg.setRepName(wxMsg.getRepName());
+ wxMsg.setRepUrl(wxMsg.getRepUrl());
+ wxMsg.setRepMediaId(wxMsg.getRepMediaId());
+ wxMpKefuMessage = WxMpKefuMessage.IMAGE().build();
+ wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
+ }
+ if (WxConsts.KefuMsgType.VOICE.equals(wxMsg.getRepType())) {
+ wxMsg.setRepName(wxMsg.getRepName());
+ wxMsg.setRepUrl(wxMsg.getRepUrl());
+ wxMsg.setRepMediaId(wxMsg.getRepMediaId());
+ wxMpKefuMessage = WxMpKefuMessage.VOICE().build();
+ wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
+ }
+ if (WxConsts.KefuMsgType.VIDEO.equals(wxMsg.getRepType())) {
+ wxMsg.setRepName(wxMsg.getRepName());
+ wxMsg.setRepDesc(wxMsg.getRepDesc());
+ wxMsg.setRepUrl(wxMsg.getRepUrl());
+ wxMsg.setRepMediaId(wxMsg.getRepMediaId());
+ wxMpKefuMessage = WxMpKefuMessage.VIDEO().build();
+ wxMpKefuMessage.setMediaId(wxMsg.getRepMediaId());
+ wxMpKefuMessage.setTitle(wxMsg.getRepName());
+ wxMpKefuMessage.setDescription(wxMsg.getRepDesc());
+ }
+ if (WxConsts.KefuMsgType.MUSIC.equals(wxMsg.getRepType())) {
+ wxMsg.setRepName(wxMsg.getRepName());
+ wxMsg.setRepDesc(wxMsg.getRepDesc());
+ wxMsg.setRepUrl(wxMsg.getRepUrl());
+ wxMsg.setRepHqUrl(wxMsg.getRepHqUrl());
+ wxMpKefuMessage = WxMpKefuMessage.MUSIC().build();
+ wxMpKefuMessage.setTitle(wxMsg.getRepName());
+ wxMpKefuMessage.setDescription(wxMsg.getRepDesc());
+ wxMpKefuMessage.setMusicUrl(wxMsg.getRepUrl());
+ wxMpKefuMessage.setHqMusicUrl(wxMsg.getRepHqUrl());
+ wxMpKefuMessage.setThumbMediaId(wxMsg.getRepThumbMediaId());
+ }
+ if (WxConsts.KefuMsgType.NEWS.equals(wxMsg.getRepType())) {
+ List list = new ArrayList<>();
+ JSONArray jSONArray = JSONUtil.parseObj(wxMsg.getContent()).getJSONArray("articles");
+ WxMpKefuMessage.WxArticle t;
+ for (Object object : jSONArray) {
+ JSONObject jSONObject = JSONUtil.parseObj(JSONUtil.toJsonStr(object));
+ t = new WxMpKefuMessage.WxArticle();
+ t.setTitle(jSONObject.getStr("title"));
+ t.setDescription(jSONObject.getStr("digest"));
+ t.setPicUrl(jSONObject.getStr("thumbUrl"));
+ t.setUrl(jSONObject.getStr("url"));
+ list.add(t);
+ }
+ wxMsg.setRepName(wxMsg.getRepName());
+ wxMsg.setRepDesc(wxMsg.getRepDesc());
+ wxMsg.setRepUrl(wxMsg.getRepUrl());
+ wxMsg.setRepMediaId(wxMsg.getRepMediaId());
+ wxMsg.setContent(wxMsg.getContent());
+ wxMpKefuMessage = WxMpKefuMessage.NEWS().build();
+ wxMpKefuMessage.setArticles(list);
+ }
+ if (wxMpKefuMessage != null) {
+ WxMpService wxMpService = WxMpConfiguration.getMpServices().get(wxMsg.getAppId());
+ WxMpKefuService wxMpKefuService = wxMpService.getKefuService();
+ wxMpKefuMessage.setToUser(wxUser.getOpenid());
+ wxMpKefuService.sendKefuMessage(wxMpKefuMessage);
+ wxMsgService.save(wxMsg);
+ return R.ok(wxMsg);
+ } else {
+ return R.failed("非法消息类型");
+ }
+ } catch (WxErrorException e) {
+ e.printStackTrace();
+ log.error("新增微信消息失败" + e.getMessage());
+ return R.failed(e.getMessage());
+ }
}
/**
- * 修改消息
+ * 修改微信消息
*
- * @param wxFansMsg 消息
+ * @param wxMsg 微信消息
* @return R
*/
- @SysLog("修改消息")
@PutMapping
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_edit')")
- public R updateById(@RequestBody WxFansMsg wxFansMsg) {
- wxFansMsg.setTenantId(TenantContextHolder.getTenantId());
- return R.ok(wxFansMsgService.updateById(wxFansMsg));
+ @PreAuthorize("@ss.hasPermi('wxmp:wxmsg:edit')")
+ public R updateById(@RequestBody WxMsg wxMsg) {
+ return R.ok(wxMsgService.updateById(wxMsg));
}
/**
- * 通过id删除消息
+ * 通过id删除微信消息
*
* @param id id
* @return R
*/
- @SysLog("删除消息")
@DeleteMapping("/{id}")
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_del')")
- public R removeById(@PathVariable Integer id) {
- return R.ok(wxFansMsgService.removeById(id));
+ @PreAuthorize("@ss.hasPermi('wxmp:wxmsg:del')")
+ public R removeById(@PathVariable String id) {
+ return R.ok(wxMsgService.removeById(id));
}
}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java
deleted file mode 100755
index 3a1d41acc..000000000
--- a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2018-2025, lengleng All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * Neither the name of the pig4cloud.com developer nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * Author: lengleng (wangiegie@gmail.com)
- */
-package com.pig4cloud.pigx.mp.controller;
-
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.pig4cloud.pigx.common.core.util.R;
-import com.pig4cloud.pigx.common.log.annotation.SysLog;
-import com.pig4cloud.pigx.mp.entity.WxFansMsgRes;
-import com.pig4cloud.pigx.mp.service.WxFansMsgResService;
-import lombok.AllArgsConstructor;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.*;
-
-
-/**
- * 微信粉丝消息回复管理
- *
- * @author lengleng
- * @date 2019-03-27 20:45:48
- */
-@RestController
-@AllArgsConstructor
-@RequestMapping("/wxfansmsgres")
-public class WxFansMsgResController {
-
- private final WxFansMsgResService wxFansMsgResService;
-
- /**
- * 分页查询
- *
- * @param page 分页对象
- * @param wxFansMsgRes 回复
- * @return
- */
- @GetMapping("/page")
- public R getWxFansMsgResPage(Page page, WxFansMsgRes wxFansMsgRes) {
- return R.ok(wxFansMsgResService.page(page, Wrappers.query(wxFansMsgRes)));
- }
-
-
- /**
- * 通过id查询回复
- *
- * @param id id
- * @return R
- */
- @GetMapping("/{id}")
- public R getById(@PathVariable("id") Integer id) {
- return R.ok(wxFansMsgResService.getById(id));
- }
-
- /**
- * 新增回复
- *
- * @param wxFansMsgRes 回复
- * @return R
- */
- @SysLog("新增回复")
- @PostMapping
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_add')")
- public R save(@RequestBody WxFansMsgRes wxFansMsgRes) {
- return wxFansMsgResService.saveAndSend(wxFansMsgRes);
- }
-
- /**
- * 修改回复
- *
- * @param wxFansMsgRes 回复
- * @return R
- */
- @SysLog("修改回复")
- @PutMapping
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_edit')")
- public R updateById(@RequestBody WxFansMsgRes wxFansMsgRes) {
- return R.ok(wxFansMsgResService.updateById(wxFansMsgRes));
- }
-
- /**
- * 通过id删除回复
- *
- * @param id id
- * @return R
- */
- @SysLog("删除回复")
- @DeleteMapping("/{id}")
- @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_del')")
- public R removeById(@PathVariable Integer id) {
- return R.ok(wxFansMsgResService.removeById(id));
- }
-
-}
diff --git a/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxMaterialController.java b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxMaterialController.java
new file mode 100644
index 000000000..fc779271f
--- /dev/null
+++ b/pigx-visual/pigx-mp-platform/src/main/java/com/pig4cloud/pigx/mp/controller/WxMaterialController.java
@@ -0,0 +1,288 @@
+package com.pig4cloud.pigx.mp.controller;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.mp.config.WxMpConfiguration;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.api.WxConsts;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpMaterialService;
+import me.chanjar.weixin.mp.api.WxMpService;
+import me.chanjar.weixin.mp.bean.material.*;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 微信素材
+ *
+ * @author JL
+ * @date 2019-03-23 21:26:35
+ */
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/wxmaterial")
+public class WxMaterialController {
+
+ /**
+ * 上传非图文微信素材
+ *
+ * @param mulFile
+ * @param mediaType
+ * @return
+ */
+ @PostMapping("/materialFileUpload")
+ public R materialFileUpload(@RequestParam("file") MultipartFile mulFile,
+ @RequestParam String appId,
+ @RequestParam("title") String title,
+ @RequestParam("introduction") String introduction,
+ @RequestParam("mediaType") String mediaType) {
+ try {
+ WxMpMaterial material = new WxMpMaterial();
+ material.setName(mulFile.getOriginalFilename());
+ if (WxConsts.MediaFileType.VIDEO.equals(mediaType)) {
+ material.setVideoTitle(title);
+ material.setVideoIntroduction(introduction);
+ }
+
+ File file = FileUtil.newFile(FileUtil.getTmpDirPath() + mulFile.getOriginalFilename());
+ mulFile.transferTo(file);
+ material.setFile(file);
+
+ WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId);
+ WxMpMaterialService wxMpMaterialService = wxMpService.getMaterialService();
+ WxMpMaterialUploadResult wxMpMaterialUploadResult = wxMpMaterialService.materialFileUpload(mediaType, material);
+ WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem wxMpMaterialFileBatchGetResult = new WxMpMaterialFileBatchGetResult.WxMaterialFileBatchGetNewsItem();
+ wxMpMaterialFileBatchGetResult.setName(file.getName());
+ wxMpMaterialFileBatchGetResult.setMediaId(wxMpMaterialUploadResult.getMediaId());
+ wxMpMaterialFileBatchGetResult.setUrl(wxMpMaterialUploadResult.getUrl());
+ FileUtil.del(file);
+ return R.ok(wxMpMaterialFileBatchGetResult);
+ } catch (WxErrorException e) {
+ log.warn("上传非图文微信素材失败: {}", e.getLocalizedMessage());
+ return R.failed(e.getLocalizedMessage());
+ } catch (Exception e) {
+ log.error("上传失败", e);
+ return R.failed(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * 新增图文消息
+ *
+ * @param data
+ * @return
+ */
+ @PostMapping("/materialNews")
+ public R materialNewsUpload(@RequestBody JSONObject data) {
+ try {
+ JSONArray jSONArray = data.getJSONArray("articles");
+ List articles = jSONArray.toList(WxMpMaterialNews.WxMpMaterialNewsArticle.class);
+ WxMpMaterialNews news = new WxMpMaterialNews();
+ news.setArticles(articles);
+
+ String appId = data.getStr("appId");
+ WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId);
+ WxMpMaterialService wxMpMaterialService = wxMpService.getMaterialService();
+ WxMpMaterialUploadResult wxMpMaterialUploadResult = wxMpMaterialService.materialNewsUpload(news);
+ return R.ok(wxMpMaterialUploadResult);
+ } catch (WxErrorException e) {
+ log.warn("新增图文失败: {}", e.getMessage());
+ return R.failed(e.getMessage());
+ } catch (Exception e) {
+ log.error("新增图文失败", e);
+ return R.failed(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * 修改图文消息
+ *
+ * @param data
+ * @return
+ */
+ @PutMapping("/materialNews")
+ public R materialNewsUpdate(@RequestBody JSONObject data) {
+ try {
+ String mediaId = data.getStr("mediaId");
+ JSONArray jSONArray = data.getJSONArray("articles");
+ List articles = jSONArray.toList(WxMpMaterialNews.WxMpMaterialNewsArticle.class);
+ String appId = data.getStr("appId");
+ WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId);
+ WxMpMaterialService wxMpMaterialService = wxMpService.getMaterialService();
+ WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate = new WxMpMaterialArticleUpdate();
+ wxMpMaterialArticleUpdate.setMediaId(mediaId);
+ int index = 0;
+ for (WxMpMaterialNews.WxMpMaterialNewsArticle article : articles) {
+ wxMpMaterialArticleUpdate.setIndex(index);
+ wxMpMaterialArticleUpdate.setArticles(article);
+ wxMpMaterialService.materialNewsUpdate(wxMpMaterialArticleUpdate);
+ index++;
+ }
+ return R.ok();
+ } catch (WxErrorException e) {
+ log.warn("修改图文失败:{}", e.getLocalizedMessage());
+ return R.failed(e.getLocalizedMessage());
+ } catch (Exception e) {
+ log.error("修改图文失败", e);
+ return R.failed(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * 上传图文消息内的图片获取URL
+ *
+ * @param mulFile
+ * @return
+ */
+ @PostMapping("/newsImgUpload")
+ public String newsImgUpload(@RequestParam("file") MultipartFile mulFile, @RequestParam String appId) throws Exception {
+ File file = FileUtil.createTempFile(FileUtil.getTmpDir());
+ mulFile.transferTo(file);
+ WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId);
+ WxMpMaterialService wxMpMaterialService = wxMpService.getMaterialService();
+ WxMediaImgUploadResult wxMediaImgUploadResult = wxMpMaterialService.mediaImgUpload(file);
+ Map