From f4fa687c783a59f607899ca76edae1ca18138aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Wed, 27 Mar 2019 22:06:20 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E7=89=B9=E6=80=A7=E3=80=82=20=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E3=80=81=E7=B2=89=E4=B8=9D=E3=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF=20=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/config/pigx-mp-manager-dev.yml | 2 + .../pigx/mp/config/WxMpContextHolder.java | 55 ++++++++ .../mp/controller/WxAccountController.java | 10 ++ .../controller/WxAccountFansController.java | 11 ++ .../mp/controller/WxFansMsgController.java | 106 +++++++++++++++ .../mp/controller/WxFansMsgResController.java | 106 +++++++++++++++ .../pigx/mp/controller/WxMenuController.java | 106 +++++++++++++++ .../mp/controller/WxPortalController.java | 4 + .../pig4cloud/pigx/mp/entity/WxAccount.java | 4 + .../pigx/mp/entity/WxAccountFans.java | 5 + .../pig4cloud/pigx/mp/entity/WxFansMsg.java | 125 ++++++++++++++++++ .../pigx/mp/entity/WxFansMsgRes.java | 69 ++++++++++ .../com/pig4cloud/pigx/mp/entity/WxMenu.java | 93 +++++++++++++ .../pig4cloud/pigx/mp/handler/LogHandler.java | 42 +++++- .../pigx/mp/mapper/WxFansMsgMapper.java | 30 +++++ .../pigx/mp/mapper/WxFansMsgResMapper.java | 30 +++++ .../pigx/mp/mapper/WxMenuMapper.java | 30 +++++ .../pigx/mp/service/WxAccountFansService.java | 7 + .../pigx/mp/service/WxFansMsgResService.java | 30 +++++ .../pigx/mp/service/WxFansMsgService.java | 30 +++++ .../pigx/mp/service/WxMenuService.java | 30 +++++ .../impl/WxAccountFansServiceImpl.java | 109 ++++++++++++++- .../service/impl/WxFansMsgResServiceImpl.java | 34 +++++ .../mp/service/impl/WxFansMsgServiceImpl.java | 34 +++++ .../mp/service/impl/WxMenuServiceImpl.java | 34 +++++ .../resources/mapper/WxAccountFansMapper.xml | 1 + .../main/resources/mapper/WxFansMsgMapper.xml | 46 +++++++ .../resources/mapper/WxFansMsgResMapper.xml | 35 +++++ .../main/resources/mapper/WxMenuMapper.xml | 41 ++++++ 29 files changed, 1254 insertions(+), 5 deletions(-) create mode 100644 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/config/WxMpContextHolder.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxMenuController.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsg.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsgRes.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxMenu.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgMapper.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgResMapper.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxMenuMapper.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgResService.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgService.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxMenuService.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgResServiceImpl.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgServiceImpl.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxMenuServiceImpl.java create mode 100755 pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgMapper.xml create mode 100755 pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgResMapper.xml create mode 100755 pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxMenuMapper.xml diff --git a/pigx-config/src/main/resources/config/pigx-mp-manager-dev.yml b/pigx-config/src/main/resources/config/pigx-mp-manager-dev.yml index d25267789..49280daac 100644 --- a/pigx-config/src/main/resources/config/pigx-mp-manager-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-mp-manager-dev.yml @@ -18,6 +18,8 @@ spring: username: root password: root url: jdbc:mysql://pigx-mysql:3306/coffeewx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8 + hikari: + connection-init-sql: SET NAMES utf8mb4 resources: static-locations: classpath:/static/,classpath:/views/ diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/config/WxMpContextHolder.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/config/WxMpContextHolder.java new file mode 100644 index 000000000..9f73e4a01 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/config/WxMpContextHolder.java @@ -0,0 +1,55 @@ +/* + * 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.config; + +import com.alibaba.ttl.TransmittableThreadLocal; +import lombok.experimental.UtilityClass; + +/** + * @author lengleng + * @date 2019/03/27 + * 微信上下文工具类 + */ +@UtilityClass +public class WxMpContextHolder { + + private final ThreadLocal THREAD_LOCAL_APPID = new TransmittableThreadLocal<>(); + + + /** + * TTL 设置appId + * + * @param appId + */ + public void setAppId(String appId) { + THREAD_LOCAL_APPID.set(appId); + } + + /** + * 获取TTL中的appId + * + * @return + */ + public String getAppId() { + return THREAD_LOCAL_APPID.get(); + } + + public void clear() { + THREAD_LOCAL_APPID.remove(); + } +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountController.java index 322d0dc9b..e7fb20a8a 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountController.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountController.java @@ -123,4 +123,14 @@ public class WxAccountController { return wxAccountService.generateQr(appId); } + /** + * 获取公众号列表 + * + * @return + */ + @GetMapping("/list") + public R list() { + return new R<>(wxAccountService.list()); + } + } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountFansController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountFansController.java index 550ca3d80..5ec3ec169 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountFansController.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxAccountFansController.java @@ -103,4 +103,15 @@ public class WxAccountFansController { return new R<>(wxAccountFansService.removeById(id)); } + /** + * 同步粉丝 + * + * @param appId + * @return + */ + @PostMapping("/sync/{appId}") + public R sync(@PathVariable String appId) { + return new R(wxAccountFansService.syncAccountFans(appId)); + } + } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java new file mode 100755 index 000000000..cb5081911 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgController.java @@ -0,0 +1,106 @@ +/* + * 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.WxFansMsg; +import com.pig4cloud.pigx.mp.service.WxFansMsgService; +import lombok.AllArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + + +/** + * 微信粉丝消息管理 + * + * @author lengleng + * @date 2019-03-27 20:45:27 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/wxfansmsg") +public class WxFansMsgController { + + private final WxFansMsgService wxFansMsgService; + + /** + * 分页查询 + * + * @param page 分页对象 + * @param wxFansMsg lengleng + * @return + */ + @GetMapping("/page") + public R getWxFansMsgPage(Page page, WxFansMsg wxFansMsg) { + return new R<>(wxFansMsgService.page(page, Wrappers.query(wxFansMsg))); + } + + + /** + * 通过id查询lengleng + * + * @param id id + * @return R + */ + @GetMapping("/{id}") + public R getById(@PathVariable("id") Integer id) { + return new R<>(wxFansMsgService.getById(id)); + } + + /** + * 新增lengleng + * + * @param wxFansMsg lengleng + * @return R + */ + @SysLog("新增lengleng") + @PostMapping + @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_add')") + public R save(@RequestBody WxFansMsg wxFansMsg) { + return new R<>(wxFansMsgService.save(wxFansMsg)); + } + + /** + * 修改lengleng + * + * @param wxFansMsg lengleng + * @return R + */ + @SysLog("修改lengleng") + @PutMapping + @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_edit')") + public R updateById(@RequestBody WxFansMsg wxFansMsg) { + return new R<>(wxFansMsgService.updateById(wxFansMsg)); + } + + /** + * 通过id删除lengleng + * + * @param id id + * @return R + */ + @SysLog("删除lengleng") + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('mp_wxfansmsg_del')") + public R removeById(@PathVariable Integer id) { + return new R<>(wxFansMsgService.removeById(id)); + } + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java new file mode 100755 index 000000000..a7d3a14bb --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxFansMsgResController.java @@ -0,0 +1,106 @@ +/* + * 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 lengleng + * @return + */ + @GetMapping("/page") + public R getWxFansMsgResPage(Page page, WxFansMsgRes wxFansMsgRes) { + return new R<>(wxFansMsgResService.page(page, Wrappers.query(wxFansMsgRes))); + } + + + /** + * 通过id查询lengleng + * + * @param id id + * @return R + */ + @GetMapping("/{id}") + public R getById(@PathVariable("id") Integer id) { + return new R<>(wxFansMsgResService.getById(id)); + } + + /** + * 新增lengleng + * + * @param wxFansMsgRes lengleng + * @return R + */ + @SysLog("新增lengleng") + @PostMapping + @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_add')") + public R save(@RequestBody WxFansMsgRes wxFansMsgRes) { + return new R<>(wxFansMsgResService.save(wxFansMsgRes)); + } + + /** + * 修改lengleng + * + * @param wxFansMsgRes lengleng + * @return R + */ + @SysLog("修改lengleng") + @PutMapping + @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_edit')") + public R updateById(@RequestBody WxFansMsgRes wxFansMsgRes) { + return new R<>(wxFansMsgResService.updateById(wxFansMsgRes)); + } + + /** + * 通过id删除lengleng + * + * @param id id + * @return R + */ + @SysLog("删除lengleng") + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('mp_wxfansmsgres_del')") + public R removeById(@PathVariable Integer id) { + return new R<>(wxFansMsgResService.removeById(id)); + } + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxMenuController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxMenuController.java new file mode 100755 index 000000000..80f5abd02 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxMenuController.java @@ -0,0 +1,106 @@ +/* + * 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.WxMenu; +import com.pig4cloud.pigx.mp.service.WxMenuService; +import lombok.AllArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + + +/** + * 微信菜单管理 + * + * @author lengleng + * @date 2019-03-27 20:45:18 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/wxmenu") +public class WxMenuController { + + private final WxMenuService wxMenuService; + + /** + * 分页查询 + * + * @param page 分页对象 + * @param wxMenu lengleng + * @return + */ + @GetMapping("/page") + public R getWxMenuPage(Page page, WxMenu wxMenu) { + return new R<>(wxMenuService.page(page, Wrappers.query(wxMenu))); + } + + + /** + * 通过id查询lengleng + * + * @param id id + * @return R + */ + @GetMapping("/{id}") + public R getById(@PathVariable("id") Integer id) { + return new R<>(wxMenuService.getById(id)); + } + + /** + * 新增lengleng + * + * @param wxMenu lengleng + * @return R + */ + @SysLog("新增lengleng") + @PostMapping + @PreAuthorize("@pms.hasPermission('mp_wxmenu_add')") + public R save(@RequestBody WxMenu wxMenu) { + return new R<>(wxMenuService.save(wxMenu)); + } + + /** + * 修改lengleng + * + * @param wxMenu lengleng + * @return R + */ + @SysLog("修改lengleng") + @PutMapping + @PreAuthorize("@pms.hasPermission('mp_wxmenu_edit')") + public R updateById(@RequestBody WxMenu wxMenu) { + return new R<>(wxMenuService.updateById(wxMenu)); + } + + /** + * 通过id删除lengleng + * + * @param id id + * @return R + */ + @SysLog("删除lengleng") + @DeleteMapping("/{id}") + @PreAuthorize("@pms.hasPermission('mp_wxmenu_del')") + public R removeById(@PathVariable Integer id) { + return new R<>(wxMenuService.removeById(id)); + } + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxPortalController.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxPortalController.java index a9afd103c..583f530d5 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxPortalController.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/controller/WxPortalController.java @@ -3,6 +3,7 @@ package com.pig4cloud.pigx.mp.controller; import cn.hutool.core.util.StrUtil; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import com.pig4cloud.pigx.mp.config.WxMpConfiguration; +import com.pig4cloud.pigx.mp.config.WxMpContextHolder; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; @@ -78,6 +79,8 @@ public class WxPortalController { @RequestParam("openid") String openid, @RequestParam(name = "encrypt_type", required = false) String encType, @RequestParam(name = "msg_signature", required = false) String msgSignature) { + + WxMpContextHolder.setAppId(appId); final WxMpService wxService = WxMpConfiguration.getMpServices().get(appId); log.info("接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}]," @@ -113,6 +116,7 @@ public class WxPortalController { } log.debug("组装回复信息:{}", out); + WxMpContextHolder.clear(); return out; } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccount.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccount.java index 76623d276..76b94ca73 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccount.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccount.java @@ -89,4 +89,8 @@ public class WxAccount extends Model { @TableLogic private String delFlag; + /** + * 租户 + */ + private Integer tenantId; } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccountFans.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccountFans.java index a2ec8af50..a10a8f8f8 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccountFans.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxAccountFans.java @@ -94,6 +94,11 @@ public class WxAccountFans extends Model { * 微信公众号appid */ private String wxAccountAppid; + + /** + * 微信公众号名 + */ + private String wxAccountName; /** * 创建时间 */ diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsg.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsg.java new file mode 100755 index 000000000..e892019c5 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsg.java @@ -0,0 +1,125 @@ +/* + * 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.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 微信消息 + * + * @author lengleng + * @date 2019-03-27 20:45:27 + */ +@Data +@TableName("t_wx_fans_msg") +@EqualsAndHashCode(callSuper = true) +public class WxFansMsg extends Model { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId + private Integer id; + /** + * 用户标识 + */ + private String openid; + /** + * 昵称 + */ + private String nickname; + /** + * 头像地址 + */ + private String headimgUrl; + /** + * 微信账号ID + */ + private Integer wxAccountId; + + /** + * 微信公众号appid + */ + private String wxAccountAppid; + + /** + * 微信公众号名 + */ + private String wxAccountName; + + /** + * 消息ID + */ + private Long msgId; + + /** + * 消息类型 + */ + private String msgType; + /** + * 内容 + */ + private String content; + /** + * 最近一条回复内容 + */ + private String resContent; + /** + * 是否已回复 + */ + private String isRes; + /** + * 微信素材ID + */ + private String mediaId; + /** + * 微信图片URL + */ + private String picUrl; + /** + * 本地图片路径 + */ + private String picPath; + /** + * 创建时间 + */ + private LocalDateTime createTime; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + + /** + * 是否删除 -1:已删除 0:正常 + */ + @TableLogic + private String delFlag; + + /** + * 租户 + */ + private Integer tenantId; + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsgRes.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsgRes.java new file mode 100755 index 000000000..610b22119 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxFansMsgRes.java @@ -0,0 +1,69 @@ +/* + * 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.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 微信粉丝消息回复表 + * + * @author lengleng + * @date 2019-03-27 20:45:48 + */ +@Data +@TableName("t_wx_fans_msg_res") +@EqualsAndHashCode(callSuper = true) +public class WxFansMsgRes extends Model { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId + private Integer id; + /** + * 粉丝消息ID + */ + private String fansMsgId; + /** + * 回复内容 + */ + private String resContent; + /** + * 用户ID + */ + private String userId; + /** + * 用户名 + */ + private String userName; + /** + * 创建时间 + */ + private LocalDateTime createTime; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxMenu.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxMenu.java new file mode 100755 index 000000000..165b90a2b --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/entity/WxMenu.java @@ -0,0 +1,93 @@ +/* + * 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.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 微信菜单表 + * + * @author lengleng + * @date 2019-03-27 20:45:18 + */ +@Data +@TableName("t_wx_menu") +@EqualsAndHashCode(callSuper = true) +public class WxMenu extends Model { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId + private Integer id; + /** + * 父ID + */ + private String parentId; + /** + * 菜单名称 + */ + private String menuName; + /** + * 菜单类型 1文本消息;2图文消息;3网址链接;4小程序 + */ + private String menuType; + /** + * 菜单等级 + */ + private String menuLevel; + /** + * 模板ID + */ + private String tplId; + /** + * 菜单URL + */ + private String menuUrl; + /** + * 排序 + */ + private String menuSort; + /** + * 微信账号ID + */ + private String wxAccountId; + /** + * 小程序appid + */ + private String miniprogramAppid; + /** + * 小程序页面路径 + */ + private String miniprogramPagepath; + /** + * 创建时间 + */ + private LocalDateTime createTime; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/handler/LogHandler.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/handler/LogHandler.java index 0294e435c..f5d65d103 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/handler/LogHandler.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/handler/LogHandler.java @@ -1,26 +1,62 @@ package com.pig4cloud.pigx.mp.handler; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.pig4cloud.pigx.mp.entity.WxAccount; +import com.pig4cloud.pigx.mp.entity.WxFansMsg; +import com.pig4cloud.pigx.mp.service.WxAccountService; +import com.pig4cloud.pigx.mp.service.WxFansMsgService; +import lombok.AllArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.mp.bean.result.WxMpUser; import org.springframework.stereotype.Component; import java.util.Map; /** - * @author Binary Wang(https://github.com/binarywang) + * @author lengleng + *

+ * 保存微信消息 */ @Slf4j @Component +@AllArgsConstructor public class LogHandler extends AbstractHandler { + private final WxFansMsgService wxFansMsgService; + private final WxAccountService wxAccountService; + @Override + @SneakyThrows public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map context, WxMpService wxMpService, WxSessionManager sessionManager) { - log.info("接收到请求消息,内容:{}", wxMessage.getContent()); + log.debug("接收到请求消息,内容:{}", wxMessage.getContent()); + + WxAccount wxAccount = wxAccountService.getOne(Wrappers.lambdaQuery() + .eq(WxAccount::getAccount, wxMessage.getToUser())); + + + WxMpUser wxmpUser = wxMpService.getUserService() + .userInfo(wxMessage.getFromUser()); + + WxFansMsg wxFansMsg = new WxFansMsg(); + wxFansMsg.setOpenid(wxmpUser.getOpenId()); + wxFansMsg.setNickname(wxmpUser.getNickname()); + wxFansMsg.setHeadimgUrl(wxmpUser.getHeadImgUrl()); + wxFansMsg.setWxAccountId(wxAccount.getId()); + wxFansMsg.setWxAccountName(wxAccount.getName()); + wxFansMsg.setWxAccountAppid(wxAccount.getAppid()); + wxFansMsg.setMsgType(wxMessage.getMsgType()); + wxFansMsg.setMsgId(wxMessage.getMsgId()); + wxFansMsg.setContent(wxMessage.getContent()); + wxFansMsg.setTenantId(wxAccount.getTenantId()); + wxFansMsgService.save(wxFansMsg); + + log.debug("保存微信用户信息成功 {}", wxFansMsg); return null; } - } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgMapper.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgMapper.java new file mode 100755 index 000000000..2719ed380 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgMapper.java @@ -0,0 +1,30 @@ +/* + * 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.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.pig4cloud.pigx.mp.entity.WxFansMsg; + +/** + * lengleng + * + * @author pigx code generator + * @date 2019-03-27 20:45:27 + */ +public interface WxFansMsgMapper extends BaseMapper { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgResMapper.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgResMapper.java new file mode 100755 index 000000000..c6f790868 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxFansMsgResMapper.java @@ -0,0 +1,30 @@ +/* + * 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.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.pig4cloud.pigx.mp.entity.WxFansMsgRes; + +/** + * lengleng + * + * @author pigx code generator + * @date 2019-03-27 20:45:48 + */ +public interface WxFansMsgResMapper extends BaseMapper { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxMenuMapper.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxMenuMapper.java new file mode 100755 index 000000000..7b7756a56 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/mapper/WxMenuMapper.java @@ -0,0 +1,30 @@ +/* + * 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.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.pig4cloud.pigx.mp.entity.WxMenu; + +/** + * lengleng + * + * @author pigx code generator + * @date 2019-03-27 20:45:18 + */ +public interface WxMenuMapper extends BaseMapper { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxAccountFansService.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxAccountFansService.java index e0c374795..5094ba7dd 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxAccountFansService.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxAccountFansService.java @@ -27,4 +27,11 @@ import com.pig4cloud.pigx.mp.entity.WxAccountFans; */ public interface WxAccountFansService extends IService { + /** + * 同步指定公众号粉丝 + * + * @param appId + * @return + */ + Boolean syncAccountFans(String appId); } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgResService.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgResService.java new file mode 100755 index 000000000..2cbfc3eeb --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgResService.java @@ -0,0 +1,30 @@ +/* + * 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.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.pig4cloud.pigx.mp.entity.WxFansMsgRes; + +/** + * 微信消息回复业务 + * + * @author lengleng + * @date 2019-03-27 20:45:48 + */ +public interface WxFansMsgResService extends IService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgService.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgService.java new file mode 100755 index 000000000..b3aa4b860 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxFansMsgService.java @@ -0,0 +1,30 @@ +/* + * 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.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.pig4cloud.pigx.mp.entity.WxFansMsg; + +/** + * 微信消息业务 + * + * @author lengleng + * @date 2019-03-27 20:45:27 + */ +public interface WxFansMsgService extends IService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxMenuService.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxMenuService.java new file mode 100755 index 000000000..4ae680302 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/WxMenuService.java @@ -0,0 +1,30 @@ +/* + * 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.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.pig4cloud.pigx.mp.entity.WxMenu; + +/** + * 微信菜单业务 + * + * @author lengleng + * @date 2019-03-27 20:45:18 + */ +public interface WxMenuService extends IService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxAccountFansServiceImpl.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxAccountFansServiceImpl.java index 45b45fc99..08f0c01f9 100755 --- a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxAccountFansServiceImpl.java +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxAccountFansServiceImpl.java @@ -16,19 +16,124 @@ */ package com.pig4cloud.pigx.mp.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.mp.config.WxMpConfiguration; +import com.pig4cloud.pigx.mp.entity.WxAccount; import com.pig4cloud.pigx.mp.entity.WxAccountFans; import com.pig4cloud.pigx.mp.mapper.WxAccountFansMapper; +import com.pig4cloud.pigx.mp.mapper.WxAccountMapper; import com.pig4cloud.pigx.mp.service.WxAccountFansService; +import lombok.AllArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.api.WxMpUserService; +import me.chanjar.weixin.mp.bean.result.WxMpUserList; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.List; /** - * 微信公众号粉丝 - * * @author lengleng * @date 2019-03-26 22:08:08 + *

+ * 微信公众号粉丝 */ +@Slf4j @Service +@AllArgsConstructor public class WxAccountFansServiceImpl extends ServiceImpl implements WxAccountFansService { + private static final int SIZE = 100; + private final WxAccountMapper wxAccountMapper; + /** + * 获取公众号粉丝,生产建议异步 + * + * @param appId + * @return + */ + @Async + @Override + @SneakyThrows + @Transactional(rollbackFor = Exception.class) + public Boolean syncAccountFans(String appId) { + WxAccount wxAccount = wxAccountMapper + .selectOne(Wrappers.query().lambda() + .eq(WxAccount::getAppid, appId)); + + WxMpService wxMpService = WxMpConfiguration.getMpServices().get(appId); + WxMpUserService wxMpUserService = wxMpService.getUserService(); + fetchUser(null, wxAccount, wxMpUserService); + return Boolean.TRUE; + } + + /** + * 获取微信用户 + * + * @param nextOpenid + * @param wxAccount + * @param wxMpUserService + * @throws WxErrorException + */ + private void fetchUser(String nextOpenid, WxAccount wxAccount, WxMpUserService wxMpUserService) throws WxErrorException { + WxMpUserList wxMpUserList = wxMpUserService.userList(nextOpenid); + + // openId 分组 每组 100个 openid + CollUtil.split(wxMpUserList.getOpenids(), SIZE) + .stream().filter(CollUtil::isNotEmpty) + .forEach(openIdList -> { + log.info("开始批量获取用户信息 {}", openIdList); + List wxAccountFansList = new ArrayList<>(); + try { + wxMpUserService.userInfoList(openIdList).forEach(wxMpUser -> { + WxAccountFans wxAccountFans = baseMapper + .selectOne(Wrappers.query().lambda() + .eq(WxAccountFans::getOpenid, wxMpUser.getOpenId())); + // 为空初始化一个新的对象 + if (wxAccountFans == null) { + wxAccountFans = new WxAccountFans(); + } + + wxAccountFans.setOpenid(wxMpUser.getOpenId()); + wxAccountFans.setSubscribeStatus(wxMpUser.getSubscribe() ? "1" : "0"); + wxAccountFans.setSubscribeTime(LocalDateTime + .ofInstant(Instant.ofEpochMilli(wxMpUser.getSubscribeTime() * 1000L) + , ZoneId.systemDefault())); + wxAccountFans.setNickname(wxMpUser.getNickname()); + wxAccountFans.setGender(String.valueOf(wxMpUser.getSex())); + wxAccountFans.setLanguage(wxMpUser.getLanguage()); + wxAccountFans.setCountry(wxMpUser.getCountry()); + wxAccountFans.setProvince(wxMpUser.getProvince()); + wxAccountFans.setCity(wxMpUser.getCity()); + wxAccountFans.setHeadimgUrl(wxMpUser.getHeadImgUrl()); + wxAccountFans.setRemark(wxMpUser.getRemark()); + wxAccountFans.setWxAccountId(String.valueOf(wxAccount.getId())); + wxAccountFans.setWxAccountAppid(wxAccount.getAppid()); + wxAccountFans.setWxAccountName(wxAccount.getName()); + wxAccountFansList.add(wxAccountFans); + }); + this.saveOrUpdateBatch(wxAccountFansList); + log.info("批量插入用户信息完成 {}", openIdList); + } catch (WxErrorException e) { + log.error("批量同步粉丝失败", e); + } + }); + + // 如果nextOpenId 不为空,则继续获取 + if (StrUtil.isNotBlank(wxMpUserList.getNextOpenid())) { + fetchUser(wxMpUserList.getNextOpenid(), wxAccount, wxMpUserService); + } + + log.info("批量同步微信用户信息完成"); + } } diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgResServiceImpl.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgResServiceImpl.java new file mode 100755 index 000000000..f66ee7538 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgResServiceImpl.java @@ -0,0 +1,34 @@ +/* + * 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.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.mp.entity.WxFansMsgRes; +import com.pig4cloud.pigx.mp.mapper.WxFansMsgResMapper; +import com.pig4cloud.pigx.mp.service.WxFansMsgResService; +import org.springframework.stereotype.Service; + +/** + * 微信消息回复业务 + * + * @author lengleng + * @date 2019-03-27 20:45:48 + */ +@Service +public class WxFansMsgResServiceImpl extends ServiceImpl implements WxFansMsgResService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgServiceImpl.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgServiceImpl.java new file mode 100755 index 000000000..73c701f0d --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxFansMsgServiceImpl.java @@ -0,0 +1,34 @@ +/* + * 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.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.mp.entity.WxFansMsg; +import com.pig4cloud.pigx.mp.mapper.WxFansMsgMapper; +import com.pig4cloud.pigx.mp.service.WxFansMsgService; +import org.springframework.stereotype.Service; + +/** + * 微信消息业务 + * + * @author lengleng + * @date 2019-03-27 20:45:27 + */ +@Service +public class WxFansMsgServiceImpl extends ServiceImpl implements WxFansMsgService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxMenuServiceImpl.java b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxMenuServiceImpl.java new file mode 100755 index 000000000..d7bfa7bcc --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/java/com/pig4cloud/pigx/mp/service/impl/WxMenuServiceImpl.java @@ -0,0 +1,34 @@ +/* + * 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.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.mp.entity.WxMenu; +import com.pig4cloud.pigx.mp.mapper.WxMenuMapper; +import com.pig4cloud.pigx.mp.service.WxMenuService; +import org.springframework.stereotype.Service; + +/** + * 微信菜单业务 + * + * @author lengleng + * @date 2019-03-27 20:45:18 + */ +@Service +public class WxMenuServiceImpl extends ServiceImpl implements WxMenuService { + +} diff --git a/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxAccountFansMapper.xml b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxAccountFansMapper.xml index 347559fab..834219ace 100755 --- a/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxAccountFansMapper.xml +++ b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxAccountFansMapper.xml @@ -38,6 +38,7 @@ + diff --git a/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgMapper.xml b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgMapper.xml new file mode 100755 index 000000000..5bcded334 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgMapper.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgResMapper.xml b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgResMapper.xml new file mode 100755 index 000000000..4ebb02559 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxFansMsgResMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + diff --git a/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxMenuMapper.xml b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxMenuMapper.xml new file mode 100755 index 000000000..432502833 --- /dev/null +++ b/pigx-visual/pigx-mp-manager/src/main/resources/mapper/WxMenuMapper.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + +