he2802 2 gadi atpakaļ
vecāks
revīzija
e50648470f

+ 10 - 6
zhongzheng-common/src/main/java/com/zhongzheng/common/core/redis/RedisCache.java

@@ -51,10 +51,12 @@ public class RedisCache
      */
     public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
     {
-        String tenantId = ServletUtils.getRequest().getHeader("TenantId");
         String unionKey = key;
-        if(Validator.isNotEmpty(tenantId)){
-            unionKey = tenantId + key;
+        if(Validator.isNotEmpty(ServletUtils.getRequest())){
+            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            if(Validator.isNotEmpty(tenantId)){
+                unionKey = tenantId + key;
+            }
         }
         redisTemplate.opsForValue().set(unionKey, value, timeout, timeUnit);
 
@@ -94,10 +96,12 @@ public class RedisCache
     public <T> T getCacheObject(final String key)
     {
         ValueOperations<String, T> operation = redisTemplate.opsForValue();
-        String tenantId = ServletUtils.getRequest().getHeader("TenantId");
         String unionKey = key;
-        if(Validator.isNotEmpty(tenantId)){
-            unionKey = tenantId + key;
+        if(Validator.isNotEmpty(ServletUtils.getRequest())){
+            String tenantId = ServletUtils.getRequest().getHeader("TenantId");
+            if(Validator.isNotEmpty(tenantId)){
+                unionKey = tenantId + key;
+            }
         }
         return operation.get(unionKey);
     }

+ 2 - 1
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/SecurityUtils.java

@@ -118,7 +118,8 @@ public class SecurityUtils
      */
     public static boolean isAdmin(Long userId)
     {
-        LoginUser user = (LoginUser) getAuthentication().getPrincipal();
+        LoginUser user= (LoginUser) getAuthentication().getPrincipal();
         return user != null && "admin".equals(user.getUser().getUserName());
+     //   return userId != null && 1L == userId;
     }
 }

+ 48 - 5
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -24,6 +24,7 @@ import com.zhongzheng.modules.alisms.service.IAliSmsService;
 import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
 import com.zhongzheng.modules.goods.service.IGoodsService;
 import com.zhongzheng.modules.goods.vo.GoodsVo;
+import com.zhongzheng.modules.system.service.ISysConfigService;
 import com.zhongzheng.modules.user.bo.UserWxFollowAddBo;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
@@ -56,23 +57,23 @@ public class WxLoginService implements IWxLoginService {
     @Autowired
     private WxTokenService wxTokenService;
 
-    @Value("${wx.small.appid}")
+  //  @Value("${wx.small.appid}")
     private String appid;
 
-    @Value("${wx.small.appsecret}")
+ //   @Value("${wx.small.appsecret}")
     private String appsrcret;
 
     private String wxAuthUrl = "https://api.weixin.qq.com/sns/jscode2session";
 
     private String wxAuthParam = "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
 
-    @Value("${wx.gzh.appid}")
+  //  @Value("${wx.gzh.appid}")
     private String gzh_appid;
 
-    @Value("${wx.scanLogin.host}")
+  //  @Value("${wx.scanLogin.host}")
     private String scanLoginHost;
 
-    @Value("${wx.gzh.appsecret}")
+ //   @Value("${wx.gzh.appsecret}")
     private String gzh_appsrcret;
 
     @Value("${wx.gzh.studyNoteTpId}")
@@ -149,8 +150,21 @@ public class WxLoginService implements IWxLoginService {
     @Autowired
     private IGoodsService iGoodsService;
 
+    @Autowired
+    private ISysConfigService configService;
+
+    public void initData(){
+        appid = configService.selectConfigByKey("wx.small.appid");
+        appsrcret = configService.selectConfigByKey("wx.small.appsecret");
+        gzh_appsrcret = configService.selectConfigByKey("wx.gzh.appsecret");
+        gzh_appid = configService.selectConfigByKey("wx.gzh.appid");
+        scanLoginHost = configService.selectConfigByKey("wx.scanLogin.host");
+
+    }
+
 
     public Map<String, String> test_login() {
+        initData();
         String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
         User user = iUserService.queryByUnionId(unionId);
         ClientLoginUser loginUser = new ClientLoginUser();
@@ -163,6 +177,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public Map<String, Object> pcLoginUrl() {
+        initData();
         String scanCode = ToolsUtils.getCharAndNumr(6);
         String key = "SCAN_LOGIN_" + scanCode;
         String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
@@ -196,6 +211,7 @@ public class WxLoginService implements IWxLoginService {
      * @return
      */
     public Map<String, Object> checkPcLogin(String scanCode) {
+        initData();
         String key = "SCAN_LOGIN_" + scanCode;
         String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
         Long userId = redisCache.getCacheObject(key);
@@ -221,6 +237,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Transactional(rollbackFor = Exception.class)
     public Map<String, Object> login(WxLoginBody loginBody) {
+        initData();
         User user = getWxUnionIdUser(loginBody);
         if (user == null) {
             throw new CustomException("登录错误");
@@ -236,6 +253,7 @@ public class WxLoginService implements IWxLoginService {
 
 
     public Map<String, String> smallTel(WxLoginBody loginBody) {
+        initData();
         User user = getWxUnionIdUser(loginBody);
         if (user == null) {
             throw new CustomException("登录错误");
@@ -249,6 +267,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public Map<String, String> gzh_login(WxLoginBody loginBody) {
+        initData();
         User user = getWxGzhUnionIdUser(loginBody);
         if (user == null) {
             throw new CustomException("登录错误");
@@ -262,6 +281,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public String refreshToken(String userAccount) {
+        initData();
         User user = iUserService.queryByAccount(userAccount);
         if (user == null) {
             throw new CustomException("userAccount不存在");
@@ -283,6 +303,7 @@ public class WxLoginService implements IWxLoginService {
      * @return
      */
     public Boolean register_small(String openId, String unionId, String tel, String inviteCode, String shareCode) {
+        initData();
         User bo = new User();
         bo.setOpenId(openId);
         bo.setUnionId(unionId);
@@ -319,6 +340,7 @@ public class WxLoginService implements IWxLoginService {
 
     //小程序获取用户openid
     public String getWxOpenId(WxLoginBody loginBody, Long userId) {
+        initData();
         LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
         lqw.eq(User::getUserId, userId);
         User user = iUserService.getOne(lqw);
@@ -339,6 +361,7 @@ public class WxLoginService implements IWxLoginService {
 
     //小程序获取用户信息
     public User getWxUnionIdUser(WxLoginBody loginBody) {
+        initData();
         String param = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
         String resultString = HttpUtils.sendGet(wxAuthUrl, param);
         //解析json
@@ -384,6 +407,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public String getWxSmallAccessToken() {
+        initData();
         String key = "WX_SMALL_ACCESS_TOKEN";
         String accessToken = redisCache.getCacheObject(key);
         if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
@@ -404,6 +428,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public String getWxGzhAccessToken() {
+        initData();
         String key = "WX_GZH_ACCESS_TOKEN";
         String accessToken = redisCache.getCacheObject(key);
         if (Validator.isEmpty(accessToken) || accessToken.equals("null")) {
@@ -425,6 +450,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public String getWxGzhUserList(String nextOpenid) {
+        initData();
         String accessToken = getWxGzhAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("accessToken 错误");
@@ -460,6 +486,7 @@ public class WxLoginService implements IWxLoginService {
     }
 
     public String getWxGzhUserCgiInfo(String openid) {
+        initData();
         String accessToken = getWxGzhAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("accessToken 错误");
@@ -478,6 +505,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendSmallTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -528,6 +556,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getLiveEnCode(SectionWatchPerBo watchPer) {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
         String url = small_wxEnCodeUrl + "?" + param;
@@ -559,6 +588,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getBackEnCode(SectionWatchPerBo watchPer) {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
         String url = small_wxEnCodeUrl + "?" + param;
@@ -576,6 +606,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendQdyTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -631,6 +662,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendQdySubTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -691,6 +723,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendQdySubStatusTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -745,6 +778,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendQdyExamTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -795,6 +829,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendQdyExamStatusTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -845,6 +880,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String sendSignatureTpMsg(String openId, Map<String, String> paramMap) {
+        initData();
         String accessToken = getWxSmallAccessToken();
         if (Validator.isEmpty(accessToken)) {
             throw new CustomException("小程序accessToken 错误");
@@ -895,6 +931,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getActivityApplyCode(Long activityId) {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
         String url = small_wxEnCodeUrl + "?" + param;
@@ -921,6 +958,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getTopicEnCode(Long topicId) {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
         String url = small_wxEnCodeUrl + "?" + param;
@@ -948,6 +986,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String shareGoodsCode(WxShareGoodsBo bo) {
+        initData();
         GoodsVo goodsVo = iGoodsService.queryById(bo.getGoodsId());
         if(Validator.isEmpty(goodsVo)){
             throw new CustomException("商品ID错误");
@@ -993,6 +1032,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public WxInfoBo getWxInfo(WxInfoQuery query) {
+        initData();
         Long time = System.currentTimeMillis();
         String nonceStr = UUID.randomUUID().toString();
         String ticket = "";
@@ -1030,6 +1070,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getWxSmallLink() {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_LinkParam, wxGzhAccessToken);
         String url = small_LinkUrl + "?" + param;
@@ -1060,6 +1101,7 @@ public class WxLoginService implements IWxLoginService {
 
     @Override
     public String getWxSmallStudyCentreLink() {
+        initData();
         String wxGzhAccessToken = getWxSmallAccessToken();
         String param = String.format(small_LinkParam, wxGzhAccessToken);
         String url = small_LinkUrl + "?" + param;
@@ -1106,6 +1148,7 @@ public class WxLoginService implements IWxLoginService {
 
     //公众号获取用户信息
     public User getWxGzhUnionIdUser(WxLoginBody loginBody) {
+        initData();
         String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
         String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
         //解析json

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/service/ISysConfigService.java

@@ -27,6 +27,8 @@ public interface ISysConfigService extends IService<SysConfig> {
      */
     public String selectConfigByKey(String configKey);
 
+    public String selectConfigByKeyNoCache(String configKey);
+
     /**
      * 查询参数配置列表
      *

+ 10 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/service/impl/SysConfigServiceImpl.java

@@ -78,6 +78,16 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
         return StrUtil.EMPTY;
     }
 
+    @Override
+    public String selectConfigByKeyNoCache(String configKey) {
+        SysConfig retConfig = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>()
+                .eq(SysConfig::getConfigKey, configKey));
+        if (Validator.isNotNull(retConfig)) {
+            return retConfig.getConfigValue();
+        }
+        return StrUtil.EMPTY;
+    }
+
     /**
      * 查询参数配置列表
      *

+ 38 - 7
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/service/impl/WxPayServiceImpl.java

@@ -62,6 +62,7 @@ import com.zhongzheng.modules.polyv.mapper.PolyvVideoMapper;
 import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
 import com.zhongzheng.modules.polyv.vo.PolyvVideoQuerVo;
 import com.zhongzheng.modules.polyv.vo.PolyvVideoVo;
+import com.zhongzheng.modules.system.service.ISysConfigService;
 import com.zhongzheng.modules.user.bo.OrderPossessUserAddBo;
 import com.zhongzheng.modules.user.bo.UserExamGoodsAddBo;
 import com.zhongzheng.modules.user.bo.UserExamGoodsQueryBo;
@@ -78,6 +79,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.PostConstruct;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -97,25 +99,25 @@ import static com.squareup.okhttp.internal.Util.md5Hex;
 @Service
 public class WxPayServiceImpl implements IWxPayService {
 
-    @Value("${wx.small.appid}")
+  //  @Value("${wx.small.appid}")
     private String appid;
 
-    @Value("${wx.gzh.appid}")
+  //  @Value("${wx.gzh.appid}")
     private String gzhAppid;
 
-    @Value("${wx.gzh.appsecret}")
+ //   @Value("${wx.gzh.appsecret}")
     private String gzh_appsrcret;
 
-    @Value("${wx.wepay.mchid}")
+ //   @Value("${wx.wepay.mchid}")
     private String mchid;
 
-    @Value("${wx.wepay.key}")
+ //   @Value("${wx.wepay.key}")
     private String key;
 
-    @Value("${wx.wepay.appsecret}")
+ //   @Value("${wx.wepay.appsecret}")
     private String appsecret;
 
-    @Value("${wx.wepay.notifyUrl}")
+ //   @Value("${wx.wepay.notifyUrl}")
     private String notifyUrl;
 
     @Value("${oldStudySys.sharePath}")
@@ -175,12 +177,28 @@ public class WxPayServiceImpl implements IWxPayService {
     @Autowired
     private IOrderShareMoneyService iOrderShareMoneyService;
 
+    @Autowired
+    private ISysConfigService configService;
+
     private String gzh_tokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
 
     private String gzh_tokenParam = "grant_type=client_credential&appid=%s&secret=%s";
 
+
+    public void initData(){
+        appid = configService.selectConfigByKey("wx.small.appid");
+        gzhAppid = configService.selectConfigByKey("wx.gzh.appid");
+        gzh_appsrcret = configService.selectConfigByKey("wx.gzh.appsecret");
+        mchid = configService.selectConfigByKey("wx.wepay.mchid");
+        key = configService.selectConfigByKey("wx.wepay.key");
+        appsecret = configService.selectConfigByKey("wx.wepay.appsecret");
+        notifyUrl =  configService.selectConfigByKey("wx.wepay.notifyUrl");
+    }
+
+
     @Override
     public Map<String, String> payment(String out_trade_no, String openid, String body, BigDecimal price) {
+        initData();
         WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
         BigDecimal unit = new BigDecimal(100);
         price = price.multiply(unit);
@@ -217,7 +235,12 @@ public class WxPayServiceImpl implements IWxPayService {
 
     @Override
     public Map<String, String> paymentPc(String out_trade_no, String openid, String body, BigDecimal price) {
+        initData();
         WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
+        System.out.println(55678);
+        System.out.println(appid);
+        System.out.println(mchid);
+        System.out.println(key);
         BigDecimal unit = new BigDecimal(100);
         price = price.multiply(unit);
         try {
@@ -235,6 +258,7 @@ public class WxPayServiceImpl implements IWxPayService {
             String TenantId = ServletUtils.getRequest().getHeader("TenantId");
             data.put("attach", TenantId);
             Map<String, String> resp = wxpay.unifiedOrder(data);
+            System.out.println(resp);
             Map<String, String> result = new HashMap<>();
             String code_url = resp.get("code_url");
             if (Validator.isEmpty(code_url)) {
@@ -260,6 +284,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
     @Override
     public Map<String, String> paymentGzh(String out_trade_no, String openid, String body, BigDecimal price, String url) {
+        initData();
         WxSmallConfig config = new WxSmallConfig(gzhAppid, mchid, key);
         try {
             WXPay wxpay = new WXPay(config);
@@ -297,6 +322,7 @@ public class WxPayServiceImpl implements IWxPayService {
     }
 
     public String wx_config_sign(Map<String, String> result, String url) {
+        initData();
         String jsapi_ticket = wx_get_jsapi_ticket();
         if (!Validator.isNotNull(jsapi_ticket)) {
             throw new CustomException("jsapi_ticket错误" + jsapi_ticket);
@@ -308,6 +334,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
     @Override
     public String paymentCallBack(String notifyData) {
+        initData();
         String xmlBack = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[报文为空]]></return_msg></xml> ";
         WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
         try {
@@ -347,6 +374,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
 
     public String wx_get_jsapi_ticket() {
+        initData();
         String key = "gzh_ticket";
         String ticket = redisCache.getCacheObject(key);
         if (!Validator.isNotNull(ticket)) {
@@ -364,6 +392,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
     //获取微信公众号access_token
     public String wx_get_token() {
+        initData();
         String key = "gzh_access_token";
         String access_token = redisCache.getCacheObject(key);
         if (!Validator.isNotNull(access_token)) {
@@ -457,6 +486,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
     @Override
     public boolean closeWxPcOrder(String out_trade_no) {
+        initData();
         WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
         try {
             WXPay wxpay = new WXPay(config);
@@ -636,6 +666,7 @@ public class WxPayServiceImpl implements IWxPayService {
 
     @Override
     public Map<String, String> refund(String out_refund_no, String transaction_id, BigDecimal refund_fee, BigDecimal total_fee) {
+        initData();
         WxSmallConfig config = new WxSmallConfig(appid, mchid, key);
         BigDecimal unit = new BigDecimal(100);
         refund_fee = refund_fee.multiply(unit);