From 7e5ed0e7b50567342946eb3e9dfaf5a213b0e7a9 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 11 一月 2022 11:04:55 +0800
Subject: [PATCH] 支持 接入商自定义
---
service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java | 134 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 128 insertions(+), 6 deletions(-)
diff --git a/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java b/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
index b2e2bd9..d0494d2 100644
--- a/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
+++ b/service-api/src/main/java/com/java110/api/smo/login/impl/OwnerAppLoginSMOImpl.java
@@ -2,18 +2,23 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.java110.core.base.smo.front.AbstractFrontServiceSMO;
+import com.java110.api.properties.WechatAuthProperties;
+import com.java110.api.smo.DefaultAbstractComponentSMO;
+import com.java110.api.smo.login.IOwnerAppLoginSMO;
import com.java110.core.context.IPageData;
import com.java110.core.context.PageData;
import com.java110.core.factory.AuthenticationFactory;
import com.java110.core.factory.WechatFactory;
import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.ownerCarOpenUser.OwnerCarOpenUserDto;
import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.dto.user.UserDto;
-import com.java110.api.properties.WechatAuthProperties;
-import com.java110.api.smo.login.IOwnerAppLoginSMO;
+import com.java110.intf.user.IOwnerCarOpenUserV1InnerServiceSMO;
import com.java110.utils.cache.CommonCache;
-import com.java110.utils.constant.*;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.constant.WechatConstant;
import com.java110.utils.exception.SMOException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.Base64Convert;
@@ -42,7 +47,7 @@
* wx鐧诲綍
*/
@Service("ownerAppLoginSMOImpl")
-public class OwnerAppLoginSMOImpl extends AbstractFrontServiceSMO implements IOwnerAppLoginSMO {
+public class OwnerAppLoginSMOImpl extends DefaultAbstractComponentSMO implements IOwnerAppLoginSMO {
private final static Logger logger = LoggerFactory.getLogger(OwnerAppLoginSMOImpl.class);
@@ -58,6 +63,9 @@
@Autowired
private WechatAuthProperties wechatAuthProperties;
+
+ @Autowired
+ private IOwnerCarOpenUserV1InnerServiceSMO ownerCarOpenUserV1InnerServiceSMOImpl;
@Override
public ResponseEntity<String> doLogin(IPageData pd) throws SMOException {
@@ -376,6 +384,120 @@
return ResultVo.createResponseEntity(ResultVo.CODE_MACHINE_OK, ResultVo.MSG_OK, urlObj);
}
+ @Override
+ public ResponseEntity<String> refreshOpenId(IPageData pd, String redirectUrl, String wAppId, HttpServletRequest request, HttpServletResponse response) {
+
+ SmallWeChatDto smallWeChatDto = null;
+ if (!StringUtil.isEmpty(wAppId)) {
+ JSONObject paramIn = new JSONObject();
+ paramIn.put("appId", wAppId);
+ smallWeChatDto = getSmallWechat(pd, paramIn);
+ }
+ if (smallWeChatDto == null) { //浠庨厤缃枃浠朵腑鑾峰彇 灏忕▼搴忛厤缃俊鎭�
+ smallWeChatDto = new SmallWeChatDto();
+ smallWeChatDto.setAppId(wechatAuthProperties.getWechatAppId());
+ smallWeChatDto.setAppSecret(wechatAuthProperties.getWechatAppSecret());
+ smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
+ smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
+ wAppId = wechatAuthProperties.getWechatAppId();
+ }
+
+ //鍒嗛厤urlCode
+ String urlCode = UUID.randomUUID().toString();
+ JSONObject param = new JSONObject();
+ if (redirectUrl.indexOf("appId") < 0) {
+ redirectUrl += ("&appId=" + smallWeChatDto.getAppId());
+ }
+ param.put("redirectUrl", redirectUrl);
+ CommonCache.setValue(urlCode, param.toJSONString(), expireTime);
+
+ URL url = null;
+ String openUrl = "";
+ try {
+ url = new URL(redirectUrl);
+
+ String newUrl = url.getProtocol() + "://" + url.getHost();
+ if (url.getPort() > 0) {
+ newUrl += (":" + url.getPort());
+ }
+
+ openUrl = WechatConstant.OPEN_AUTH
+ .replace("APPID", smallWeChatDto.getAppId())
+ .replace("SCOPE", "snsapi_userinfo")
+ .replace(
+ "REDIRECT_URL",
+ URLEncoder
+ .encode(
+ (newUrl
+ + "/app/openServiceNotifyOpenId?appId=992020061452450002&urlCode=" +
+ urlCode + "&wId=" + WechatFactory.getWId(wAppId)),
+ "UTF-8")).replace("STATE", "1");
+
+ } catch (Exception e) {
+ logger.error("寰俊鍏紬鍙烽壌鏉� redirectUrl 閿欒 " + redirectUrl, e);
+ throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, e.getLocalizedMessage());
+ }
+ JSONObject urlObj = new JSONObject();
+ urlObj.put("openUrl", openUrl);
+
+ return ResultVo.createResponseEntity(ResultVo.CODE_MACHINE_OK, ResultVo.MSG_OK, urlObj);
+ }
+
+ @Override
+ public ResponseEntity openServiceNotifyOpenId(IPageData pd, HttpServletRequest request) {
+ JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
+ String authCode = paramIn.getString("code");
+ String state = paramIn.getString("state");
+ String paramStr = CommonCache.getAndRemoveValue(paramIn.getString("urlCode"));
+
+ if (StringUtil.isEmpty(paramStr)) {
+ return ResultVo.redirectPage("/");
+ }
+
+ JSONObject param = JSONObject.parseObject(paramStr);
+ String redirectUrl = param.getString("redirectUrl");
+ String wId = paramIn.getString("wId");
+ SmallWeChatDto smallWeChatDto = null;
+ if (!StringUtil.isEmpty(wId)) {
+ paramIn.put("appId", WechatFactory.getAppId(wId));
+ smallWeChatDto = getSmallWechat(pd, paramIn);
+ }
+ if (smallWeChatDto == null) { //浠庨厤缃枃浠朵腑鑾峰彇 灏忕▼搴忛厤缃俊鎭�
+ smallWeChatDto = new SmallWeChatDto();
+ smallWeChatDto.setAppId(wechatAuthProperties.getWechatAppId());
+ smallWeChatDto.setAppSecret(wechatAuthProperties.getWechatAppSecret());
+ smallWeChatDto.setMchId(wechatAuthProperties.getMchId());
+ smallWeChatDto.setPayPassword(wechatAuthProperties.getKey());
+ }
+
+ String url = WechatConstant.APP_GET_ACCESS_TOKEN_URL.replace("APPID", smallWeChatDto.getAppId())
+ .replace("SECRET", smallWeChatDto.getAppSecret())
+ .replace("CODE", authCode);
+
+ ResponseEntity<String> paramOut = outRestTemplate.getForEntity(url, String.class);
+
+ logger.debug("璋冪敤寰俊鎹㈠幓openId " + paramOut);
+ if (paramOut.getStatusCode() != HttpStatus.OK) {
+ return ResultVo.redirectPage("/");
+ }
+ JSONObject paramObj = JSONObject.parseObject(paramOut.getBody());
+ //鑾峰彇 openId
+ String openId = paramObj.getString("openid");
+ redirectUrl = redirectUrl + "&openId=" + openId;
+
+ //鏌ヨ鏄惁鏈夎溅鐗屽彿
+ OwnerCarOpenUserDto ownerCarOpenUserDto = new OwnerCarOpenUserDto();
+ ownerCarOpenUserDto.setOpenId(openId);
+ List<OwnerCarOpenUserDto> ownerCarOpenUserDtos = ownerCarOpenUserV1InnerServiceSMOImpl.queryOwnerCarOpenUsers(ownerCarOpenUserDto);
+ if (ownerCarOpenUserDtos != null && ownerCarOpenUserDtos.size() > 0) {
+ redirectUrl += ("&carNum=" + ownerCarOpenUserDtos.get(0).getCarNum());
+ }
+
+
+ //redirectUrl = redirectUrl + (redirectUrl.indexOf("?") > 0 ? "&key=" + tmpUserDto.getKey() : "?key=" + tmpUserDto.getKey());
+ return ResultVo.redirectPage(redirectUrl);
+ }
+
/**
* 鍏紬鍙风櫥褰�
*
@@ -561,5 +683,5 @@
public void setRestTemplate(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
-
+
}
--
Gitblit v1.8.0