From aaaf4564b44adf5b9a47843b27fbd68ea56c9a52 Mon Sep 17 00:00:00 2001 From: jyy <935090232@qq.com> Date: Mon, 08 Mar 2021 13:57:56 +0800 Subject: [PATCH] Merge branch 'api' into hive2.0 --- zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java | 50 +++++++++++++++++++++++--------------------------- 1 files changed, 23 insertions(+), 27 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java index 7f5344c..2b1bfb8 100644 --- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java +++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java @@ -1,23 +1,25 @@ package com.matrix.system.shopXcx.api; -import com.matrix.core.tools.LogUtil; -import com.matrix.core.tools.PropertiesUtil; -import com.matrix.core.tools.StringUtils; import com.matrix.component.tools.HttpRequest; import com.matrix.component.tools.HttpResponse; +import com.matrix.core.tools.LogUtil; +import com.matrix.core.tools.PropertiesUtil; +import com.matrix.system.common.bean.BusParameterSettings; +import com.matrix.system.common.constance.AppConstance; +import com.matrix.system.common.dao.BusParameterSettingsDao; import net.sf.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import java.io.IOException; +@Service public class WeChatApiTools { - /** - * 小程序秘钥 - */ - private static final String XCX_SECRET = "xcx_secret"; - /** - * 小程序appid - */ - private static final String XCX_APPID = "xcx_appid"; + + + @Autowired + private BusParameterSettingsDao busParameterSettingsDao; + /** * 微信登录url */ @@ -33,8 +35,6 @@ */ private static String accessToken = ""; - private static String appid = ""; - private static String secret = ""; /** @@ -46,31 +46,27 @@ * @param code * @return */ - public static String getXcxLoginUrl(String code) { + public String getXcxLoginUrl(String code,Long companyId) { String wechatLoginUrl = PropertiesUtil.getString(WECHAT_LOGIN_URL); - return String.format(wechatLoginUrl, getAppid(), getSecret(), code); + return String.format(wechatLoginUrl, getAppid(companyId), getSecret(companyId), code); } /** * 获取小程序APPId * @return */ - public static String getAppid(){ - if(StringUtils.isBlank(appid)){ - appid = PropertiesUtil.getString(XCX_APPID); - } - return appid; + public String getAppid(Long companyId){ + BusParameterSettings appId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId); + return appId.getParamValue(); } /** * 获取小程序秘钥 * @return */ - public static String getSecret(){ - if(StringUtils.isBlank(secret)){ - secret = PropertiesUtil.getString(XCX_SECRET); - } - return secret; + public String getSecret(Long companyId){ + BusParameterSettings secret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_SECRET, companyId); + return secret.getParamValue(); } @@ -83,7 +79,7 @@ accessToken = ""; } - public static String getAccessToken() throws IOException { + public String getAccessToken(Long companyId) throws IOException { if (isTokenInvalid()) { synchronized (accessToken) { @@ -93,7 +89,7 @@ HttpResponse result = null; result = reqObj .sendHttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" - + getAppid() + "&secret=" + getSecret(), null); + + getAppid(companyId) + "&secret=" + getSecret(companyId), null); JSONObject json = JSONObject.fromObject(result.getDataString()); String access_token = json.getString("access_token"); accessToken = access_token; -- Gitblit v1.9.1