From 710c714801bc2c905882fb6bd24fcc502928a536 Mon Sep 17 00:00:00 2001
From: zxc <1272811460@qq.com>
Date: Mon, 3 Aug 2020 17:58:01 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0?=
=?UTF-8?q?=E2=80=94=E2=80=94=E5=85=BC=E5=AE=B9=20=E5=9F=8E=E9=98=B3?=
=?UTF-8?q?=EF=BD=9C=EF=BD=9C=E5=85=9A=E7=BE=A4e=E4=BA=8B=E9=80=9A?=
=?UTF-8?q?=EF=BC=8C=E5=85=A8=E7=BD=91=E5=8F=91=E5=B8=83=E9=83=A8=E5=88=86?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/epmet/dto/FixationAppIdDTO.java | 86 +++++++++++
.../epmet/dto/form/ModifyCustomerFormDTO.java | 6 +-
.../dto/result/FixationAppIdResultDTO.java | 30 ++++
.../com/epmet/constant/ModuleConstant.java | 15 ++
.../constant/ThirdRunTimeInfoConstant.java | 4 +
.../java/com/epmet/dao/FixationAppIdDao.java | 43 ++++++
.../main/java/com/epmet/dao/PaUserDao.java | 9 ++
.../com/epmet/entity/FixationAppIdEntity.java | 56 +++++++
.../ComponentVerifyTicketServiceImpl.java | 38 +++++
.../service/impl/PaCustomerServiceImpl.java | 8 +-
.../service/impl/WarrantServiceImpl.java | 146 ++++++++++++++++++
.../wxapi/constant/WxMaCodeConstant.java | 5 +
.../resources/mapper/FixationAppIdDao.xml | 17 ++
.../src/main/resources/mapper/PaUserDao.xml | 16 ++
14 files changed, 472 insertions(+), 7 deletions(-)
create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FixationAppIdDTO.java
create mode 100644 epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/FixationAppIdResultDTO.java
create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FixationAppIdDao.java
create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FixationAppIdEntity.java
create mode 100644 epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FixationAppIdDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FixationAppIdDTO.java
new file mode 100644
index 0000000000..ad55fbb43d
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FixationAppIdDTO.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.epmet.dto;
+
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+
+/**
+ * 固定的AppId表
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2020-08-03
+ */
+@Data
+public class FixationAppIdDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * ID
+ */
+ private String id;
+
+ /**
+ * 小程序AppId
+ */
+ private String appId;
+
+ /**
+ * 客户Id
+ */
+ private String customerId;
+
+ /**
+ * 客户端类型resi:居民端,work:工作端
+ */
+ private String clientType;
+
+ /**
+ * 删除状态0:正常,已删除
+ */
+ private Integer delFlag;
+
+ /**
+ * 乐观锁
+ */
+ private Integer revision;
+
+ /**
+ * 创建人
+ */
+ private String createdBy;
+
+ /**
+ * 创建时间
+ */
+ private Date createdTime;
+
+ /**
+ * 更新人
+ */
+ private String updatedBy;
+
+ /**
+ * 更新时间
+ */
+ private Date updatedTime;
+
+}
\ No newline at end of file
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ModifyCustomerFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ModifyCustomerFormDTO.java
index 3b6afe2a8f..aff37e587b 100644
--- a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ModifyCustomerFormDTO.java
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ModifyCustomerFormDTO.java
@@ -14,13 +14,13 @@ public class ModifyCustomerFormDTO implements Serializable {
private static final long serialVersionUID = -6547893374373422628L;
/**
- * 待修改的客户Id
+ * 待修改的客户Id 公众号创建的客户
* */
private String oldCustomerId;
/**
- * 修改后的客户Id
+ * 修改后的客户Id crm表原来的customerId
*/
- private String newCustonerId;
+ private String newCustomerId;
}
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/FixationAppIdResultDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/FixationAppIdResultDTO.java
new file mode 100644
index 0000000000..d27aa43ef7
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/FixationAppIdResultDTO.java
@@ -0,0 +1,30 @@
+package com.epmet.dto.result;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @Author zxc
+ * @DateTime 2020/8/3 4:15 下午
+ */
+@Data
+public class FixationAppIdResultDTO implements Serializable {
+
+ private static final long serialVersionUID = 3810567059789358255L;
+
+ /**
+ * 客户ID
+ */
+ private String masterCustomerId;
+
+ /**
+ * 客户端类型:resi:居民端,work:工作端
+ */
+ private String clientType;
+
+ /**
+ * AppId
+ */
+ private String appId;
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
index 1bc5e3b98b..bbe5ac73b9 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
@@ -86,6 +86,21 @@ public interface ModuleConstant {
String AUDIT_FAILED = "audit_failed";
String XML = "xml";
String CREATE_TIME = "CreateTime";
+ String QUERY_AUTH_CODE = "QUERY_AUTH_CODE";
+ String _CALL_BACK = "_callback";
+ String FROM_CALLBACK = "from_callback";
+ String APPLICATION_JSON = "application/json";
+ String _FROM_API = "_from_api";
+
+ /**
+ * 微信模推送给第三方平台方 Content固定格式
+ */
+ String TESTCOMPONENT_MSG_TYPE_TEXT = "TESTCOMPONENT_MSG_TYPE_TEXT";
+
+ /**
+ * 第三方平台方立马回应文本消息并最终触达粉丝 Content固定格式
+ */
+ String TESTCOMPONENT_MSG_TYPE_TEXT_callback = "TESTCOMPONENT_MSG_TYPE_TEXT_callback";
int FORTY_THOUSAND_AND_THIRTEEN = 40013;
int EIGHTY_NINE_THOUSAND = 89000;
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
index 188c19a89e..1f896bae8f 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
@@ -103,4 +103,8 @@ public interface ThirdRunTimeInfoConstant {
String BEGIN_CREATE_OPEN = "============================开始执行绑定开放平台账号===================================";
String CODE_AUDIT_RESULT = "----------------------------------代码审核结果即将插入,需要插入的内容为:%s-----------------------------------------";
+
+ String TEXT_MESSAGE_LOG_INFO = "content:%s,content[1]:%s,fromUserName:%s,toUserName:%s";
+
+ String SEND_MESSAGE_XML = "要发送的xml内容为:%s";
}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FixationAppIdDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FixationAppIdDao.java
new file mode 100644
index 0000000000..ceb297a05c
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FixationAppIdDao.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.epmet.dao;
+
+import com.epmet.commons.mybatis.dao.BaseDao;
+import com.epmet.dto.result.FixationAppIdResultDTO;
+import com.epmet.entity.FixationAppIdEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * 固定的AppId表
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2020-08-03
+ */
+@Mapper
+public interface FixationAppIdDao extends BaseDao {
+
+ /**
+ * @Description 查询固定AppId信息
+ * @author zxc
+ * @date 2020/8/3 4:25 下午
+ */
+ List selectFixationInfos();
+
+}
\ No newline at end of file
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java
index 5595a3d61f..49586a2370 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java
@@ -20,6 +20,7 @@ package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.CheckPaUserFormDTO;
+import com.epmet.dto.form.CustomerManagerFormDTO;
import com.epmet.entity.PaUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -58,4 +59,12 @@ public interface PaUserDao extends BaseDao {
* @Description 根据数据来源和手机号查询公众号用户基本信息,校验用户是否存在
**/
PaUserDTO selectUser(@Param("id") String id, @Param("source") String source);
+
+ /**
+ * @Description 查询管理员基本信息
+ * @param customerId
+ * @author zxc
+ * @date 2020/8/3 5:21 下午
+ */
+ CustomerManagerFormDTO selectManagerInfo(@Param("customerId") String customerId);
}
\ No newline at end of file
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FixationAppIdEntity.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FixationAppIdEntity.java
new file mode 100644
index 0000000000..4d7a70e7e8
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FixationAppIdEntity.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2018 人人开源 https://www.renren.io
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.epmet.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+/**
+ * 固定的AppId表
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2020-08-03
+ */
+@Data
+@EqualsAndHashCode(callSuper=false)
+@TableName("fixation_app_id")
+public class FixationAppIdEntity extends BaseEpmetEntity {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 小程序AppId
+ */
+ private String appId;
+
+ /**
+ * 客户Id
+ */
+ private String customerId;
+
+ /**
+ * 客户端类型resi:居民端,work:工作端
+ */
+ private String clientType;
+
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
index c54dd03a31..67bcddbac0 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
@@ -15,6 +15,7 @@ import com.epmet.dao.*;
import com.epmet.dto.PaCustomerUserAgencyDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
+import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.mpaes.WXBizMsgCrypt;
import com.epmet.mpaes.WXXmlToMapUtil;
import com.epmet.redis.RedisThird;
@@ -79,6 +80,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
private AuthResultRecordDao authResultRecordDao;
@Autowired
private PaCustomerUserAgencyDao paCustomerUserAgencyDao;
+ @Autowired
+ private FixationAppIdDao fixationAppIdDao;
+ @Autowired
+ private OperCrmOpenFeignClient operCrmOpenFeignClient;
+ @Autowired
+ private PaUserDao paUserDao;
+ @Autowired
+ private PaCustomerServiceImpl paCustomerServiceImpl;
@Value("${third.platform.appId}")
private String componentAppId;
@@ -386,8 +395,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String authCode = authCodeAndTime.getAuthCode();
String clientType = authCodeAndTime.getClientType();
String expiresIn = authCodeAndTime.getExpiresIn();
+ // 公众号创建客户的id
String customerId = this.getLoginUserCustomerId(tokenDto);
Date expiresInTime = this.countExpirationTime(expiresIn);
+
+
//authCode存数据库
AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setAuthCode(authCode);
@@ -402,6 +414,32 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
// 1. 开始获取授权信息(使用授权码)
AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType);
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid();
+ List fixationAppIdResultDTOS = fixationAppIdDao.selectFixationInfos();
+ String finalCustomerId = customerId;//
+ fixationAppIdResultDTOS.forEach(fixationAppId -> {
+ if (fixationAppId.getAppId().equals(authAppId)){
+ // TODO 是城阳项目或者党群e事通
+ // crm表中的customerId【原customerId】
+ String masterCustomerId = fixationAppId.getMasterCustomerId();
+ formDTO.setCustomerId(masterCustomerId);
+ authCodeDao.deleteCustomerAuthCode(finalCustomerId,clientType);
+ authCodeDao.insertRedirectAuthCode(formDTO);
+ //authCode存缓存
+ redisThird.setAuthCode(formDTO);
+
+ ModifyCustomerFormDTO modifyCustomer = new ModifyCustomerFormDTO();
+ modifyCustomer.setOldCustomerId(finalCustomerId);
+ modifyCustomer.setNewCustomerId(masterCustomerId);
+ paCustomerServiceImpl.modifyCustomer(modifyCustomer);
+
+ // 管理员授权
+ CustomerManagerFormDTO customerManager = paUserDao.selectManagerInfo(finalCustomerId);
+ customerManager.setCustomerId(finalCustomerId);
+ operCrmOpenFeignClient.addManager(customerManager);
+ }
+ });
+ //替换 新customerId为旧customerId
+ customerId = formDTO.getCustomerId();
// 2. 创建开放平台账号并绑定 或者 直接绑定开放平台
this.createAndBindOpenAccount(customerId,authAppId,clientType);
// 3. 更新 customer_mp 表授权状态和AuthAppId
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
index 3f72254505..ae9d730829 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
@@ -513,22 +513,22 @@ public class PaCustomerServiceImpl extends BaseServiceImpl%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustonerId()));
+ logger.error(String.format("修改pa_customer表Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustomerId()));
throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
}
//2.修改pa_customer_agency表customerId
if (paCustomerAgencyDao.updateCustomerId(formDTO) < NumConstant.ONE) {
- logger.error(String.format("修改pa_customer_agency表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustonerId()));
+ logger.error(String.format("修改pa_customer_agency表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustomerId()));
throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
}
//3.修改customer_mp表customerId
if (customerMpDao.updateCustomerId(formDTO) < NumConstant.ONE) {
- logger.error(String.format("修改customer_mp表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustonerId()));
+ logger.error(String.format("修改customer_mp表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustomerId()));
throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
}
//4.修改pa_customer_user_agency表customerId
if (paCustomerUserAgencyDao.updateCustomerId(formDTO) < NumConstant.ONE) {
- logger.error(String.format("修改pa_customer_user_agency表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustonerId()));
+ logger.error(String.format("修改pa_customer_user_agency表客户Id失败,待修改的客户Id->%s,修改后的客户Id->%s", formDTO.getOldCustomerId(), formDTO.getNewCustomerId()));
throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java
index 956c5c31e6..d5e2249cef 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java
@@ -1,18 +1,29 @@
package com.epmet.service.impl;
+import cn.hutool.json.JSONObject;
+import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.client.config.utils.IOUtils;
+import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.ConvertUtils;
+import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.constant.ModuleConstant;
+import com.epmet.constant.ThirdRedisKeyConstant;
import com.epmet.constant.ThirdRunTimeInfoConstant;
import com.epmet.dao.*;
import com.epmet.dto.form.CodeAuditRecordFormDTO;
import com.epmet.dto.form.MessagePushTextFormDTO;
+import com.epmet.dto.result.AuthorizationInfoResultDTO;
import com.epmet.dto.result.CustomerIdAndClientResultDTO;
import com.epmet.dto.result.TemplateAndAppIdResultDTO;
import com.epmet.mpaes.AesException;
import com.epmet.mpaes.WXBizMsgCrypt;
import com.epmet.mpaes.WXXmlToMapUtil;
+import com.epmet.redis.RedisThird;
import com.epmet.service.WarrantService;
+import com.epmet.wxapi.constant.WxMaCodeConstant;
+import com.fasterxml.jackson.core.JsonEncoding;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
@@ -26,6 +37,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -56,6 +68,8 @@ public class WarrantServiceImpl implements WarrantService {
private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl;
@Autowired
private MessagePushTextDao messagePushTextDao;
+ @Autowired
+ private RedisThird redisThird;
/**
* @Description 1.保存代码审核结果 2.更新代码上传结果
@@ -134,8 +148,140 @@ public class WarrantServiceImpl implements WarrantService {
Date date = componentVerifyTicketServiceImpl.sToDate(createTime.toString());
messagePushTextFormDTO.setWeChatCreateTime(date);
messagePushTextDao.insertMessageText(messagePushTextFormDTO);
+// switch (messagePushTextFormDTO.getContent()){
+// //测试公众号处理用户消息
+// case ModuleConstant.TESTCOMPONENT_MSG_TYPE_TEXT:
+//
+//
+// }
+// if (messagePushTextFormDTO.getContent().startsWith(ModuleConstant.QUERY_AUTH_CODE)){
+// // 测试公众号使用客服消息接口处理用户消息
+// String content = messagePushTextFormDTO.getContent();
+// String contentBefore = content.substring(NumConstant.ZERO, content.indexOf(ThirdRedisKeyConstant.COLON));
+// //auth_code
+// String queryAuthCode = content.substring(contentBefore.length() + NumConstant.ONE, content.length());
+//
+// }
}
log.info("消息与事件接收URL【代码审核结果】结束......");
return ModuleConstant.SUCCESS;
}
+
+ /**
+ * 方法描述: 类型为enevt的时候,拼接
+ * @param request
+ * @param response
+ * @param event
+ * @param toUserName 发送接收人
+ * @param fromUserName 发送人
+ * @author zxc
+ */
+ public void replyEventMessage(HttpServletRequest request, HttpServletResponse response,
+ String event, String toUserName, String fromUserName)
+ throws DocumentException, IOException {
+ String content = event + ModuleConstant.FROM_CALLBACK;
+ replyTextMessage(request,response,content,toUserName,fromUserName);
+ }
+
+
+ /**
+ * 立马回应文本消息并最终触达粉丝
+ * @param content 文本
+ * @param toUserName 发送接收人
+ * @param fromUserName 发送人
+ * @author zxc
+ */
+ public void processTextMessage(HttpServletRequest request, HttpServletResponse response,
+ String content,String toUserName, String fromUserName)
+ throws IOException, DocumentException{
+ if(ModuleConstant.TESTCOMPONENT_MSG_TYPE_TEXT.equals(content)){
+ String returnContent = content+ModuleConstant._CALL_BACK;
+ replyTextMessage(request,response,returnContent,toUserName,fromUserName);
+ }else if(StringUtils.startsWithIgnoreCase(content, ModuleConstant.QUERY_AUTH_CODE)){
+ response.getWriter().print("");//需在5秒内返回空串表明暂时不回复,然后再立即使用客服消息接口发送消息回复粉丝
+ log.info(String.format(ThirdRunTimeInfoConstant.TEXT_MESSAGE_LOG_INFO,content,content.split(ThirdRedisKeyConstant.COLON)[NumConstant.ONE],fromUserName,toUserName));
+ //接下来客服API再回复一次消息
+ replyApiTextMessage(content.split(ThirdRedisKeyConstant.COLON)[NumConstant.ONE],toUserName);
+ }
+ }
+
+
+
+ /**
+ * 方法描述: 直接返回给微信开放平台
+ * @param request
+ * @param response
+ * @param content 文本
+ * @param toUserName 发送接收人
+ * @param fromUserName 发送人
+ * @author zxc
+ */
+ public void replyTextMessage(HttpServletRequest request, HttpServletResponse response,
+ String content,String toUserName, String fromUserName)
+ throws DocumentException, IOException {
+ Long createTime = System.currentTimeMillis() / 1000;
+ StringBuffer sb = new StringBuffer(512);
+ sb.append("");
+ sb.append(" ");
+ sb.append(" ");
+ sb.append(""+createTime.toString()+" ");
+ sb.append(" ");
+ sb.append(" ");
+ sb.append(" ");
+ String replyMsg = sb.toString();
+ log.info(String.format(ThirdRunTimeInfoConstant.SEND_MESSAGE_XML,replyMsg));
+ returnJSON(replyMsg,response);
+ }
+
+ /**
+ * 方法描述: 调用客服回复消息给粉丝
+ * @param auth_code
+ * @param fromUserName
+ * @throws DocumentException
+ * @throws IOException
+ * @return void
+ * @author zxc
+ */
+ public void replyApiTextMessage(String auth_code, String fromUserName) throws DocumentException, IOException {
+ // 得到微信授权成功的消息后,应该立刻进行处理!!相关信息只会在首次授权的时候推送过来
+ //第三方平台【component_access_token】
+ String componentAccessToken = redisThird.getComponentAccessToken();
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
+ jsonObject.put(ModuleConstant.COMPONENT_APPID, componentAppId);
+ jsonObject.put(ModuleConstant.AUTHORIZATION_CODE, auth_code);
+ String authInfo = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_QUERY_AUTH_URL + componentAccessToken, JSON.toJSONString(jsonObject)).getData();
+ HashMap hashMap = JSON.parseObject(authInfo, HashMap.class);
+ Map map = hashMap.get(ModuleConstant.AUTHORIZATION_INFO);
+ AuthorizationInfoResultDTO authorizationInfoResultDTO = ConvertUtils.mapToEntity(map, AuthorizationInfoResultDTO.class);
+ String authorizer_access_token = authorizationInfoResultDTO.getAuthorizer_access_token();
+
+ JSONObject json = new JSONObject();
+ json.put("touser",fromUserName);
+ json.put("msgtype", "text");
+ json.put("text", "{\"content\":\""+auth_code+ModuleConstant._FROM_API+"\"}");
+
+ String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.SEND_MESSAGE_CUSTOM + authorizer_access_token, JSON.toJSONString(json)).getData();
+ log.info("客服发送接口返回值:"+data);
+ }
+
+
+ /**
+ * 方法描述: 返回数据到请求方
+ * @param data 数据
+ * @param response
+ * @author zxc
+ */
+ public void returnJSON(Object data,HttpServletResponse response) {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonEncoding encoding = JsonEncoding.UTF8;
+ response.setContentType(ModuleConstant.APPLICATION_JSON);
+ JsonGenerator generator = objectMapper.getJsonFactory().
+ createJsonGenerator(response.getOutputStream(), encoding);
+ objectMapper.writeValue(generator, data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
index 75ce684c49..f27eaff2c1 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
@@ -76,6 +76,11 @@ public interface WxMaCodeConstant {
*/
String API_OPEN_GET = "https://api.weixin.qq.com/cgi-bin/open/get?access_token=";
+ /**
+ *
+ */
+ String SEND_MESSAGE_CUSTOM = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=";
+
/**
* 为授权的小程序帐号上传小程序代码.
*/
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml
new file mode 100644
index 0000000000..b688f5f77d
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+ SELECT
+ customer_id AS masterCustomerId,
+ client_type AS clientType,
+ app_id AS appId
+ FROM
+ fixation_app_id
+ WHERE
+ del_flag = 0
+
+
\ No newline at end of file
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml
index 628eefe53f..4b67271ab7 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml
@@ -50,4 +50,20 @@
AND source = #{source}
+
+
+ SELECT
+ pu.real_name AS realName,
+ pu.gender AS gender,
+ pu.phone AS mobile
+ FROM
+ pa_user pu
+ LEFT JOIN customer_mp cm ON cm.created_by = pu.id
+ WHERE
+ pu.del_flag = '0'
+ AND cm.CUSTOMER_ID = #{customerId}
+ AND CM.DEL_FLAG = '0'
+ LIMIT 1
+
+
\ No newline at end of file