All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitlab.summercattle.addons.wechat.officialaccounts.controller.OfficialAccountsMenuController Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitlab.summercattle.addons.wechat.officialaccounts.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.gitlab.summercattle.addons.wechat.officialaccounts.menu.MenuBar;
import com.gitlab.summercattle.addons.wechat.officialaccounts.service.OfficialAccountsService;
import com.gitlab.summercattle.commons.exception.CommonException;
import com.gitlab.summercattle.commons.resp.Response;

/**
 * 微信公众号菜单控制器
 * @author orange
 *
 */
@RestController
@RequestMapping("/WeChat/menu")
public class OfficialAccountsMenuController {

	@Autowired
	private OfficialAccountsService officialAccountsService;

	@PostMapping(path = "/create", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response createMenu(@RequestParam("source") String source, @RequestBody MenuBar menuBar) {
		try {
			officialAccountsService.createMenu(source, menuBar);
			return new Response();
		}
		catch (CommonException e) {
			return new Response(e.getCode(), e.getMessage());
		}
	}

	@GetMapping(path = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response deleteMenu(@RequestParam("source") String source) {
		try {
			officialAccountsService.deleteMenu(source);
			return new Response();
		}
		catch (CommonException e) {
			return new Response(e.getCode(), e.getMessage());
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy