diff --git a/Cpop-Common/src/main/java/com/cpop/common/constant/Constants.java b/Cpop-Common/src/main/java/com/cpop/common/constant/Constants.java index 8920454..9b7d394 100644 --- a/Cpop-Common/src/main/java/com/cpop/common/constant/Constants.java +++ b/Cpop-Common/src/main/java/com/cpop/common/constant/Constants.java @@ -172,7 +172,7 @@ public interface Constants { /** * 超级管理员 */ - String SUPER_ADMIN = "PuPu"; + String SUPER_ADMIN = "Cpop"; /** * 超级管理员 diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/table/SysConfig.java b/Cpop-Core/src/main/java/com/cpop/core/base/table/SysConfig.java index a0ae425..87942bb 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/base/table/SysConfig.java +++ b/Cpop-Core/src/main/java/com/cpop/core/base/table/SysConfig.java @@ -22,7 +22,7 @@ import java.io.Serializable; @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) -@Table(value = "pp_sys_config", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) +@Table(value = "cp_sys_config", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false) public class SysConfig extends BaseEntity implements Serializable { /** diff --git a/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java b/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java index 169cbfd..44532ef 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java +++ b/Cpop-Core/src/main/java/com/cpop/core/service/impl/OamStaffDetailsServiceImpl.java @@ -52,7 +52,7 @@ public class OamStaffDetailsServiceImpl implements UserDetailsService { staffLoginInfo.setUserId(sysUser.getId()); //员工 if (!staffLoginInfo.getUserName().equals(Constants.SUPER_ADMIN)) { - Row row = DbChain.table("pp_oam_staff") + Row row = DbChain.table("cp_oam_staff") .select() .where("user_id = ?", staffLoginInfo.getUserId()) .one(); diff --git a/Cpop-Core/src/main/resources/static.keyPair/privateKey b/Cpop-Core/src/main/resources/static.keyPair/privateKey deleted file mode 100644 index 458b4be..0000000 Binary files a/Cpop-Core/src/main/resources/static.keyPair/privateKey and /dev/null differ diff --git a/Cpop-Core/src/main/resources/static.keyPair/publicKey b/Cpop-Core/src/main/resources/static.keyPair/publicKey deleted file mode 100644 index 543d0b9..0000000 Binary files a/Cpop-Core/src/main/resources/static.keyPair/publicKey and /dev/null differ diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml index 1ce6497..9db0d3f 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml @@ -1,7 +1,7 @@ # 项目相关配置 cpop: # 名称 - name: PuPu-OAM + name: Cpop-Oam # 版本 version: 1.0.0 #JWT diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages.properties b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages.properties similarity index 100% rename from Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages.properties rename to Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages.properties diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages_en_US.properties b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages_en_US.properties similarity index 100% rename from Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages_en_US.properties rename to Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages_en_US.properties diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages_zh_CN.properties b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages_zh_CN.properties similarity index 100% rename from Cpop-Oam/Cpop-Oam-Web/src/main/resources/static.i18n/messages_zh_CN.properties rename to Cpop-Oam/Cpop-Oam-Web/src/main/resources/static/i18n/messages_zh_CN.properties diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaCodeCommitBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaCodeCommitBo.java new file mode 100644 index 0000000..a6ec833 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaCodeCommitBo.java @@ -0,0 +1,56 @@ +package com.cpop.oam.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * @author DB + * @createTime 2023/10/10 17:14 + * @description + */ +@Data +@ApiModel(value = "OpenPlatformCommit上传代码对象") +public class WxOpenMaCodeCommitBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 授权方 appid + */ + @NotBlank(message = "授权方appid不能为空") + @ApiModelProperty(value = "授权方 appid",required = true) + private String authorizerAppid; + + /** + * 代码库中的代码模板 ID + */ + @NotNull(message = "代码库中的代码模板ID不能为空") + @ApiModelProperty(value = "代码库中的代码模板 ID",required = true) + private Long templateId; + + /** + * 为了方便第三方平台的开发者引入 extAppid 的开发调试工作 + */ + @NotBlank(message = "extJson不能为空") + @ApiModelProperty(value = "该参数则是用于控制ext.json配置文件的内容",required = true) + private String extJson; + + /** + * 代码版本号,开发者可自定义 + */ + @NotBlank(message = "代码版本号不能为空") + @ApiModelProperty(value = "代码版本号,开发者可自定义",required = true) + private String userVersion; + + /** + * 代码描述,开发者可自定义 + */ + @NotBlank(message = "代码描述不能为空") + @ApiModelProperty(value = "代码描述,开发者可自定义",required = true) + private String userDesc; +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaSubmitAuditBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaSubmitAuditBo.java new file mode 100644 index 0000000..ff43011 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaSubmitAuditBo.java @@ -0,0 +1,9 @@ +package com.cpop.oam.business.bo; + +/** + * @author DB + * @createTime 2023/10/10 17:35 + * @description + */ +public class WxOpenMaSubmitAuditBo { +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaTrialQrCodeBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaTrialQrCodeBo.java new file mode 100644 index 0000000..b6fff68 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaTrialQrCodeBo.java @@ -0,0 +1,35 @@ +package com.cpop.oam.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @author DB + * @createTime 2023/10/10 17:22 + * @description + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "WxOpenMaTrialQrCodeBo生产二维码") +public class WxOpenMaTrialQrCodeBo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 授权方 appid + */ + @NotBlank(message = "授权方appid不能为空") + @ApiModelProperty(value = "授权方 appid",required = true) + private String authorizerAppid; + + /** + * 指定二维码扫码后直接进入指定页面并可同时带上参数 + */ + @ApiModelProperty("指定二维码扫码后直接进入指定页面并可同时带上参数") + private String path; +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java new file mode 100644 index 0000000..1cc0926 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java @@ -0,0 +1,534 @@ +package com.cpop.oam.business.controller; + +import cn.binarywang.wx.miniapp.bean.WxMaAuditMediaUploadResult; +import com.cpop.common.utils.StringUtils; +import com.cpop.core.base.R; +import com.cpop.core.base.entity.PageDomain; +import com.cpop.core.base.exception.ServiceException; +import com.cpop.core.utils.sql.SqlUtils; +import com.cpop.oam.business.bo.WxOpenMaCodeCommitBo; +import com.cpop.oam.business.bo.WxOpenMaTrialQrCodeBo; +import com.cpop.sdk.framework.config.WxOpenProperties; +import com.cpop.sdk.framework.handler.WxOpenService; +import com.mybatisflex.core.paginate.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; +import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; +import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; +import me.chanjar.weixin.open.bean.message.WxOpenMaSubmitAuditMessage; +import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; +import me.chanjar.weixin.open.bean.result.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Base64; +import java.util.List; +import java.util.Map; + +/** + * @author DB + * @createTime 2023/10/10 13:40 + * @description 微信开放平台 + */ +@RestController +@Api(tags = "微信开放平台模块") +@RequestMapping("/wxOpen") +public class WxOpenController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxOpenService wxOpenService; + + @Autowired + private WxOpenProperties properties; + + /** + * @descriptions 第三方平台授权 + * @author DB + * @date 2023/10/10 13:43 + * @param requestBody 请求参数 + * @param timestamp 时间戳 + * @param nonce 随机串 + * @param signature 签名 + * @param encType 解密类型 + * @param msgSignature 签名信息 + * @return: java.lang.Object 返回 + */ + @RequestMapping("/receiveTicket") + public Object receiveTicket(@RequestBody(required = false) String requestBody, @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, @RequestParam("signature") String signature, + @RequestParam(name = "encrypt_type", required = false) String encType, + @RequestParam(name = "msg_signature", required = false) String msgSignature) { + if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { + throw new ServiceException("非法请求,可能属于伪造的请求!"); + } + // aes加密的消息 + WxOpenXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); + try { + wxOpenService.getWxOpenComponentService().route(inMessage); + } catch (WxErrorException e) { + this.logger.error("wxOpen:receiveTicket", e); + } + return "success"; + } + + /** + * @Description: 获取授权链接 + * @return R + * @Author DB + * @Date: 2023/6/14 21:47 + */ + @ApiOperation("获取授权链接") + @GetMapping("/getAuthorizedLink") + public R getAuthorizedLink() { + String preAuthUrl; + try { + preAuthUrl = wxOpenService.getWxOpenComponentService().getPreAuthUrl(properties.getRedirectUri()); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(preAuthUrl); + } + + /** + * @descriptions 授权回调地址 + * @author DB + * @date 2023/10/10 15:49 + * @param authorizationCode 授权码 + * @return: me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult + */ + @GetMapping("/redirectUrl") + @ResponseBody + public WxOpenQueryAuthResult redirectUrl(@RequestParam("auth_code") String authorizationCode) { + try { + return wxOpenService.getWxOpenComponentService().getQueryAuth(authorizationCode); + } catch (WxErrorException e) { + logger.error("gotoPreAuthUrl", e); + throw new ServiceException(e.getMessage()); + } + } + + /** + * @descriptions + * @author DB + * @date 2023/10/10 14:56 + * @param requestBody 请求体 + * @param appId appid + * @param signature 签名 + * @param timestamp 时间戳 + * @param nonce 随机串 + * @param openid openId + * @param encType 加密类型 + * @param msgSignature 加密信息 + * @return: java.lang.Object + */ + @RequestMapping("{appId}/callback") + public Object callback(@RequestBody(required = false) String requestBody, + @PathVariable("appId") String appId, + @RequestParam("signature") String signature, + @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, + @RequestParam("openid") String openid, + @RequestParam("encrypt_type") String encType, + @RequestParam("msg_signature") String msgSignature) { + if (!StringUtils.equalsIgnoreCase("aes", encType) || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { + throw new ServiceException("非法请求,可能属于伪造的请求!"); + } + String out = ""; + // aes加密的消息 + WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody, wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); + // 全网发布测试用例 + if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) { + try { + if (StringUtils.equals(inMessage.getMsgType(), "text")) { + if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) { + out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml( + WxMpXmlOutMessage.TEXT().content("TESTCOMPONENT_MSG_TYPE_TEXT_callback") + .fromUser(inMessage.getToUser()) + .toUser(inMessage.getFromUser()) + .build(), + wxOpenService.getWxOpenConfigStorage() + ); + } else if (StringUtils.startsWith(inMessage.getContent(), "QUERY_AUTH_CODE:")) { + String msg = inMessage.getContent().replace("QUERY_AUTH_CODE:", "") + "_from_api"; + WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(msg).toUser(inMessage.getFromUser()).build(); + wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); + } + } else if (StringUtils.equals(inMessage.getMsgType(), "event")) { + WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(inMessage.getEvent() + "from_callback").toUser(inMessage.getFromUser()).build(); + wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage); + } + } catch (WxErrorException e) { + logger.error("callback", e); + } + }else{ + WxMpXmlOutMessage outMessage = wxOpenService.getWxOpenMessageRouter().route(inMessage, appId); + if(outMessage != null){ + out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMessage, wxOpenService.getWxOpenConfigStorage()); + } + } + return out; + } + + /** + * @param appid 绑定小程序appid + * @return R + * @Description: 小程序绑定开放平台 + * @Author DB + * @Date: 2023/6/14 21:47 + */ + @ApiOperation("小程序绑定开放平台") + @GetMapping("/bindOpenAccount/{appid}") + public R bindOpenAccount(@PathVariable String appid) { + try { + wxOpenService.getWxOpenComponentService().bindOpenAccount(appid, WxConsts.AppIdType.MINI_TYPE, properties.getOpenAppid()); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 解除绑定开放平台帐号 + * @param appid 绑定小程序appid + * @return R + * @Author DB + * @Date: 2023/6/14 21:47 + */ + @ApiOperation("解除绑定开放平台帐号") + @GetMapping("/unbindOpenAccount/{appid}") + public R unbindOpenAccount(@PathVariable String appid) { + try { + wxOpenService.getWxOpenComponentService().unbindOpenAccount(appid, WxConsts.AppIdType.MINI_TYPE, properties.getOpenAppid()); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @return R>> + * @Description: 获取授权小程序列表 + * @author DB + * @Date: 2023/6/14 0014 17:00 + */ + @ApiOperation("获取授权小程序列表") + @GetMapping("/getAuthorizerList") + public R>> getAuthorizerList() { + try { + PageDomain pageDomain = SqlUtils.getInstance().getPageDomain(); + WxOpenAuthorizerListResult authorizerList = wxOpenService.getWxOpenComponentService().getAuthorizerList(pageDomain.getPageNum(), pageDomain.getPageSize()); + Page> page = Page.of(pageDomain.getPageNum(), pageDomain.getPageSize(), authorizerList.getTotalCount()); + page.setRecords(authorizerList.getList()); + return R.ok(page); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 获取授权小程序详情 + * @param authorizerAppid 授权小程序appid + * @return R> + * @author DB + * @Date: 2023/6/15 0015 16:38 + */ + @ApiOperation("获取授权小程序详情") + @GetMapping("/getAuthorizerInfo/{authorizerAppid}") + public R getAuthorizerInfo(@PathVariable String authorizerAppid) { + try { + WxOpenAuthorizerInfoResult wxOpenAuthorizerInfoResult = wxOpenService.getWxOpenComponentService().getAuthorizerInfo(authorizerAppid); + return R.ok(wxOpenAuthorizerInfoResult); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 上传代码并生成体验版 + * @param bo 请求参数 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("上传代码并生成体验版") + @PostMapping("/commit") + public R commit(@RequestBody @Validated WxOpenMaCodeCommitBo bo) { + try { + wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(bo.getAuthorizerAppid()) + .codeCommit(bo.getTemplateId(),bo.getUserVersion(),bo.getUserDesc(),bo.getExtJson()); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 获取体验版二维码 + * @param bo 请求参数 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:35 + */ + @ApiOperation("获取体验版二维码") + @PostMapping("/getTrialQrCode") + public R getTrialQrCode(@RequestBody WxOpenMaTrialQrCodeBo bo) { + try { + File testQrcode = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(bo.getAuthorizerAppid()) + .getTestQrcode(bo.getPath(), null); + FileInputStream inputFile = new FileInputStream(testQrcode); + BufferedImage bufferedImage = ImageIO.read(inputFile); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "png", outputStream); + String trialQrCode = Base64.getEncoder().encodeToString(outputStream.toByteArray()); + String head = "data:image/png;base64,"; + return R.ok(head + trialQrCode); + } catch (IOException | WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 提交代码审核 + * @param message 微信小程序代码包提交审核(仅供第三方开发者代小程序调用 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("提交代码审核") + @PostMapping("/submitAudit/{authorizerAppid}") + public R submitAudit(@PathVariable String authorizerAppid ,@RequestBody WxOpenMaSubmitAuditMessage message) { + try { + WxOpenMaSubmitAuditResult wxOpenMaSubmitAuditResult = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid) + .submitAudit(message); + return R.ok(wxOpenMaSubmitAuditResult); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @descriptions 查询审核单状态 + * @author DB + * @date 2023/10/10 17:41 + * @param authorizerAppid 授权appid + * @param auditId 审核id + * @return: com.cpop.core.base.R + */ + @ApiOperation("查询审核单状态") + @GetMapping("/getAuditStatus") + public R getAuditStatus(@RequestParam("authorizerAppid") String authorizerAppid, @RequestParam("auditId") Long auditId) { + try { + WxOpenMaQueryAuditResult auditStatus = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).getAuditStatus(auditId); + return R.ok(auditStatus); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 撤回代码审核 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("撤回代码审核") + @PutMapping("/undoAudit/{authorizerAppid}") + public R getAuditStatus(@PathVariable String authorizerAppid) { + try { + wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).undoCodeAudit(); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 发布已通过审核的小程序 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("发布已通过审核的小程序") + @PutMapping("/release/{authorizerAppid}") + public R release(@PathVariable String authorizerAppid) { + try { + wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).releaseAudited(); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 撤回代码审核 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("小程序版本回退") + @PutMapping("/revertCodeRelease/{authorizerAppid}") + public R revertCodeRelease(@PathVariable String authorizerAppid) { + try { + wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).revertCodeRelease(); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 加急代码审核 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("加急代码审核") + @PutMapping("/speedupCodeAudit") + public R speedupCodeAudit(@RequestParam("authorizerAppid") String authorizerAppid, @RequestParam("auditId") Long auditId) { + try { + wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).speedAudit(auditId); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @return R + * @Description: 查询小程序版本信息 + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("查询小程序版本信息") + @GetMapping("/getVersionInfo/{authorizerAppid}") + public R getVersionInfo(@PathVariable String authorizerAppid) { + try { + WxOpenVersioninfoResult versionInfo = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).getVersionInfo(); + return R.ok(versionInfo); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 查询最新一次审核单状态 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("查询最新一次审核单状态") + @GetMapping("/getLatestAuditStatus/{authorizerAppid}") + public R getLatestAuditStatus(@PathVariable String authorizerAppid) { + try { + WxOpenMaQueryAuditResult latestAuditStatus = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).getLatestAuditStatus(); + return R.ok(latestAuditStatus); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @return R + * @Description: 上传提审素材 + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("上传提审素材") + @PostMapping("/uploadMediaToCodeAudit/{authorizerAppid}") + public R uploadMediaToCodeAudit(@RequestParam("file") File file, @PathVariable("authorizerAppid") String authorizerAppid) { + try { + WxMaAuditMediaUploadResult wxMaAuditMediaUploadResult = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).uploadMedia(file); + return R.ok(wxMaAuditMediaUploadResult); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @descriptions 获取模板列表 + * @author DB + * @date 2023/10/10 18:17 + * @param templateType 模板类型 + * @return: com.cpop.core.base.R> + */ + @ApiOperation("获取模板列表") + @GetMapping("/getTemplateList") + public R> getTemplateList(@RequestParam("templateType")Integer templateType) { + try { + List templateList = wxOpenService.getWxOpenComponentService().getTemplateList(templateType); + return R.ok(templateList); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @Description: 获取草稿箱列表 + * @return R + * @author DB + * @Date: 2023/6/16 0016 17:34 + */ + @ApiOperation("获取草稿箱列表") + @GetMapping("/getTemplateDraftList") + public R> getTemplateDraftList() { + try { + List templateDraftList = wxOpenService.getWxOpenComponentService().getTemplateDraftList(); + return R.ok(templateDraftList); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * @descriptions 将草稿添加到模板库 + * @author DB + * @date 2023/10/10 18:16 + * @param draftId 草稿id + * @param templateType 模板类型 + * @return: com.cpop.core.base.R + */ + @ApiOperation("将草稿添加到模板库") + @PostMapping("/addToTemplate") + public R addToTemplate(@RequestParam("draftId") Long draftId, @RequestParam("templateType") Integer templateType) { + try { + wxOpenService.getWxOpenComponentService().addToTemplate(draftId, templateType); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + + /** + * @Description: 删除代码模板 + * @param templateId 模板id + * @return R + * @author DB + * @Date: 2023/6/27 0027 14:28 + */ + @ApiOperation("删除代码模板") + @DeleteMapping("/deleteTemplate/{templateId}") + public R deleteTemplate(@PathVariable Integer templateId) { + try { + wxOpenService.getWxOpenComponentService().deleteTemplate(templateId); + } catch (WxErrorException e) { + throw new ServiceException(e.getMessage()); + } + return R.ok(); + } + +} diff --git a/Cpop-Sdk/pom.xml b/Cpop-Sdk/pom.xml index bacdcda..f028362 100644 --- a/Cpop-Sdk/pom.xml +++ b/Cpop-Sdk/pom.xml @@ -18,6 +18,11 @@ com.cpop Cpop-Core + + + com.github.binarywang + weixin-java-open + com.github.binarywang diff --git a/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/config/WxOpenProperties.java b/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/config/WxOpenProperties.java new file mode 100644 index 0000000..bb1daf5 --- /dev/null +++ b/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/config/WxOpenProperties.java @@ -0,0 +1,95 @@ +package com.cpop.sdk.framework.config; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author DB + * @createTime 2023/10/10 11:13 + * @description + */ +@ConfigurationProperties(prefix = "wx.open") +public class WxOpenProperties { + + private String openAppid; + + /** + * 设置微信三方平台的appid + */ + private String componentAppId; + + /** + * 设置微信三方平台的app secret + */ + private String componentSecret; + + /** + * 设置微信三方平台的token + */ + private String componentToken; + + /** + * 设置微信三方平台的EncodingAESKey + */ + private String componentAesKey; + + /** + * 获取跳转页面URL + */ + private String redirectUri; + + public String getOpenAppid() { + return openAppid; + } + + public void setOpenAppid(String openAppid) { + this.openAppid = openAppid; + } + + public String getComponentAppId() { + return componentAppId; + } + + public void setComponentAppId(String componentAppId) { + this.componentAppId = componentAppId; + } + + public String getComponentSecret() { + return componentSecret; + } + + public void setComponentSecret(String componentSecret) { + this.componentSecret = componentSecret; + } + + public String getComponentToken() { + return componentToken; + } + + public void setComponentToken(String componentToken) { + this.componentToken = componentToken; + } + + public String getComponentAesKey() { + return componentAesKey; + } + + public void setComponentAesKey(String componentAesKey) { + this.componentAesKey = componentAesKey; + } + + public String getRedirectUri() { + return redirectUri; + } + + public void setRedirectUri(String redirectUri) { + this.redirectUri = redirectUri; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, + ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/handler/WxOpenService.java b/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/handler/WxOpenService.java new file mode 100644 index 0000000..2117fca --- /dev/null +++ b/Cpop-Sdk/src/main/java/com/cpop/sdk/framework/handler/WxOpenService.java @@ -0,0 +1,53 @@ +package com.cpop.sdk.framework.handler; + +import com.cpop.sdk.framework.config.WxOpenProperties; +import me.chanjar.weixin.open.api.impl.WxOpenInRedisTemplateConfigStorage; +import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter; +import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; + +/** + * @author DB + * @createTime 2023/10/10 11:29 + * @description + */ +@Service +@EnableConfigurationProperties({WxOpenProperties.class}) +public class WxOpenService extends WxOpenServiceImpl { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private WxOpenProperties wxOpenProperties; + + private WxOpenMessageRouter wxOpenMessageRouter; + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + @PostConstruct + public void init() { + WxOpenInRedisTemplateConfigStorage inRedisConfigStorage = new WxOpenInRedisTemplateConfigStorage(stringRedisTemplate, "Cpop:sdk:wxOpen:"); + inRedisConfigStorage.setComponentAppId(wxOpenProperties.getComponentAppId()); + inRedisConfigStorage.setComponentAppSecret(wxOpenProperties.getComponentSecret()); + inRedisConfigStorage.setComponentToken(wxOpenProperties.getComponentToken()); + inRedisConfigStorage.setComponentAesKey(wxOpenProperties.getComponentAesKey()); + setWxOpenConfigStorage(inRedisConfigStorage); + wxOpenMessageRouter = new WxOpenMessageRouter(this); + wxOpenMessageRouter.rule().handler((wxMpXmlMessage, map, wxMpService, wxSessionManager) -> { + logger.info("\n接收到 {} 公众号请求消息,内容:{}", wxMpService.getWxMpConfigStorage().getAppId(), wxMpXmlMessage); + return null; + }).next(); + } + + public WxOpenMessageRouter getWxOpenMessageRouter(){ + return wxOpenMessageRouter; + } +} diff --git a/Cpop-Sdk/src/main/resources/application-sdk.yml b/Cpop-Sdk/src/main/resources/application-sdk.yml index 7509203..8a715e2 100644 --- a/Cpop-Sdk/src/main/resources/application-sdk.yml +++ b/Cpop-Sdk/src/main/resources/application-sdk.yml @@ -8,15 +8,23 @@ qCloud: #微信SDK wx: + #开放平台 + open: + openAppid: wx6e07ba6606e912a5 + componentAppId: wx1efbf67f8637d7d1 + componentSecret: fc2e9457aaa32342751cc655b5a1d273 + componentToken: jambox + componentAesKey: 1a3NBxmCFwkCJvfoQ7WhJHB6iX3qHPsc9JbaDznE1i0 + redirectUri: https://empower.oamapi.cpopsz.com/test/openPlatform/thirdPartyPlatform/redirectUrl #小程序 miniapp: configs: - #\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u7684appid + #appid - appid: wx1eb0e5fb7dac3c05 - #\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u7684Secret + #Secret secret: f274d2ca01cc58cb5387379356c005c1 - #\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u6D88\u606F\u670D\u52A1\u5668\u914D\u7F6E\u7684token + # token: - #\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u6D88\u606F\u670D\u52A1\u5668\u914D\u7F6E\u7684EncodingAESKey + # aesKey: msgDataFormat: JSON diff --git a/pom.xml b/pom.xml index b6bad55..9ca5464 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,12 @@ knife4j-openapi2-spring-boot-starter ${knife4j.version} + + + com.github.binarywang + weixin-java-open + ${wechat-java.version} + com.github.binarywang