Skip to content

Commit

Permalink
添加微信后台支持模块.dev分支
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx committed Nov 28, 2018
1 parent 897d8ed commit 5630a3f
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public enum ResponseCodeFromWx {
* 不存在的菜单数据
*/
no_menu(46003, "不存在的菜单数据"),
/**
* 不合法的按钮个数
*/
error_menu_nums(40016, "不合法的按钮个数"),
// endregion
// region 业务响应码

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.yyx.wx.commons.util;

import org.yyx.domain.ResponseEntity;
import org.yyx.wx.commons.vo.pubnum.request.BaseRequest;

import static org.yyx.wx.commons.bussinessenum.ResponseCodeFromWx.getCode;
import static org.yyx.wx.commons.bussinessenum.ResponseCodeFromWx.isSuccess;

/**
* 返回结果工具类
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/10/19-23:05
*/
public class ResponseUtil {


/**
* 私有构造
*/
private ResponseUtil() {
}

/**
* 响应的封装
*
* @param baseRequest 微信请求本地服务器父类
* @return 封装结果
*/
public static ResponseEntity response(BaseRequest baseRequest) {
Integer errcode = baseRequest.getErrcode();
boolean success = isSuccess(errcode);
if (success) {
return org.yyx.util.http.ResponseUtil.success(baseRequest);
}
return new ResponseEntity(Long.valueOf(errcode), getCode(errcode).getDescription(), baseRequest.getErrmsg());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public class ButtonBean {
* 小程序的页面路径
*/
private String pagepath;

public ButtonBean[] getSub_button() {
for (ButtonBean buttonBean : sub_button) {
if (buttonBean != null) {
return sub_button;
}
}
return null;
}
}
38 changes: 26 additions & 12 deletions yyx-wx-manage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@
<scope>runtime</scope>
</dependency>
<!-- endregion -->
<!-- region beetlSQL dep -->
<!-- https://mvnrepository.com/artifact/com.ibeetl/beetlsql -->
<!--&lt;!&ndash; region beetlSQL dep &ndash;&gt;-->
<!--&lt;!&ndash; https://mvnrepository.com/artifact/com.ibeetl/beetlsql &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>com.ibeetl</groupId>-->
<!--<artifactId>beetlsql</artifactId>-->
<!--<version>${beetlsql}</version>-->
<!--</dependency>-->
<!--&lt;!&ndash; endregion &ndash;&gt;-->
<!--&lt;!&ndash; region beetl &ndash;&gt;-->
<!--&lt;!&ndash; https://mvnrepository.com/artifact/com.ibeetl/beetl &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>com.ibeetl</groupId>-->
<!--<artifactId>beetl</artifactId>-->
<!--<version>${beetl}</version>-->
<!--</dependency>-->
<!--&lt;!&ndash; endregion &ndash;&gt;-->
<!-- region beetlsql -->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetlsql</artifactId>
<version>${beetlsql}</version>
</dependency>
<!-- endregion -->
<!-- region beetl -->
<!-- https://mvnrepository.com/artifact/com.ibeetl/beetl -->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>${beetl}</version>
<artifactId>beetl-framework-starter</artifactId>
<version>RELEASE</version>
</dependency>
<!-- endregion -->
<!-- region swagger -->
Expand Down Expand Up @@ -105,6 +112,13 @@
<version>${fastjson}</version>
</dependency>
<!-- endregion -->
<!-- region configuration-processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- endregion -->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.yyx.wx.manage.menu.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
Expand All @@ -13,16 +13,15 @@
*/
@Component
@Data
@ConfigurationProperties(prefix = "wx.url.menu")
public class WxPubNumMenuConfig {

/**
* 查询自定义菜单的URL
*/
@Value("${wx.url.menu.search_menu}")
private String searchMenuList;
/**
* 创建自定义菜单URL
*/
@Value("${wx.url.menu.create_menu}")
private String createCustomMenu;
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.yyx.wx.manage.menu.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yyx.domain.ResponseEntity;
import org.yyx.util.http.ResponseUtil;
import org.yyx.wx.commons.util.ResponseUtil;
import org.yyx.wx.commons.vo.pubnum.request.BaseRequest;
import org.yyx.wx.commons.vo.pubnum.request.menu.MenuRequest;
import org.yyx.wx.commons.vo.pubnum.response.menu.CustomerMenuResponse;
import org.yyx.wx.manage.menu.service.IMenuService;

import javax.annotation.Resource;

import static org.yyx.wx.commons.bussinessenum.ResponseCodeFromWx.getCode;
import static org.yyx.wx.commons.bussinessenum.ResponseCodeFromWx.isSuccess;

/**
* 菜单相关的请求接口
* <p>
Expand All @@ -33,8 +35,18 @@ public class MenuController {
@Resource
private IMenuService menuService;

public ResponseEntity createMenu(MenuRequest menuRequest) {
return ResponseUtil.success();
/**
* 自定义菜单创建接口
*
* @param customerMenuResponse 自定义菜单
* @return 创建结果
*/
@PostMapping("add")
@ApiOperation(value = "创建一个新的自定义菜单", httpMethod = "POST", response = ResponseEntity.class)
@ApiImplicitParam(dataTypeClass = MenuRequest.class, value = "自定义菜单")
public ResponseEntity createMenu(@RequestBody CustomerMenuResponse customerMenuResponse) {
BaseRequest menuStatus = menuService.createMenu(customerMenuResponse);
return ResponseUtil.response(menuStatus);
}

/**
Expand All @@ -46,11 +58,6 @@ public ResponseEntity createMenu(MenuRequest menuRequest) {
@ApiOperation(value = "获取自定义菜单接口", httpMethod = "GET", response = ResponseEntity.class)
public ResponseEntity<MenuRequest> queryMenu() {
MenuRequest menuRequest = menuService.queryMenuList();
Integer errcode = menuRequest.getErrcode();
boolean success = isSuccess(errcode);
if (success) {
return ResponseUtil.success(menuRequest);
}
return new ResponseEntity<>(Long.valueOf(errcode), getCode(errcode).getDescription(), menuRequest.getErrmsg());
return ResponseUtil.response(menuRequest);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.yyx.wx.manage.menu.service;

import org.yyx.wx.commons.vo.pubnum.request.BaseRequest;
import org.yyx.wx.commons.vo.pubnum.request.menu.MenuRequest;
import org.yyx.wx.commons.vo.pubnum.response.menu.CustomerMenuResponse;

/**
* 菜单相关的业务接口
Expand All @@ -11,6 +13,14 @@
*/
public interface IMenuService {

/**
* 自定义菜单创建接口
*
* @param customerMenuResponse 要创建的菜单
* @return 结果
*/
BaseRequest createMenu(CustomerMenuResponse customerMenuResponse);

/**
* 自定义菜单查询接口
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;
import org.yyx.wx.acount.auth.service.IAccessTokenService;
import org.yyx.wx.commons.vo.pubnum.request.BaseRequest;
import org.yyx.wx.commons.vo.pubnum.request.auth.BaseAccessTokenRequest;
import org.yyx.wx.commons.vo.pubnum.request.menu.MenuRequest;
import org.yyx.wx.commons.vo.pubnum.response.menu.CustomerMenuResponse;
import org.yyx.wx.manage.menu.config.WxPubNumMenuConfig;
import org.yyx.wx.manage.menu.service.IMenuService;

Expand All @@ -14,7 +16,8 @@
/**
* 菜单业务接口实现
* <p>
*w
* w
*
* @author 叶云轩 at [email protected]
* @date 2018/10/14-22:40
*/
Expand All @@ -26,10 +29,27 @@ public class MenuServiceImpl implements IMenuService {
*/
@Resource
private WxPubNumMenuConfig wxPubNumMenuConfig;

/**
* Token业务接口
*/
@Resource
private IAccessTokenService accessTokenService;

/**
* 自定义菜单创建接口
*
* @param customerMenuResponse 要创建的菜单
* @return 结果
*/
@Override
public BaseRequest createMenu(CustomerMenuResponse customerMenuResponse) {
BaseAccessTokenRequest baseAccessToken = accessTokenService.getBaseAccessToken();
String createMenuStatus = HttpUtil.post(wxPubNumMenuConfig.getCreateCustomMenu()
+ baseAccessToken.getAccess_token()
, JSONObject.toJSONString(customerMenuResponse));
return JSONObject.parseObject(createMenuStatus, BaseRequest.class);
}

/**
* 查询自定义菜单方法
*
Expand All @@ -38,7 +58,8 @@ public class MenuServiceImpl implements IMenuService {
@Override
public MenuRequest queryMenuList() {
BaseAccessTokenRequest baseAccessToken = accessTokenService.getBaseAccessToken();
String menuListJson = HttpUtil.get(wxPubNumMenuConfig.getSearchMenuList() + baseAccessToken.getAccess_token());
String menuListJson = HttpUtil.get(wxPubNumMenuConfig.getSearchMenuList()
+ baseAccessToken.getAccess_token());
return JSONObject.parseObject(menuListJson, MenuRequest.class);
}
}
3 changes: 3 additions & 0 deletions yyx-wx-manage/src/main/resources/btsql-ext.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 产品模式
PRODUCT_MODE=false
CHARSET=UTF-8
1 change: 1 addition & 0 deletions yyx-wx-manage/src/main/resources/sql/table/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- 配置表
Loading

0 comments on commit 5630a3f

Please sign in to comment.