6XPz-=*&F1!qjxJ8u%0b
z>qqs9$DKQO@~BPMn4WOjOY6U>QwOUvZgBtj;eKDc^_$n65QAe?m&vmtv$kC!Xq%Fs
z+)y(D*(=|1NH~jjbb>AV&9_GTKDi6uK`J|A#=Iv?o^6)uFMa8kq)JXm?H3Kl6P`){
z!|4%SJedyPnl%9him=6&)6>)4R5q#6RnQP`y=GM)r*j)x@|G$!`D5`@H2nsNQWX-}
zTY%o`)zsjO3DS&z$^M@=M>+O>+tk$5x5UoO^V#8QK~=eVQN=11?t^|eL
zSlZJoV9qPdRR{X=MrqMYCfOCrb;}!$wQ3r$nqZ3;X+;KIMFQBq1!8D1kVn*MZ=&bV=Zny|1J;wko@01P;`iwp(WzdxBk*DJhwUeUpu?0Odciz1d
zdpOxWH^l#23)8FmMkjJcFKLZJRJl~i$J+nXhAg`Cc$z&;%UOXN&hNEWF&+QX!cJ5+^U;q}revP`=i&-a9#@$TS`}efhj=SWyz#l|Nxo(g3{`!%%
zr;ZP<_T;{dOgLboX);QSvR-^AIcaOpAw2y6q@|_#EqyP4&~8jtdz=2rEJIFQn*K`6DAUf=yeJN~i3FXAvJaPRn?jJ7PHaeM`BNtt{m5
zEND9~N$gB(}hA_?_Xnjn3vy9uPocHStzyJj(S~l(VpYVTM$vTd84zF
zok-Ic!`;eq;&x|!tUD4>DdE?~qzf#4p-^}Q?lNhkMo3`2C_@0<>-
zioopBA7nH$x$fZ%9IGw8a>j%b05LfBZ;l2@BxstjI}0q3a{QnA4n
z#c6
zN$t&w#^rZSNqOiN$3lC~Cl@k52K
z0&j$GT?)!((Dnux85dr>nVzHiki`*4UzpO~^V3s5!;25yvaxIFD^4A2+bt*IRnqth
zi-&?>)@Z(_EZ+Y5zpq5pvU?}N?N?QLUst}_-1sk_MV5bm{lPC#9J=2G1e)dkD??d@(M=2Av&}P#)BUovM=?tJAL5Q%R%#4BE+$1@q$KegH3UJw|lm%G;No~`VHKysm9(A
zFvBHx#W6ZuCvjvj%_%aOHmM1HjSVITF1^e(kRIPXSf}efN+6+xTkf|$$tZ`t
zXphsuvOK)TsBp&hsD#coOl&1aumh|-(=IMMyKJXbmMwk0R8mK_0=J&5z_m-WQXMG!
zT{R)X1YlAVc*QOizGS*`3|WoMmnHXbQXy_SKT7EvAF|cZ98z<5neJr++RN!M!T?yP2>|AsJ_AQoCef_D7`i%wi8-)o1_t_<|)FYi2UJ%b_^;NfEh8rxO674yqC0;urcVke`|<{?K!1|>CT!m&!Ds5&H04Oi
z^1R9LV_M+5sl6UuarWJ8%Wr1h>6xpABPu?N4G}vXx$>h)yQ@@zic!O#Pwz??2~le-
z-%YWbd%S!umI%B}YqPk?)dBAW3vd^uKEXX1L7$C^THYt~e>Zgek2Qo|QKJ`hzQw6r
SCxErffR>t`YK5|O*#82fxI5GU
literal 0
HcmV?d00001
diff --git a/tiesheng-login/src/main/resources/static/ding/index.html b/tiesheng-login/src/main/resources/static/ding/index.html
new file mode 100644
index 0000000..451c6cf
--- /dev/null
+++ b/tiesheng-login/src/main/resources/static/ding/index.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+ 钉钉授权
+
+
+
+
+
+
+
diff --git a/tiesheng-message/pom.xml b/tiesheng-message/pom.xml
index 97e877b..11463e2 100644
--- a/tiesheng-message/pom.xml
+++ b/tiesheng-message/pom.xml
@@ -6,7 +6,7 @@
com.tiesheng
tiesheng-parent
- 0.0.4
+ 0.0.5
tiesheng-message
@@ -18,15 +18,10 @@
-
- com.tiesheng
- tiesheng-ding
- ${project.parent.version}
-
com.tiesheng
- tiesheng-wxmp
+ tiesheng-platform
${project.parent.version}
diff --git a/tiesheng-wxmp/pom.xml b/tiesheng-platform/pom.xml
similarity index 67%
rename from tiesheng-wxmp/pom.xml
rename to tiesheng-platform/pom.xml
index 05e0d88..62bc495 100644
--- a/tiesheng-wxmp/pom.xml
+++ b/tiesheng-platform/pom.xml
@@ -6,10 +6,10 @@
com.tiesheng
tiesheng-parent
- 0.0.4
+ 0.0.5
- tiesheng-wxmp
+ tiesheng-platform
8
@@ -17,4 +17,12 @@
UTF-8
+
+
+ com.tiesheng
+ tiesheng-util
+ ${project.parent.version}
+
+
+
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/PlatformAutoImportSelector.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/PlatformAutoImportSelector.java
new file mode 100644
index 0000000..9c32826
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/PlatformAutoImportSelector.java
@@ -0,0 +1,10 @@
+package com.tiesheng.platform;
+
+
+import org.springframework.context.annotation.ComponentScan;
+
+@ComponentScan({
+ "com.tiesheng.platform.**.*",
+})
+public class PlatformAutoImportSelector {
+}
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/config/DingConfig.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java
similarity index 95%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/config/DingConfig.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java
index 4cc7b3c..6bebb4f 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/config/DingConfig.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/PlatformDingConfig.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.config;
+package com.tiesheng.platform.config.ding;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.TypeReference;
@@ -9,7 +9,7 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
-import com.tiesheng.ding.pojos.*;
+import com.tiesheng.platform.config.ding.bean.*;
import com.tiesheng.util.TimedCacheHelper;
import com.tiesheng.util.exception.ApiException;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -22,13 +22,12 @@ import java.util.function.Consumer;
* @author hao
*/
@Configuration
-@ConfigurationProperties(prefix = "tiesheng.ding")
-public class DingConfig {
+@ConfigurationProperties(prefix = "platform.ding")
+public class PlatformDingConfig {
private static final String CACHE_ACCESS_TOKEN = "cache_ding_access_token_";
private static final String CACHE_JSAPI_TICKET = "cache_ding_jsapi_ticket_";
-
private Map configs = MapUtil.newHashMap();
private DingConfigBean global;
@@ -240,12 +239,11 @@ public class DingConfig {
* @param content
* @param actionUrl
* @param userIds
- * @return
*/
- public String messageNotification(String service, String title, String content, String actionUrl, List userIds) {
+ public void messageNotification(String service, String title, String content, String actionUrl, List userIds) {
if (CollUtil.isEmpty(userIds)) {
- return "";
+ return;
}
DingConfigBean configBean = getConfigBean(service);
@@ -264,7 +262,7 @@ public class DingConfig {
body.put("agent_id", configBean.getAgentId());
body.put("userid_list", CollUtil.join(userIds, ","));
body.put("msg", msg);
- return HttpUtil.post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + getAccessToken(service),
+ String resp = HttpUtil.post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token=" + getAccessToken(service),
JSONUtil.toJsonStr(body));
}
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingConfigBean.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingConfigBean.java
similarity index 95%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingConfigBean.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingConfigBean.java
index 17e0c30..74d3ac1 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingConfigBean.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingConfigBean.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
/**
* @author hao
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingDeptVo.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingDeptVo.java
similarity index 93%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingDeptVo.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingDeptVo.java
index 451f2bf..ab237be 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingDeptVo.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingDeptVo.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
public class DingDeptVo {
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingJsapiSignature.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingJsapiSignature.java
similarity index 97%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingJsapiSignature.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingJsapiSignature.java
index c7ca7ba..880e653 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingJsapiSignature.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingJsapiSignature.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingResponse.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingResponse.java
similarity index 95%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingResponse.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingResponse.java
index 3c3935d..9b017fd 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingResponse.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingResponse.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
import java.util.Objects;
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserInfo.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserInfo.java
similarity index 98%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserInfo.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserInfo.java
index b6c8cb0..7855d98 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserInfo.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserInfo.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
import java.util.List;
diff --git a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserListVo.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserListVo.java
similarity index 95%
rename from tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserListVo.java
rename to tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserListVo.java
index 5a92a0b..f07a99a 100644
--- a/tiesheng-ding/src/main/java/com/tiesheng/ding/pojos/DingUserListVo.java
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/ding/bean/DingUserListVo.java
@@ -1,4 +1,4 @@
-package com.tiesheng.ding.pojos;
+package com.tiesheng.platform.config.ding.bean;
import java.util.ArrayList;
import java.util.List;
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/PlatformWxmpConfig.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/PlatformWxmpConfig.java
new file mode 100644
index 0000000..93a5aa5
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/PlatformWxmpConfig.java
@@ -0,0 +1,181 @@
+package com.tiesheng.platform.config.wxmp;
+
+
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.URLUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.LogFactory;
+import com.tiesheng.platform.config.wxmp.bean.WxConfigBean;
+import com.tiesheng.platform.config.wxmp.bean.WxJsapiSignature;
+import com.tiesheng.platform.config.wxmp.bean.WxOAuth2AccessToken;
+import com.tiesheng.platform.config.wxmp.bean.WxUserInfo;
+import com.tiesheng.util.TimedCacheHelper;
+import com.tiesheng.util.exception.ApiException;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author hao
+ */
+@Configuration
+@ConfigurationProperties(prefix = "platform.wxmp")
+public class PlatformWxmpConfig {
+
+ private static final String CACHE_ACCESS_TOKEN = "cache_weixin_access_token_";
+ private static final String CACHE_JSAPI_TICKET = "cache_weixin_jsapi_ticket_";
+
+
+ private WxConfigBean global;
+ private Map configs = MapUtil.newHashMap();
+
+ /**
+ * 获取一个DingConfigBean
+ *
+ * @param service
+ * @return
+ */
+ public WxConfigBean getConfigBean(String service) {
+ WxConfigBean bean = configs.get(service);
+ if (bean == null) {
+ bean = global;
+ }
+ if (bean == null) {
+ throw new ApiException("该服务未配置微信授权");
+ }
+ return bean;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 业务逻辑
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ /**
+ * 获取accessToken
+ *
+ * @return
+ */
+ private String getAccessToken(String service) {
+ WxConfigBean configBean = getConfigBean(service);
+ String accessToken = TimedCacheHelper.getTimedCache().get(CACHE_ACCESS_TOKEN + configBean.getAppId(), false);
+ if (StrUtil.isEmpty(accessToken)) {
+ Map query = new HashMap<>(10);
+ query.put("grant_type", "client_credential");
+ query.put("appid", configBean.getAppId());
+ query.put("secret", configBean.getAppSecret());
+ String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token", query);
+ LogFactory.get().info("getAccessToken: " + response);
+ JSONObject respJson = JSONUtil.parseObj(response);
+ accessToken = respJson.getStr("access_token");
+ TimedCacheHelper.getTimedCache().put(CACHE_ACCESS_TOKEN + configBean.getAppId(), accessToken, respJson.getLong("expires_in"));
+ }
+ return accessToken;
+ }
+
+
+ /**
+ * 获取jsapi_ticket
+ *
+ * @return
+ */
+ private String getJsapiTicket(String service) {
+ WxConfigBean configBean = getConfigBean(service);
+ String jsapiTicket = TimedCacheHelper.getTimedCache().get(CACHE_JSAPI_TICKET + configBean.getAppId(), false);
+ if (StrUtil.isEmpty(jsapiTicket)) {
+ Map query = new HashMap<>(10);
+ query.put("access_token", getAccessToken(service));
+ query.put("type", "jsapi");
+ String response = HttpUtil.get("https://api.weixin.qq.com/cgi-bin/ticket/getticket", query);
+ LogFactory.get().info("getJsapiTicket: " + response);
+ JSONObject respJson = JSONUtil.parseObj(response);
+ jsapiTicket = respJson.getStr("ticket");
+ TimedCacheHelper.getTimedCache().put(CACHE_JSAPI_TICKET + configBean.getAppId(), jsapiTicket, respJson.getLong("expires_in"));
+ }
+ return jsapiTicket;
+ }
+
+
+ /**
+ * 创建jssdk配置
+ *
+ * @param url
+ * @return
+ */
+ public WxJsapiSignature createJsapiSignature(String service, String url) {
+ WxConfigBean configBean = getConfigBean(service);
+ if (StrUtil.contains(url, "#")) {
+ url = StrUtil.sub(url, 0, StrUtil.indexOf(url, '#'));
+ }
+ return WxJsapiSignature.create(configBean.getAppId(), url, getJsapiTicket(service));
+ }
+
+
+ /**
+ * 生成认证url
+ *
+ * @return
+ */
+ public String buildAuthorizationUrl(String service, String redirectUrl, String scope) {
+ WxConfigBean configBean = getConfigBean(service);
+ return "https://open.weixin.qq.com/connect/oauth2/authorize"
+ + "?appid=" + configBean.getAppId()
+ + "&redirect_uri=" + URLUtil.encodeAll(redirectUrl)
+ + "&response_type=code&scope=" + scope
+ + "&state=STATE#wechat_redirect";
+ }
+
+
+ /**
+ * 通过code获取用户授权信息
+ *
+ * @param code
+ * @return
+ */
+ public WxUserInfo getOAuth2AccessToken(String service, String code) {
+ WxConfigBean configBean = getConfigBean(service);
+ WxOAuth2AccessToken wxOAuth2AccessToken = WxOAuth2AccessToken.create(configBean.getAppId(), configBean.getAppSecret(), code);
+ WxUserInfo wxUserInfo = WxUserInfo.create(wxOAuth2AccessToken);
+ wxUserInfo.setAppId(configBean.getAppId());
+ return wxUserInfo;
+ }
+
+
+ /**
+ * 获取临时素材-图片
+ *
+ * @return
+ * @link
+ */
+ public void mediaPicGet(String service, String mediaId, String filePath) {
+ String fileUrl = String.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s",
+ getAccessToken(service), mediaId);
+ HttpUtil.downloadFile(fileUrl, filePath);
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // setter\getter
+ ///////////////////////////////////////////////////////////////////////////
+
+ public Map getConfigs() {
+ return configs;
+ }
+
+ public void setConfigs(Map configs) {
+ this.configs = configs;
+ }
+
+ public WxConfigBean getGlobal() {
+ return global;
+ }
+
+ public void setGlobal(WxConfigBean global) {
+ this.global = global;
+ }
+}
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxConfigBean.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxConfigBean.java
new file mode 100644
index 0000000..5a24275
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxConfigBean.java
@@ -0,0 +1,30 @@
+package com.tiesheng.platform.config.wxmp.bean;
+
+/**
+ * @author hao
+ */
+public class WxConfigBean {
+
+ private String appId;
+ private String appSecret;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // setter\getter
+ ///////////////////////////////////////////////////////////////////////////
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ public String getAppSecret() {
+ return appSecret;
+ }
+
+ public void setAppSecret(String appSecret) {
+ this.appSecret = appSecret;
+ }
+}
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxJsapiSignature.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxJsapiSignature.java
new file mode 100644
index 0000000..45ae405
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxJsapiSignature.java
@@ -0,0 +1,81 @@
+package com.tiesheng.platform.config.wxmp.bean;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.crypto.SecureUtil;
+
+/**
+ * jssdk配置
+ *
+ * @author hao
+ */
+public class WxJsapiSignature {
+
+ private String appId;
+ private String nonceStr;
+ private long timestamp;
+ private String url;
+ private String signature;
+
+ public static WxJsapiSignature create(String appId, String url, String ticket) {
+ WxJsapiSignature wxJsapiSignature = new WxJsapiSignature();
+ wxJsapiSignature.setAppId(appId);
+ wxJsapiSignature.setUrl(url);
+ wxJsapiSignature.setTimestamp(DateUtil.currentSeconds());
+ wxJsapiSignature.setNonceStr(RandomUtil.randomString(10));
+
+ // 生成签名
+ String builder = "jsapi_ticket=" + ticket +
+ "&noncestr=" + wxJsapiSignature.getNonceStr() +
+ "×tamp=" + wxJsapiSignature.getTimestamp() +
+ "&url=" + wxJsapiSignature.getUrl();
+ wxJsapiSignature.setSignature(SecureUtil.sha1(builder));
+
+ return wxJsapiSignature;
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // setter\getter
+ ///////////////////////////////////////////////////////////////////////////
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ public String getNonceStr() {
+ return nonceStr;
+ }
+
+ public void setNonceStr(String nonceStr) {
+ this.nonceStr = nonceStr;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getSignature() {
+ return signature;
+ }
+
+ public void setSignature(String signature) {
+ this.signature = signature;
+ }
+}
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxOAuth2AccessToken.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxOAuth2AccessToken.java
new file mode 100644
index 0000000..97d93d9
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxOAuth2AccessToken.java
@@ -0,0 +1,46 @@
+package com.tiesheng.platform.config.wxmp.bean;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+
+/**
+ * @author hao
+ */
+public class WxOAuth2AccessToken {
+
+ private String accessToken;
+ private String openid;
+
+ public static WxOAuth2AccessToken create(String appId, String secret, String code) {
+ String response = HttpUtil.get("https://api.weixin.qq.com/sns/oauth2/access_token" +
+ "?appid=" + appId + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code");
+ JSONObject respJson = JSONUtil.parseObj(response);
+
+ WxOAuth2AccessToken oAuth2AccessToken = new WxOAuth2AccessToken();
+ oAuth2AccessToken.setOpenid(respJson.getStr("openid"));
+ oAuth2AccessToken.setAccessToken(respJson.getStr("access_token"));
+ return oAuth2AccessToken;
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // setter\getter
+ ///////////////////////////////////////////////////////////////////////////
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getOpenid() {
+ return openid;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+}
diff --git a/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxUserInfo.java b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxUserInfo.java
new file mode 100644
index 0000000..447f217
--- /dev/null
+++ b/tiesheng-platform/src/main/java/com/tiesheng/platform/config/wxmp/bean/WxUserInfo.java
@@ -0,0 +1,115 @@
+package com.tiesheng.platform.config.wxmp.bean;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+
+/**
+ * @author hao
+ */
+public class WxUserInfo {
+
+ private String accessToken;
+ private String nickname;
+ private String sex;
+ private String province;
+ private String city;
+ private String country;
+ private String headimgurl;
+ private String openid;
+ private String appId;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 逻辑方法
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ /**
+ * 通过oAuth2AccessToken获取用户信息
+ *
+ * @param oAuth2AccessToken
+ * @return
+ */
+ public static WxUserInfo create(WxOAuth2AccessToken oAuth2AccessToken) {
+ String s = HttpUtil.get("https://api.weixin.qq.com/sns/userinfo"
+ + "?access_token=" + oAuth2AccessToken.getAccessToken()
+ + "&openid=" + oAuth2AccessToken.getOpenid() + "&lang=zh_CN");
+ return JSONUtil.toBean(s, WxUserInfo.class);
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // setter\getter
+ ///////////////////////////////////////////////////////////////////////////
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public String getSex() {
+ return sex;
+ }
+
+ public void setSex(String sex) {
+ this.sex = sex;
+ }
+
+ public String getProvince() {
+ return province;
+ }
+
+ public void setProvince(String province) {
+ this.province = province;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getHeadimgurl() {
+ return headimgurl;
+ }
+
+ public void setHeadimgurl(String headimgurl) {
+ this.headimgurl = headimgurl;
+ }
+
+ public String getOpenid() {
+ return openid;
+ }
+
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+}
diff --git a/tiesheng-poi/pom.xml b/tiesheng-poi/pom.xml
index ad4017b..dd93475 100644
--- a/tiesheng-poi/pom.xml
+++ b/tiesheng-poi/pom.xml
@@ -6,7 +6,7 @@
com.tiesheng
tiesheng-parent
- 0.0.4
+ 0.0.5
tiesheng-poi
diff --git a/tiesheng-util/pom.xml b/tiesheng-util/pom.xml
index 7589245..0906519 100644
--- a/tiesheng-util/pom.xml
+++ b/tiesheng-util/pom.xml
@@ -6,7 +6,7 @@
com.tiesheng
tiesheng-parent
- 0.0.4
+ 0.0.5
tiesheng-util
diff --git a/tiesheng-util/src/main/java/com/tiesheng/util/pojos/ApiResp.java b/tiesheng-util/src/main/java/com/tiesheng/util/pojos/ApiResp.java
index 2bc2805..2760bbe 100644
--- a/tiesheng-util/src/main/java/com/tiesheng/util/pojos/ApiResp.java
+++ b/tiesheng-util/src/main/java/com/tiesheng/util/pojos/ApiResp.java
@@ -17,6 +17,7 @@ public class ApiResp {
private int code;
private String message;
+ private Throwable exception;
private T data;
private long recordsTotal = 0;
private boolean encrypt = false;
@@ -171,4 +172,12 @@ public class ApiResp {
public void setEncrypt(boolean encrypt) {
this.encrypt = encrypt;
}
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public void setException(Throwable exception) {
+ this.exception = exception;
+ }
}
diff --git a/tiesheng-web/pom.xml b/tiesheng-web/pom.xml
index f2bbaa6..fb1e20f 100644
--- a/tiesheng-web/pom.xml
+++ b/tiesheng-web/pom.xml
@@ -6,7 +6,7 @@
com.tiesheng
tiesheng-parent
- 0.0.4
+ 0.0.5
tiesheng-web
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/exception/SpringExceptionHandler.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/exception/SpringExceptionHandler.java
index a88150f..0f608b1 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/config/exception/SpringExceptionHandler.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/exception/SpringExceptionHandler.java
@@ -25,7 +25,7 @@ import java.io.IOException;
@RestControllerAdvice
public class SpringExceptionHandler {
- @Autowired(required = false)
+ @Autowired
TieshengWebConfigurer tieshengWebConfigurer;
@@ -74,10 +74,7 @@ public class SpringExceptionHandler {
return ApiResp.respCust(ApiRespEnum.ServerError.getCode(), "IO异常");
}
- if (tieshengWebConfigurer != null) {
- return tieshengWebConfigurer.addExceptionHandler(e);
- }
- return ApiResp.respCust(ApiRespEnum.ServerError);
+ return tieshengWebConfigurer.addExceptionHandler(e);
}
}
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/json/FastJsonMessageConverter.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/json/FastJsonMessageConverter.java
index c1dc2f9..5266855 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/config/json/FastJsonMessageConverter.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/json/FastJsonMessageConverter.java
@@ -1,6 +1,5 @@
package com.tiesheng.core.config.json;
-import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@@ -29,8 +28,7 @@ public class FastJsonMessageConverter {
FastJsonConfig config = new FastJsonConfig();
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullStringAsEmpty,
- SerializerFeature.WriteEnumUsingName,
- SerializerFeature.WriteNullNumberAsZero);
+ SerializerFeature.WriteEnumUsingName);
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/web/DefaultWebConfigurer.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/DefaultWebConfigurer.java
new file mode 100644
index 0000000..4d7bc02
--- /dev/null
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/DefaultWebConfigurer.java
@@ -0,0 +1,13 @@
+package com.tiesheng.core.config.web;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Configuration;
+
+
+/**
+ * @author hao
+ */
+@Configuration
+@ConditionalOnMissingBean(value = TieshengWebConfigurer.class, ignored = DefaultWebConfigurer.class)
+public class DefaultWebConfigurer implements TieshengWebConfigurer {
+}
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java
index 17ad62a..5e3a5ec 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/config/web/TieshengWebConfigurer.java
@@ -1,12 +1,17 @@
package com.tiesheng.core.config.web;
import cn.hutool.log.LogFactory;
-import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.core.config.web.bean.CurrentWebUser;
+import com.tiesheng.core.pojos.dao.CorePlatformUnique;
+import com.tiesheng.login.config.token.TsTokenConfig;
+import com.tiesheng.login.config.token.bean.TokenBean;
+import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.exception.ApiRespEnum;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.context.annotation.Configuration;
+import javax.servlet.http.HttpServletResponse;
+
/**
* WEB配置
*
@@ -24,6 +29,7 @@ public interface TieshengWebConfigurer {
default CurrentWebUser getCurrentUserName() {
CurrentWebUser webUser = new CurrentWebUser();
webUser.setId(TsTokenConfig.getWithoutThr().getId());
+ webUser.setName(webUser.getId());
return webUser;
}
@@ -34,8 +40,10 @@ public interface TieshengWebConfigurer {
* @param e 异常
*/
default ApiResp addExceptionHandler(Exception e) {
- LogFactory.get().info(e);
- return ApiResp.respCust(ApiRespEnum.ServerError);
+ ApiResp apiResp = ApiResp.respCust(ApiRespEnum.ServerError);
+ apiResp.setException(e);
+ LogFactory.get().info(apiResp.getException());
+ return apiResp;
}
@@ -45,4 +53,48 @@ public interface TieshengWebConfigurer {
default void uploadFileCheck(String fileExt) {
}
+
+ /**
+ * 配置登录
+ *
+ * @return
+ */
+ default LoginConfigurer loginConfigurer() {
+ return new LoginConfigurer() {
+ @Override
+ public TokenBean doLogin(CorePlatformUnique platformUnique) {
+ throw new ApiException("请配置TieshengWebConfigurer->loginConfigurer");
+ }
+
+ @Override
+ public void redirect(TokenBean bean, String extra, HttpServletResponse response) {
+ throw new ApiException("请配置TieshengWebConfigurer->loginConfigurer");
+ }
+ };
+ }
+
+
+ interface LoginConfigurer {
+
+ /**
+ * 登录逻辑
+ *
+ * @param platformUnique
+ * @return
+ */
+ TokenBean doLogin(CorePlatformUnique platformUnique);
+
+
+ /**
+ * 登录重定向
+ *
+ * @param bean
+ * @param extra
+ * @param response
+ */
+ void redirect(TokenBean bean, String extra, HttpServletResponse response);
+
+ }
+
+
}
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java b/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/LogController.java
similarity index 86%
rename from tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java
rename to tiesheng-web/src/main/java/com/tiesheng/core/controller/log/LogController.java
index 5143244..d8a97ee 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/ManagerLogController.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/controller/log/LogController.java
@@ -2,11 +2,10 @@ package com.tiesheng.core.controller.log;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.tiesheng.core.pojos.dao.CoreLogLogin;
import com.tiesheng.core.pojos.dao.CoreLogOperation;
import com.tiesheng.core.pojos.dto.PageDTO;
import com.tiesheng.core.service.CoreLogService;
-import com.tiesheng.login.pojos.dao.CoreLogLogin;
-import com.tiesheng.login.service.LoginLogService;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -21,12 +20,10 @@ import java.util.List;
*/
@RestController
@RequestMapping("/manager/log")
-public class ManagerLogController {
+public class LogController {
@Autowired
CoreLogService coreLogService;
- @Autowired(required = false)
- LoginLogService loginLogService;
/**
@@ -63,9 +60,7 @@ public class ManagerLogController {
queryWrapper.orderByDesc("create_time");
Page page = dto.pageObj();
- if (loginLogService != null) {
- loginLogService.page(page, queryWrapper);
- }
+ coreLogService.getLogLoginMapper().selectPage(page, queryWrapper);
return ApiResp.respOK(page.getRecords(), page.getTotal());
}
diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java b/tiesheng-web/src/main/java/com/tiesheng/core/mapper/CoreLogLoginMapper.java
similarity index 60%
rename from tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java
rename to tiesheng-web/src/main/java/com/tiesheng/core/mapper/CoreLogLoginMapper.java
index decbb40..81f3c88 100644
--- a/tiesheng-login/src/main/java/com/tiesheng/login/mapper/CoreLogLoginMapper.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/mapper/CoreLogLoginMapper.java
@@ -1,7 +1,7 @@
-package com.tiesheng.login.mapper;
+package com.tiesheng.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.tiesheng.login.pojos.dao.CoreLogLogin;
+import com.tiesheng.core.pojos.dao.CoreLogLogin;
public interface CoreLogLoginMapper extends BaseMapper {
-}
\ No newline at end of file
+}
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/mapper/CorePlatformUniqueMapper.java b/tiesheng-web/src/main/java/com/tiesheng/core/mapper/CorePlatformUniqueMapper.java
new file mode 100644
index 0000000..e96f83a
--- /dev/null
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/mapper/CorePlatformUniqueMapper.java
@@ -0,0 +1,7 @@
+package com.tiesheng.core.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.tiesheng.core.pojos.dao.CorePlatformUnique;
+
+public interface CorePlatformUniqueMapper extends BaseMapper {
+}
\ No newline at end of file
diff --git a/tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java b/tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CoreLogLogin.java
similarity index 60%
rename from tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java
rename to tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CoreLogLogin.java
index 5215090..eac49fa 100644
--- a/tiesheng-login/src/main/java/com/tiesheng/login/pojos/dao/CoreLogLogin.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CoreLogLogin.java
@@ -1,27 +1,14 @@
-package com.tiesheng.login.pojos.dao;
+package com.tiesheng.core.pojos.dao;
-import com.baomidou.mybatisplus.annotation.*;
-
-import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.tiesheng.core.pojos.DaoBase;
/**
* 日志-登录
*/
@TableName(value = "core_log_login")
-public class CoreLogLogin {
-
- @TableId(value = "id", type = IdType.ASSIGN_ID)
- private String id;
-
- @TableField(value = "create_time", fill = FieldFill.INSERT)
- private Date createTime;
-
- @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
- private Date updateTime;
-
- @TableField(value = "is_deleted")
- private Integer isDeleted;
-
+public class CoreLogLogin extends DaoBase {
/**
* 用户id
*/
@@ -52,38 +39,6 @@ public class CoreLogLogin {
@TableField(value = "address")
private String address;
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public Date getCreateTime() {
- return createTime;
- }
-
- public void setCreateTime(Date createTime) {
- this.createTime = createTime;
- }
-
- public Date getUpdateTime() {
- return updateTime;
- }
-
- public void setUpdateTime(Date updateTime) {
- this.updateTime = updateTime;
- }
-
- public Integer getIsDeleted() {
- return isDeleted;
- }
-
- public void setIsDeleted(Integer isDeleted) {
- this.isDeleted = isDeleted;
- }
-
/**
* 获取用户id
*
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CorePlatformUnique.java b/tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CorePlatformUnique.java
new file mode 100644
index 0000000..daa4880
--- /dev/null
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/pojos/dao/CorePlatformUnique.java
@@ -0,0 +1,134 @@
+package com.tiesheng.core.pojos.dao;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.tiesheng.core.pojos.DaoBase;
+import java.util.Date;
+
+/**
+ * 平台-唯一值
+ */
+@TableName(value = "core_platform_unique")
+public class CorePlatformUnique extends DaoBase {
+ /**
+ * 用户id
+ */
+ @TableField(value = "user_id")
+ private String userId;
+
+ /**
+ * appId
+ */
+ @TableField(value = "app_id")
+ private String appId;
+
+ /**
+ * 唯一值
+ */
+ @TableField(value = "unique_id")
+ private String uniqueId;
+
+ /**
+ * 平台
+ */
+ @TableField(value = "platform")
+ private String platform;
+
+ /**
+ * 其他参数
+ */
+ @TableField(value = "info")
+ private String info;
+
+ /**
+ * 获取用户id
+ *
+ * @return user_id - 用户id
+ */
+ public String getUserId() {
+ return userId;
+ }
+
+ /**
+ * 设置用户id
+ *
+ * @param userId 用户id
+ */
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * 获取appId
+ *
+ * @return app_id - appId
+ */
+ public String getAppId() {
+ return appId;
+ }
+
+ /**
+ * 设置appId
+ *
+ * @param appId appId
+ */
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ /**
+ * 获取唯一值
+ *
+ * @return unique_id - 唯一值
+ */
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ /**
+ * 设置唯一值
+ *
+ * @param uniqueId 唯一值
+ */
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ /**
+ * 获取平台
+ *
+ * @return platform - 平台
+ */
+ public String getPlatform() {
+ return platform;
+ }
+
+ /**
+ * 设置平台
+ *
+ * @param platform 平台
+ */
+ public void setPlatform(String platform) {
+ this.platform = platform;
+ }
+
+ /**
+ * 获取其他参数
+ *
+ * @return info - 其他参数
+ */
+ public String getInfo() {
+ return info;
+ }
+
+ /**
+ * 设置其他参数
+ *
+ * @param info 其他参数
+ */
+ public void setInfo(String info) {
+ this.info = info;
+ }
+}
\ No newline at end of file
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java b/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java
index 9794b40..0381a99 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/service/CoreLogService.java
@@ -1,22 +1,36 @@
package com.tiesheng.core.service;
+import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;
-import com.tiesheng.login.config.token.TsTokenConfig;
import com.tiesheng.core.config.web.TieshengWebConfigurer;
import com.tiesheng.core.config.web.bean.CurrentWebUser;
+import com.tiesheng.core.mapper.CoreLogLoginMapper;
import com.tiesheng.core.mapper.CoreLogOperationMapper;
+import com.tiesheng.core.pojos.dao.CoreLogLogin;
import com.tiesheng.core.pojos.dao.CoreLogOperation;
+import com.tiesheng.core.pojos.dao.CorePlatformUnique;
+import com.tiesheng.util.ServletKit;
+import com.tiesheng.util.ip2region.DataBlock;
+import com.tiesheng.util.ip2region.Ip2Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import javax.servlet.http.HttpServletRequest;
+
/**
* @author hao
*/
@Service
public class CoreLogService extends TsServiceBase {
- @Autowired(required = false)
+ @Autowired
TieshengWebConfigurer tieshengWebConfigurer;
+ @Autowired
+ CoreLogLoginMapper coreLogLoginMapper;
+
+ public CoreLogLoginMapper getLogLoginMapper() {
+ return coreLogLoginMapper;
+ }
///////////////////////////////////////////////////////////////////////////
// 操作日志
@@ -28,13 +42,9 @@ public class CoreLogService extends TsServiceBase implements TieshengLoginConfigurer {
+
+ @Autowired
+ TieshengWebConfigurer tieshengWebConfigurer;
+ @Autowired
+ CoreLogService coreLogService;
+
+ @Override
+ public TokenBean doLogin(String appId, String uniqueId, String platfrom, String info) {
+
+ CorePlatformUnique platformUnique = getByAppAndUnique(appId, uniqueId, platfrom);
+ platformUnique.setInfo(info);
+ TokenBean tokenBean = tieshengWebConfigurer.loginConfigurer().doLogin(platformUnique);
+ if (tokenBean != null) {
+ platformUnique.setUserId(tokenBean.getId());
+ platformUnique.setIsDeleted(0);
+ saveOrUpdate(platformUnique);
+
+ // 添加登录日志
+ coreLogService.addLoginLog(platformUnique);
+ }
+ return tokenBean;
+ }
+
+ @Override
+ public void onLoginRedirect(TokenBean bean, String extra, HttpServletResponse response) {
+ tieshengWebConfigurer.loginConfigurer().redirect(bean, extra, response);
+ }
+
+
+ /**
+ * 通过appId获取登录对象
+ *
+ * @param appId
+ * @param uniqueId
+ * @return
+ */
+ private CorePlatformUnique getByAppAndUnique(String appId, String uniqueId, String platform) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("app_id", appId);
+ queryWrapper.eq("unique_id", uniqueId);
+ queryWrapper.eq("platform", platform);
+ queryWrapper.last("limit 1");
+ CorePlatformUnique platformUnique = getOne(queryWrapper);
+ if (platformUnique == null) {
+ platformUnique = new CorePlatformUnique();
+ platformUnique.setAppId(appId);
+ platformUnique.setUniqueId(uniqueId);
+ platformUnique.setPlatform(platform);
+ }
+ return platformUnique;
+ }
+
+}
diff --git a/tiesheng-web/src/main/java/com/tiesheng/core/service/FileUploadService.java b/tiesheng-web/src/main/java/com/tiesheng/core/service/FileUploadService.java
index b793527..6a59886 100644
--- a/tiesheng-web/src/main/java/com/tiesheng/core/service/FileUploadService.java
+++ b/tiesheng-web/src/main/java/com/tiesheng/core/service/FileUploadService.java
@@ -22,7 +22,7 @@ import java.util.List;
@Service
public class FileUploadService {
- @Autowired(required = false)
+ @Autowired
TieshengWebConfigurer tieshengWebConfigurer;
@@ -38,10 +38,8 @@ public class FileUploadService {
public String saveMultipartFile(MultipartFile file) {
try {
- if (tieshengWebConfigurer != null) {
- String fileType = FileTypeUtil.getType(file.getInputStream(), file.getOriginalFilename());
- tieshengWebConfigurer.uploadFileCheck(fileType);
- }
+ String fileType = FileTypeUtil.getType(file.getInputStream(), file.getOriginalFilename());
+ tieshengWebConfigurer.uploadFileCheck(fileType);
FileUploadPath filePath = FileUploadPath.random();
@@ -65,9 +63,7 @@ public class FileUploadService {
* @param fileExt
*/
public void chunkStart(String fileExt) {
- if (tieshengWebConfigurer != null) {
- tieshengWebConfigurer.uploadFileCheck(fileExt);
- }
+ tieshengWebConfigurer.uploadFileCheck(fileExt);
}
/**
@@ -111,33 +107,33 @@ public class FileUploadService {
* 合并块文件
*
* @param fileMd5
- * @param fileExt
*/
public String chunkMerge(String fileMd5) {
- // 1,获取块文件的路径
+ // 1,获取文件块的目录
FileUploadPath folder = FileUploadPath.folder(fileMd5);
- // 2,生成保存文件路径
- FileUploadPath uploadPath = FileUploadPath.random();
-
- // 3,如果文件不存在
- if (FileUtil.exist(folder.getAbsolutePath())) {
+ // 2,如果目录不存在
+ if (!FileUtil.exist(folder.getAbsolutePath())) {
+ throw new ApiException("请先上传文件块");
+ }
- // 4,获取块文件,此列表是已经排好序的列表
- List chunkFiles = getChunkFiles(new File(folder.getAbsolutePath()));
+ // 3,生成保存文件的路径
+ FileUploadPath uploadPath = FileUploadPath.random();
- // 5,合并文件
- File newFile = FileUtil.newFile(uploadPath.getAbsolutePath());
- for (File file : chunkFiles) {
- byte[] bytes = FileUtil.readBytes(file);
- FileUtil.writeBytes(bytes, newFile, 0, bytes.length, true);
- }
+ // 4,获取块文件,此列表是已经排好序的列表
+ List chunkFiles = getSortedChunkFiles(new File(folder.getAbsolutePath()));
- // 6,删除块文件目录
- FileUtil.del(folder.getAbsolutePath());
+ // 5,合并文件
+ File newFile = FileUtil.newFile(uploadPath.getAbsolutePath());
+ for (File file : chunkFiles) {
+ byte[] bytes = FileUtil.readBytes(file);
+ FileUtil.writeBytes(bytes, newFile, 0, bytes.length, true);
}
+ // 6,删除块文件目录
+ FileUtil.del(folder.getAbsolutePath());
+
return uploadPath.getHttpPath();
}
@@ -148,7 +144,7 @@ public class FileUploadService {
* @param chunkFileFolder
* @return
*/
- private List getChunkFiles(File chunkFileFolder) {
+ private List getSortedChunkFiles(File chunkFileFolder) {
//获取路径下的所有块文件
File[] chunkFiles = chunkFileFolder.listFiles();
diff --git a/tiesheng-login/src/main/resources/db/migration/tiesheng_login_log.sql b/tiesheng-web/src/main/resources/db/migration/core_log_login.sql
similarity index 100%
rename from tiesheng-login/src/main/resources/db/migration/tiesheng_login_log.sql
rename to tiesheng-web/src/main/resources/db/migration/core_log_login.sql
diff --git a/tiesheng-web/src/main/resources/db/migration/core_platform_unique.sql b/tiesheng-web/src/main/resources/db/migration/core_platform_unique.sql
new file mode 100644
index 0000000..b517b02
--- /dev/null
+++ b/tiesheng-web/src/main/resources/db/migration/core_platform_unique.sql
@@ -0,0 +1,22 @@
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for core_platform_unique
+-- ----------------------------
+CREATE TABLE `core_platform_unique`
+(
+ `id` varchar(50) NOT NULL,
+ `create_time` datetime NOT NULL,
+ `update_time` datetime NOT NULL,
+ `is_deleted` int(6) NOT NULL DEFAULT '0',
+ `user_id` varchar(50) DEFAULT NULL COMMENT '用户id',
+ `app_id` varchar(255) DEFAULT NULL COMMENT 'appId',
+ `unique_id` varchar(255) DEFAULT NULL COMMENT '唯一值',
+ `platform` varchar(255) DEFAULT NULL COMMENT '平台',
+ `info` text COMMENT '其他参数',
+ PRIMARY KEY (`id`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8mb4 COMMENT ='平台-唯一值';
+
+SET FOREIGN_KEY_CHECKS = 1;
diff --git a/tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml b/tiesheng-web/src/main/resources/mapper/CoreLogLoginMapper.xml
similarity index 86%
rename from tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml
rename to tiesheng-web/src/main/resources/mapper/CoreLogLoginMapper.xml
index 9aeaf93..700fbd3 100644
--- a/tiesheng-login/src/main/resources/mapper/CoreLogLoginMapper.xml
+++ b/tiesheng-web/src/main/resources/mapper/CoreLogLoginMapper.xml
@@ -1,7 +1,7 @@
-
-
+
+
@@ -18,4 +18,4 @@
id, create_time, update_time, is_deleted, user_id, user_name, platform, ip, address
-
\ No newline at end of file
+
diff --git a/tiesheng-web/src/main/resources/mapper/CorePlatformUniqueMapper.xml b/tiesheng-web/src/main/resources/mapper/CorePlatformUniqueMapper.xml
new file mode 100644
index 0000000..8cf45eb
--- /dev/null
+++ b/tiesheng-web/src/main/resources/mapper/CorePlatformUniqueMapper.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id, create_time, update_time, is_deleted, user_id, app_id, unique_id, platform, info
+
+
\ No newline at end of file