|
@@ -458,6 +458,68 @@ public class WechatAccountController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 创建微信公众号菜单
|
|
|
|
+ @RequestMapping("/deleteMenu")
|
|
|
|
+ public HttpRespMsg deleteMenu(Integer companyId) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ WechatAccount wechatAccount = wechatAccountService.getOne(new QueryWrapper<WechatAccount>().eq("company_id", companyId));
|
|
|
|
+ if (wechatAccount==null){
|
|
|
|
+ httpRespMsg.setError("该公司没有配置公众号相关的参数");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ String accessToken = wechatAccountService.getAccessToken(companyId, wechatAccount.getAppId());
|
|
|
|
+ log.info("accessToken==>{}", accessToken);
|
|
|
|
+ boolean deleted = deleteMenuWithMiniProgram(accessToken);
|
|
|
|
+ if (deleted){
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }else {
|
|
|
|
+ httpRespMsg.setError("删除失败");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建包含小程序链接的菜单
|
|
|
|
+ * @param accessToken 微信access_token
|
|
|
|
+ * @return 是否创建成功
|
|
|
|
+ */
|
|
|
|
+ public boolean deleteMenuWithMiniProgram(String accessToken) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 设置请求头
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
+
|
|
|
|
+ // 创建请求实体
|
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<>(headers);
|
|
|
|
+
|
|
|
|
+ // 构建完整URL
|
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + accessToken;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // 发送POST请求
|
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.exchange(
|
|
|
|
+ requestUrl,
|
|
|
|
+ HttpMethod.GET,
|
|
|
|
+ requestEntity,
|
|
|
|
+ String.class
|
|
|
|
+ );
|
|
|
|
+ log.info("responseEntity==>" + responseEntity);
|
|
|
|
+
|
|
|
|
+ // 解析响应
|
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
|
+ JSONObject jsonResult = JSON.parseObject(responseEntity.getBody());
|
|
|
|
+ log.info("解析响应"+jsonResult.toJSONString());
|
|
|
|
+ return jsonResult.getInteger("errcode") == 0;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建包含小程序链接的菜单
|
|
* 创建包含小程序链接的菜单
|
|
* @param accessToken 微信access_token
|
|
* @param accessToken 微信access_token
|