|
@@ -15,6 +15,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
|
|
+import com.qmth.boot.core.solar.model.WxappAccessToken;
|
|
|
|
+import com.qmth.boot.core.solar.service.SolarService;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.uuid.FastUUID;
|
|
import com.qmth.boot.tools.uuid.FastUUID;
|
|
|
|
|
|
@@ -22,7 +24,6 @@ import cn.com.qmth.mps.bean.User;
|
|
import cn.com.qmth.mps.config.SysProperty;
|
|
import cn.com.qmth.mps.config.SysProperty;
|
|
import cn.com.qmth.mps.entity.SchoolEntity;
|
|
import cn.com.qmth.mps.entity.SchoolEntity;
|
|
import cn.com.qmth.mps.entity.UserEntity;
|
|
import cn.com.qmth.mps.entity.UserEntity;
|
|
-import cn.com.qmth.mps.entity.WxappAccessTokenEntity;
|
|
|
|
import cn.com.qmth.mps.entity.WxappInfoEntity;
|
|
import cn.com.qmth.mps.entity.WxappInfoEntity;
|
|
import cn.com.qmth.mps.enums.Role;
|
|
import cn.com.qmth.mps.enums.Role;
|
|
import cn.com.qmth.mps.exception.ParameterExceptions;
|
|
import cn.com.qmth.mps.exception.ParameterExceptions;
|
|
@@ -54,7 +55,10 @@ public class AuthServiceImpl implements AuthorizationService<User>, AuthService
|
|
private SysProperty sysProperty;
|
|
private SysProperty sysProperty;
|
|
@Autowired
|
|
@Autowired
|
|
private WxappInfoService wxappInfoService;
|
|
private WxappInfoService wxappInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SolarService solarService;
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public AdminLoginVo loginWxAppCode(String loginCode) {
|
|
public AdminLoginVo loginWxAppCode(String loginCode) {
|
|
JSONObject auth=getAuthorization(loginCode);
|
|
JSONObject auth=getAuthorization(loginCode);
|
|
@@ -150,33 +154,43 @@ public class AuthServiceImpl implements AuthorizationService<User>, AuthService
|
|
sessionService.updateUserSession(user);
|
|
sessionService.updateUserSession(user);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void modifyWxappAccessToken() {
|
|
public void modifyWxappAccessToken() {
|
|
- WxappAccessTokenEntity token = wxappAccessTokenService.getWxappAccessToken();
|
|
|
|
|
|
+ WxappAccessToken token = wxappAccessTokenService.getWxappAccessToken();
|
|
long now = System.currentTimeMillis();
|
|
long now = System.currentTimeMillis();
|
|
- if (StringUtils.isEmpty(token.getAccessToken()) || token.getExpiresTime() - now <= 15 * 60 * 1000) {
|
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
|
- params.put("appid", sysProperty.getWxappAppid());
|
|
|
|
- params.put("secret", sysProperty.getWxappSecret());
|
|
|
|
- params.put("grant_type", "client_credential");
|
|
|
|
- String ret;
|
|
|
|
- try {
|
|
|
|
- ret = HttpUtil.httpsActionGet("https://api.weixin.qq.com/cgi-bin/token", null, params);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new StatusException("获取失败", e);
|
|
|
|
- }
|
|
|
|
- JSONObject jo = JSONObject.fromObject(ret);
|
|
|
|
- if (jo.containsKey("errcode")) {
|
|
|
|
- throw new StatusException("获取失败," + jo.getString("errmsg"));
|
|
|
|
- }
|
|
|
|
- int ex = jo.getInt("expires_in");
|
|
|
|
- String at = jo.getString("access_token");
|
|
|
|
- token.setAccessToken(at);
|
|
|
|
- token.setExpiresTime(now + ex * 1000);
|
|
|
|
- wxappAccessTokenService.updateById(token);
|
|
|
|
|
|
+ if (StringUtils.isEmpty(token.getAccessToken()) || token.getExpireTime() - now <= 0) {
|
|
|
|
+ WxappAccessToken wt=solarService.getWxappAccessToken(sysProperty.getWxappAppid());
|
|
|
|
+ wxappAccessTokenService.saveWxappAccessToken(wt.getAccessToken(),wt.getExpireTime());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// @Override
|
|
|
|
+// public void modifyWxappAccessToken() {
|
|
|
|
+// WxappAccessTokenEntity token = wxappAccessTokenService.getWxappAccessToken();
|
|
|
|
+// long now = System.currentTimeMillis();
|
|
|
|
+// if (StringUtils.isEmpty(token.getAccessToken()) || token.getExpiresTime() - now <= 15 * 60 * 1000) {
|
|
|
|
+// Map<String, String> params = new HashMap<>();
|
|
|
|
+// params.put("appid", sysProperty.getWxappAppid());
|
|
|
|
+// params.put("secret", sysProperty.getWxappSecret());
|
|
|
|
+// params.put("grant_type", "client_credential");
|
|
|
|
+// String ret;
|
|
|
|
+// try {
|
|
|
|
+// ret = HttpUtil.httpsActionGet("https://api.weixin.qq.com/cgi-bin/token", null, params);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// throw new StatusException("获取失败", e);
|
|
|
|
+// }
|
|
|
|
+// JSONObject jo = JSONObject.fromObject(ret);
|
|
|
|
+// if (jo.containsKey("errcode")) {
|
|
|
|
+// throw new StatusException("获取失败," + jo.getString("errmsg"));
|
|
|
|
+// }
|
|
|
|
+// int ex = jo.getInt("expires_in");
|
|
|
|
+// String at = jo.getString("access_token");
|
|
|
|
+// token.setAccessToken(at);
|
|
|
|
+// token.setExpiresTime(now + ex * 1000);
|
|
|
|
+// wxappAccessTokenService.updateById(token);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|