From bbe0a2fd03063316e50cf141986bda984599bbda Mon Sep 17 00:00:00 2001 From: 935090232@qq.com <ak473600000> Date: Tue, 22 Feb 2022 23:41:42 +0800 Subject: [PATCH] Merge branch 'developer' --- zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java | 66 ++++++++++++++++++-------------- 1 files changed, 37 insertions(+), 29 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..e055e95 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,24 @@ 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 +34,6 @@ */ private static String accessToken = ""; - private static String appid = ""; - private static String secret = ""; /** @@ -46,34 +45,43 @@ * @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); + } + + /** + * 获取管理端小程序登录地址 + * + * @param code + * @return + */ + public String getManagerXcxLoginUrl(String code) { + String wechatLoginUrl = PropertiesUtil.getString(WECHAT_LOGIN_URL); + String appId = PropertiesUtil.getString(AppConstance.MINI_PROGRAM_MANAGER_APP_ID); + String secret = PropertiesUtil.getString(AppConstance.MINI_PROGRAM_MANAGER_SECRET); + + return String.format(wechatLoginUrl, appId, secret, 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(); } - - /** * 清空token @@ -83,7 +91,7 @@ accessToken = ""; } - public static String getAccessToken() throws IOException { + public String getAccessToken(Long companyId) throws IOException { if (isTokenInvalid()) { synchronized (accessToken) { @@ -93,7 +101,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