Oam-微信开放平台

This commit is contained in:
DB 2023-10-10 22:29:20 +08:00
parent 74b0fbbb19
commit 2da94ee07a
18 changed files with 809 additions and 8 deletions

View File

@ -172,7 +172,7 @@ public interface Constants {
/**
* 超级管理员
*/
String SUPER_ADMIN = "PuPu";
String SUPER_ADMIN = "Cpop";
/**
* 超级管理员

View File

@ -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 {
/**

View File

@ -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();

View File

@ -1,7 +1,7 @@
# 项目相关配置
cpop:
# 名称
name: PuPu-OAM
name: Cpop-Oam
# 版本
version: 1.0.0
#JWT

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
package com.cpop.oam.business.bo;
/**
* @author DB
* @createTime 2023/10/10 17:35
* @description
*/
public class WxOpenMaSubmitAuditBo {
}

View File

@ -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;
}

View File

@ -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<String>
* @Author DB
* @Date: 2023/6/14 21:47
*/
@ApiOperation("获取授权链接")
@GetMapping("/getAuthorizedLink")
public R<String> 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<String>
* @Description: 小程序绑定开放平台
* @Author DB
* @Date: 2023/6/14 21:47
*/
@ApiOperation("小程序绑定开放平台")
@GetMapping("/bindOpenAccount/{appid}")
public R<Void> 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<String>
* @Author DB
* @Date: 2023/6/14 21:47
*/
@ApiOperation("解除绑定开放平台帐号")
@GetMapping("/unbindOpenAccount/{appid}")
public R<Void> 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<Page<Map<String, String>>>
* @Description: 获取授权小程序列表
* @author DB
* @Date: 2023/6/14 0014 17:00
*/
@ApiOperation("获取授权小程序列表")
@GetMapping("/getAuthorizerList")
public R<Page<Map<String, String>>> getAuthorizerList() {
try {
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
WxOpenAuthorizerListResult authorizerList = wxOpenService.getWxOpenComponentService().getAuthorizerList(pageDomain.getPageNum(), pageDomain.getPageSize());
Page<Map<String, String>> 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<List<OpenPlatformAuthorizerListVo>>
* @author DB
* @Date: 2023/6/15 0015 16:38
*/
@ApiOperation("获取授权小程序详情")
@GetMapping("/getAuthorizerInfo/{authorizerAppid}")
public R<WxOpenAuthorizerInfoResult> 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<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("上传代码并生成体验版")
@PostMapping("/commit")
public R<Void> 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<JSONObject>
* @author DB
* @Date: 2023/6/16 0016 17:35
*/
@ApiOperation("获取体验版二维码")
@PostMapping("/getTrialQrCode")
public R<String> 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<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("提交代码审核")
@PostMapping("/submitAudit/{authorizerAppid}")
public R<WxOpenMaSubmitAuditResult> 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<me.chanjar.weixin.open.bean.result.WxOpenMaQueryAuditResult>
*/
@ApiOperation("查询审核单状态")
@GetMapping("/getAuditStatus")
public R<WxOpenMaQueryAuditResult> 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<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("撤回代码审核")
@PutMapping("/undoAudit/{authorizerAppid}")
public R<Void> getAuditStatus(@PathVariable String authorizerAppid) {
try {
wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).undoCodeAudit();
} catch (WxErrorException e) {
throw new ServiceException(e.getMessage());
}
return R.ok();
}
/**
* @Description: 发布已通过审核的小程序
* @return R<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("发布已通过审核的小程序")
@PutMapping("/release/{authorizerAppid}")
public R<Void> release(@PathVariable String authorizerAppid) {
try {
wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).releaseAudited();
} catch (WxErrorException e) {
throw new ServiceException(e.getMessage());
}
return R.ok();
}
/**
* @Description: 撤回代码审核
* @return R<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("小程序版本回退")
@PutMapping("/revertCodeRelease/{authorizerAppid}")
public R<Void> revertCodeRelease(@PathVariable String authorizerAppid) {
try {
wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(authorizerAppid).revertCodeRelease();
} catch (WxErrorException e) {
throw new ServiceException(e.getMessage());
}
return R.ok();
}
/**
* @Description: 加急代码审核
* @return R<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("加急代码审核")
@PutMapping("/speedupCodeAudit")
public R<Void> 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<OpenPlatformVersionInfoVo>
* @Description: 查询小程序版本信息
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("查询小程序版本信息")
@GetMapping("/getVersionInfo/{authorizerAppid}")
public R<WxOpenVersioninfoResult> 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<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("查询最新一次审核单状态")
@GetMapping("/getLatestAuditStatus/{authorizerAppid}")
public R<WxOpenMaQueryAuditResult> 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<OpenPlatformVersionInfoVo>
* @Description: 上传提审素材
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("上传提审素材")
@PostMapping("/uploadMediaToCodeAudit/{authorizerAppid}")
public R<WxMaAuditMediaUploadResult> 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<java.util.List<me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate>>
*/
@ApiOperation("获取模板列表")
@GetMapping("/getTemplateList")
public R<List<WxOpenMaCodeTemplate>> getTemplateList(@RequestParam("templateType")Integer templateType) {
try {
List<WxOpenMaCodeTemplate> templateList = wxOpenService.getWxOpenComponentService().getTemplateList(templateType);
return R.ok(templateList);
} catch (WxErrorException e) {
throw new ServiceException(e.getMessage());
}
}
/**
* @Description: 获取草稿箱列表
* @return R<Void>
* @author DB
* @Date: 2023/6/16 0016 17:34
*/
@ApiOperation("获取草稿箱列表")
@GetMapping("/getTemplateDraftList")
public R<List<WxOpenMaCodeTemplate>> getTemplateDraftList() {
try {
List<WxOpenMaCodeTemplate> 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<java.lang.Void>
*/
@ApiOperation("将草稿添加到模板库")
@PostMapping("/addToTemplate")
public R<Void> 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<Void>
* @author DB
* @Date: 2023/6/27 0027 14:28
*/
@ApiOperation("删除代码模板")
@DeleteMapping("/deleteTemplate/{templateId}")
public R<Void> deleteTemplate(@PathVariable Integer templateId) {
try {
wxOpenService.getWxOpenComponentService().deleteTemplate(templateId);
} catch (WxErrorException e) {
throw new ServiceException(e.getMessage());
}
return R.ok();
}
}

View File

@ -18,6 +18,11 @@
<groupId>com.cpop</groupId>
<artifactId>Cpop-Core</artifactId>
</dependency>
<!--微信开放平台-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-open</artifactId>
</dependency>
<!--微信小程序-->
<dependency>
<groupId>com.github.binarywang</groupId>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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

View File

@ -150,6 +150,12 @@
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<!--微信开放平台-->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-open</artifactId>
<version>${wechat-java.version}</version>
</dependency>
<!--微信小程序-->
<dependency>
<groupId>com.github.binarywang</groupId>