From 2da94ee07a6634ac945c279ae2f3b98f444fd6c9 Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Tue, 10 Oct 2023 22:29:20 +0800 Subject: [PATCH] =?UTF-8?q?Oam-=E5=BE=AE=E4=BF=A1=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cpop/common/constant/Constants.java | 2 +- .../com/cpop/core/base/table/SysConfig.java | 2 +- .../impl/OamStaffDetailsServiceImpl.java | 2 +- .../main/resources/static.keyPair/privateKey | Bin 1476 -> 0 bytes .../main/resources/static.keyPair/publicKey | Bin 551 -> 0 bytes .../src/main/resources/application.yml | 2 +- .../i18n}/messages.properties | 0 .../i18n}/messages_en_US.properties | 0 .../i18n}/messages_zh_CN.properties | 0 .../oam/business/bo/WxOpenMaCodeCommitBo.java | 56 ++ .../business/bo/WxOpenMaSubmitAuditBo.java | 9 + .../business/bo/WxOpenMaTrialQrCodeBo.java | 35 ++ .../business/controller/WxOpenController.java | 534 ++++++++++++++++++ Cpop-Sdk/pom.xml | 5 + .../framework/config/WxOpenProperties.java | 95 ++++ .../sdk/framework/handler/WxOpenService.java | 53 ++ .../src/main/resources/application-sdk.yml | 16 +- pom.xml | 6 + 18 files changed, 809 insertions(+), 8 deletions(-) delete mode 100644 Cpop-Core/src/main/resources/static.keyPair/privateKey delete mode 100644 Cpop-Core/src/main/resources/static.keyPair/publicKey rename Cpop-Oam/Cpop-Oam-Web/src/main/resources/{static.i18n => static/i18n}/messages.properties (100%) rename Cpop-Oam/Cpop-Oam-Web/src/main/resources/{static.i18n => static/i18n}/messages_en_US.properties (100%) rename Cpop-Oam/Cpop-Oam-Web/src/main/resources/{static.i18n => static/i18n}/messages_zh_CN.properties (100%) create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaCodeCommitBo.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaSubmitAuditBo.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/bo/WxOpenMaTrialQrCodeBo.java create mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java create mode 100644 Cpop-Sdk/src/main/java/com/cpop/sdk/framework/config/WxOpenProperties.java create mode 100644 Cpop-Sdk/src/main/java/com/cpop/sdk/framework/handler/WxOpenService.java 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 458b4be286829a1550e40813d4a385d08d08f186..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1476 zcmZvcc|6k%9LIl~nLF$i9xFWR1fDEF1) zS*{3~P$42buJkB{Ipd+8=kzt`*Y$GdnD;0>ez2e06+;*fy^d=SNl8iK?S zLL3NW_Qu(&+nEo|!2rYt5Wo?={P&=@9~FSv?6<2EaU?HwES2Iz@-lD*_y{DtzX!pC z3V>bBYyhaIKgAD64FJLbkPQH#hL8zV;Ly*(fA6UOyrbZ_2MvPBRDj0;YZ^q^Ur@X( zwGQQXoB#trFc|TKV6$v7xm1m9OP;&QHY4x+sn`U#BFJ_J$$0uIwe4AW~%x9p&I;u_j#o1k& zUxt}@YZg~cAX^cSsjpr=pF*!yUQy;#3%I|)7`|_Lalm>Ot)$p4k+5~x>V)D>&MBT1 zFVs|ThlYjlE#c4T!nVp=V~<{X>qrz8vqGTDkpoV|jHin3)-*&EIc@4n9Sz@$Tm;L@__RuB7N{OIc>3nX23jpWro;_DXyJ% z=kAiQ!3(HB=XjJ>i*|dwhSe*i+-d>idfw}0a%@&OxRw8!LLyTN%mV^IKaz-A^VMdG z;|6#8;%kd+?Y~9a4H*>B*P|iCxPaCve`(JLq2FN^e2ty3i8Eg}w$sfMhfw20ujeX{ z5Wi_-IIXQEZ5~xpx6LPyjG*!etb`C_R#TI_TNt+{xxEX{tqax!7k%F{;|-NVI@}N| zvy6?sGm6)&VJ5TRD<>HXp(q>bjINaR@g!#01H7*%=A>n@UXRs)&N1FuZ;piPX8)-O zO^ZzI%fmNmYF!S#@X6N{XLJh&b)yy1dfEY(%eldgG2WL1B z7a^~=OZMz+bM;E+)ja*=({S}|t>z~SM*`(LFlil0%H zw3GQI4%(s?WNcH8PIZunL2)Y?ZRxB0L36gu3q9iJI+QF8zLzS;>ojz~_2d1xRd-|j zel*KotcfU~DkhYhnbY;0zPWv`F4YijS$v{h&`2zg9y#+kU-3dXXJ|F2gBEcp1%0zP zo4s)N1lIaeDv<4_Zzu?F+y9|W_NzibQR{8X@JhiE&Q7Sq;%iL)GOivyCR~xB63wn( zT6tlO4=tfSTX`9u+nO==|n)4EZ59JG% zeuu@0+wkfY{E7>zC|-EHTC@6F6}a(#?V?89O`a95gADF=#L#R@R~CEfDI@ zB0m|WO~}C#bs@Umg}GWAktE1ym%dO!%uFLZqDlV4H(QS}m9L_gSzmZKT8PqaKZ7U9 zQwnE|!sz*vg>)g`nvU9ty%=aj?Q05nr)dkPtz_+fSmTNokdEdOa^0}Hc zv_x-@h~%iEJA!GhG`8BGw@@$QrfSY;I@UE&p@=o%mL^EclP<{~p^ueCJU+<(*CDML zgsbkRW6I|-PpL+ZGMT2b`=%O}buzQmNB}E;p6%NVexvW`a&CV5*B6|<7Zd?#W|WhV z%7mOQ*AAmlZus!@PWO7A_pqXW3%%cb04UP0(WZ85X;k<8OI?OE0BW77@ zcogi_+fxKusdmefb(vA30#G}QIToQ8MggS%Pq#lb2>es9J?~L~13&uqJ&Uv;1^N9K P?%9&h&cVvb)Y0N^YG#=2 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 543d0b962bc1728f2e1599dc27bc362a83f337c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 551 zcmZ4UmVvdnh(RPPu`E%qI5oMnD6^ze&pWj;D79ekPyfvwvz9tDF|hbBa3{^I7}{8%M|kCI*Iz0tN;~HG?Kb zB?DeIPOUbNw(q=*jEt-d%uS5^3_x)%rY1&4hUF)i*p{D+(h=HVWi#dThm~A+v0FhaPLXO_c!JzdoBN_!#P(q z*?Z@fuMv}bwrPCPVAm;}^J?miIc_nRyq>wMsU8*W|1INbuKI7D3-gzB%SY#q8MyM) z^SpCkad=bx-DRgUOhs3&SzgKZx%pC9&dlwq30@7#Ed|paWo^1PYweB(siR`ouXg%~ zwq2KHVSjAnu=N&S(Tmwl?n63nV1 + * @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