lodsve.wechat.api.menu.WeChatMenuService Maven / Gradle / Ivy
/*
* Copyright (C) 2018 Sun.Hao
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package lodsve.wechat.api.menu;
import com.fasterxml.jackson.core.type.TypeReference;
import lodsve.wechat.beans.Menu;
import lodsve.wechat.core.WeChat;
import lodsve.wechat.core.WeChatRequest;
import lodsve.wechat.core.WeChatUrl;
import lodsve.wechat.exception.WeChatException;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* 菜单操作.
*
* @author sunhao([email protected])
* @version V1.0, 16/2/23 下午4:17
*/
@Component
public class WeChatMenuService {
public static final int MENU_LENGTH = 3;
/**
* 创建菜单(会删除原来的菜单)
*
* @param menus 需要创建的菜单
*/
public void create(Menu... menus) {
if (ArrayUtils.isEmpty(menus)) {
return;
}
if (menus.length > MENU_LENGTH) {
throw new WeChatException(107001, "微信按钮个数限制小于等于3个");
}
for (Menu m : menus) {
List