From 76252b1bbd29fe1f9bb607429069178e47460688 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 23 六月 2020 10:48:41 +0800
Subject: [PATCH] 优化公众号对接接口

---
 service-front/src/main/java/com/java110/front/smo/wechatGateway/impl/WechatGatewaySMOImpl.java |   66 +++++++++++++++++++++++----------
 1 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/smo/wechatGateway/impl/WechatGatewaySMOImpl.java b/service-front/src/main/java/com/java110/front/smo/wechatGateway/impl/WechatGatewaySMOImpl.java
index 056b893..d03f30b 100644
--- a/service-front/src/main/java/com/java110/front/smo/wechatGateway/impl/WechatGatewaySMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/wechatGateway/impl/WechatGatewaySMOImpl.java
@@ -1,15 +1,22 @@
 package com.java110.front.smo.wechatGateway.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.core.base.smo.front.AbstractFrontServiceSMO;
 import com.java110.core.context.IPageData;
 import com.java110.core.factory.WechatFactory;
+import com.java110.dto.owner.OwnerAppUserDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.dto.smallWechatAttr.SmallWechatAttrDto;
 import com.java110.front.properties.WechatAuthProperties;
-import com.java110.front.smo.AppAbstractComponentSMO;
 import com.java110.front.smo.wechatGateway.IWechatGatewaySMO;
 import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.ServiceCodeConstant;
+import com.java110.utils.constant.ServiceCodeSmallWechatAttrConstant;
 import com.java110.utils.constant.ServiceConstant;
 import com.java110.utils.constant.WechatConstant;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,11 +28,13 @@
 import org.springframework.web.client.RestTemplate;
 import org.thymeleaf.util.StringUtils;
 
+import java.util.List;
+
 /**
  * wx鐧诲綍
  */
-@Service("ownerAppLoginSMOImpl")
-public class WechatGatewaySMOImpl extends AppAbstractComponentSMO implements IWechatGatewaySMO {
+@Service("wechatGatewaySMOImpl")
+public class WechatGatewaySMOImpl extends AbstractFrontServiceSMO implements IWechatGatewaySMO {
 
     private final static Logger logger = LoggerFactory.getLogger(WechatGatewaySMOImpl.class);
 
@@ -41,17 +50,10 @@
     @Override
     public ResponseEntity<String>
     gateway(IPageData pd) throws Exception {
-        return businessProcess(pd);
-    }
 
-    @Override
-    protected void validate(IPageData pd, JSONObject paramIn) {
+        JSONObject paramIn = JSONObject.parseObject(pd.getReqData());
         Assert.hasKeyAndValue(paramIn, "fromUserName", "璇锋眰鎶ユ枃涓湭鍖呭惈fromUserName");
         Assert.hasKeyAndValue(paramIn, "toUserName", "璇锋眰鎶ユ枃涓湭鍖呭惈toUserName");
-    }
-
-    @Override
-    protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
 
         logger.debug("doLogin鍏ュ弬锛�" + paramIn.toJSONString());
         String responseStr = "";
@@ -78,6 +80,35 @@
         }
         return new ResponseEntity<>(responseStr, HttpStatus.OK);
     }
+
+    @Override
+    public SmallWeChatDto getSmallWechat(IPageData pd, SmallWeChatDto smallWeChatDto) {
+
+        //List<SmallWeChatDto> smallWeChatDtos = super.getForApis(pd, smallWeChatDto, ServiceCodeSmallWeChatConstant.LIST_SMALL_WE_CHATS, SmallWeChatDto.class);
+        ResponseEntity<String> responseEntity = this.callCenterService(restTemplate, pd, "",
+                ServiceConstant.SERVICE_API_URL + "/api/smallWeChat.listSmallWeChats?appId="
+                        + smallWeChatDto.getAppId() + "&page=1&row=1", HttpMethod.GET);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return null;
+        }
+        JSONObject smallWechatObj = JSONObject.parseObject(responseEntity.getBody().toString());
+        JSONArray smallWeChats = smallWechatObj.getJSONArray("smallWeChats");
+
+
+        if (smallWeChats == null || smallWeChats.size() < 1) {
+            return null;
+        }
+        smallWeChatDto = BeanConvertUtil.covertBean(smallWeChats.get(0), SmallWeChatDto.class);
+        SmallWechatAttrDto smallWechatAttrDto = new SmallWechatAttrDto();
+        smallWechatAttrDto.setCommunityId(smallWeChatDto.getObjId());
+        smallWechatAttrDto.setWechatId(smallWeChatDto.getWeChatId());
+        List<SmallWechatAttrDto> smallWechatAttrs = super.getForApis(pd, smallWechatAttrDto, ServiceCodeSmallWechatAttrConstant.LIST_SMALLWECHATATTRS, SmallWechatAttrDto.class);
+
+        smallWeChatDto.setSmallWechatAttrs(smallWechatAttrs);
+        return smallWeChatDto;
+    }
+
 
     public RestTemplate getRestTemplate() {
         return restTemplate;
@@ -168,16 +199,11 @@
      * @return
      */
     private boolean judgeBindOwner(IPageData pd, String openId) {
+        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+        ownerAppUserDto.setOpenId(openId);
+        List<OwnerAppUserDto> ownerAppUserDtos = super.getForApis(pd, ownerAppUserDto, ServiceCodeConstant.LIST_APPUSERBINDINGOWNERS, OwnerAppUserDto.class);
 
-        ResponseEntity responseEntity = this.callCenterService(restTemplate, pd, "", ServiceConstant.SERVICE_API_URL + "/api/owner.listAppUserBindingOwners?openId=" + openId, HttpMethod.GET);
-
-        if (responseEntity.getStatusCode() != HttpStatus.OK) {
-            return true;
-        }
-
-        JSONObject ownerInfo = JSONObject.parseObject(responseEntity.getBody().toString());
-
-        if (ownerInfo.getInteger("total") != 1) {
+        if (ownerAppUserDtos == null || ownerAppUserDtos.size() != 1) {
             return false;
         }
         return true;

--
Gitblit v1.8.0