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

com.gitlab.summercattle.addons.wechat.utils.ApplicationUtils 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.utils;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.gitlab.summercattle.addons.wechat.miniprogram.configure.MiniProgramApplication;
import com.gitlab.summercattle.addons.wechat.miniprogram.configure.MiniProgramConfigProperties;
import com.gitlab.summercattle.addons.wechat.officialaccounts.configure.OfficialAccountsApplication;
import com.gitlab.summercattle.addons.wechat.officialaccounts.configure.OfficialAccountsConfigProperties;
import com.gitlab.summercattle.commons.exception.CommonException;

/**
 * 应用工具
 * @author orange
 *
 */
public class ApplicationUtils {

	public static MiniProgramApplication getMiniProgramApplication(String source, MiniProgramConfigProperties miniProgramConfigProperties)
			throws CommonException {
		if (StringUtils.isBlank(source)) {
			throw new CommonException("来源为空");
		}
		List applications = miniProgramConfigProperties.getApplications();
		MiniProgramApplication application = null;
		if (applications != null) {
			for (MiniProgramApplication lApplication : applications) {
				if (source.equalsIgnoreCase(lApplication.getSource())) {
					application = lApplication;
					break;
				}
			}
		}
		if (application == null) {
			throw new CommonException("微信小程序'" + source + "'的服务信息为空");
		}
		if (StringUtils.isBlank(application.getAppId())) {
			throw new CommonException("微信小程序'" + source + "'的应用Id为空");
		}
		if (StringUtils.isBlank(application.getSecret())) {
			throw new CommonException("微信小程序'" + source + "'的密钥为空");
		}
		return application;
	}

	public static OfficialAccountsApplication getOfficialAccountsApplication(String source,
			OfficialAccountsConfigProperties officialAccountsConfigProperties) throws CommonException {
		if (StringUtils.isBlank(source)) {
			throw new CommonException("来源为空");
		}
		List applications = officialAccountsConfigProperties.getApplications();
		OfficialAccountsApplication application = null;
		if (applications != null) {
			for (OfficialAccountsApplication lApplication : applications) {
				if (source.equalsIgnoreCase(lApplication.getSource())) {
					application = lApplication;
					break;
				}
			}
		}
		if (application == null) {
			throw new CommonException("微信服务公众号'" + source + "'的服务信息为空");
		}
		if (StringUtils.isBlank(application.getAppId())) {
			throw new CommonException("微信服务公众号'" + source + "'的应用为空");
		}
		if (StringUtils.isBlank(application.getSecret())) {
			throw new CommonException("微信服务公众号'" + source + "'的密钥为空");
		}
		if (StringUtils.isBlank(application.getToken())) {
			throw new CommonException("微信服务公众号'" + source + "'的令牌为空");
		}
		if (StringUtils.isBlank(application.getMessageAesKey())) {
			throw new CommonException("微信服务公众号'" + source + "'的消息密钥为空");
		}
		return application;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy