From 1e1315f441b9fdceeb6c753a47f7122c6111dbec Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 10 Mar 2022 11:20:51 +0800
Subject: [PATCH] fix alpha config
---
zq-erp/src/main/java/com/matrix/system/shopXcx/api/WeChatApiTools.java | 80 +++++++++++++++++++++++++---------------
1 files changed, 50 insertions(+), 30 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..e002b34 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,36 @@
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.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.beans.factory.annotation.Value;
+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";
+
+
+
+ @Value("${wechar_login_url}")
+ private String wecharLoginUrl;
+
+ @Value("${xcx_manager_appid}")
+ private String xcxManagerAppid;
+
+ @Value("${xcx_manager_secret}")
+ private String xcxManagerSecret;
+
+
+ @Autowired
+ private BusParameterSettingsDao busParameterSettingsDao;
+
/**
* 微信登录url
*/
@@ -33,8 +46,6 @@
*/
private static String accessToken = "";
- private static String appid = "";
- private static String secret = "";
/**
@@ -46,34 +57,43 @@
* @param code
* @return
*/
- public static String getXcxLoginUrl(String code) {
- String wechatLoginUrl = PropertiesUtil.getString(WECHAT_LOGIN_URL);
- return String.format(wechatLoginUrl, getAppid(), getSecret(), code);
+ public String getXcxLoginUrl(String code,Long companyId) {
+ String wechatLoginUrl =wecharLoginUrl;
+
+ return String.format(wechatLoginUrl, getAppid(companyId), getSecret(companyId), code);
+ }
+
+ /**
+ * 获取管理端小程序登录地址
+ *
+ * @param code
+ * @return
+ */
+ public String getManagerXcxLoginUrl(String code) {
+ String wechatLoginUrl = wecharLoginUrl;
+ String appId =xcxManagerAppid;
+ String secret = xcxManagerSecret;
+
+ 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 +103,7 @@
accessToken = "";
}
- public static String getAccessToken() throws IOException {
+ public String getAccessToken(Long companyId) throws IOException {
if (isTokenInvalid()) {
synchronized (accessToken) {
@@ -93,7 +113,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