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

com.gitlab.summercattle.addons.wechat.officialaccounts.menu.button.MiniProgramButton 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.menu.button;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson2.JSONObject;
import com.gitlab.summercattle.addons.wechat.miniprogram.configure.MiniProgramConfigProperties;
import com.gitlab.summercattle.addons.wechat.miniprogram.configure.MiniProgramApplication;
import com.gitlab.summercattle.addons.wechat.officialaccounts.menu.AbstractButton;
import com.gitlab.summercattle.addons.wechat.officialaccounts.menu.ButtonType;
import com.gitlab.summercattle.addons.wechat.utils.ApplicationUtils;
import com.gitlab.summercattle.commons.aop.context.SpringContext;
import com.gitlab.summercattle.commons.exception.CommonException;

/**
 * 小程序按钮
 * @author orange
 *
 */
public class MiniProgramButton extends AbstractButton {

	private static final long serialVersionUID = 1L;

	private String url;

	private String source;

	private String pagePath;

	public MiniProgramButton(String name, String url, String source, String pagePath) {
		super(name);
		this.url = url;
		this.source = source;
		this.pagePath = pagePath;
	}

	@Override
	public ButtonType getType() {
		return ButtonType.MiniProgram;
	}

	@Override
	public void setJson(JSONObject jsonObj) throws CommonException {
		if (StringUtils.isBlank(source)) {
			throw new CommonException("小程序来源为空");
		}
		MiniProgramConfigProperties miniProgramConfigProperties = SpringContext.getBean(MiniProgramConfigProperties.class);
		MiniProgramApplication miniProgramApplication = ApplicationUtils.getMiniProgramApplication(source, miniProgramConfigProperties);
		jsonObj.put("url", url);
		jsonObj.put("appid", miniProgramApplication.getAppId());
		jsonObj.put("pagepath", pagePath);
	}

	public String getUrl() {
		return url;
	}

	public String getSource() {
		return source;
	}

	public String getPagePath() {
		return pagePath;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy