Browse Source

第三方平台——兼容 城阳||党群e事通,全网发布部分添加

dev_shibei_match
zxc 5 years ago
parent
commit
710c714801
  1. 86
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/FixationAppIdDTO.java
  2. 6
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/ModifyCustomerFormDTO.java
  3. 30
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/result/FixationAppIdResultDTO.java
  4. 15
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ModuleConstant.java
  5. 4
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/constant/ThirdRunTimeInfoConstant.java
  6. 43
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/FixationAppIdDao.java
  7. 9
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/PaUserDao.java
  8. 56
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/entity/FixationAppIdEntity.java
  9. 38
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  10. 8
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/PaCustomerServiceImpl.java
  11. 146
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/WarrantServiceImpl.java
  12. 5
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/constant/WxMaCodeConstant.java
  13. 17
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml
  14. 16
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml

86
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

6
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; private static final long serialVersionUID = -6547893374373422628L;
/** /**
* 待修改的客户Id * 待修改的客户Id 公众号创建的客户
* */ * */
private String oldCustomerId; private String oldCustomerId;
/** /**
* 修改后的客户Id * 修改后的客户Id crm表原来的customerId
*/ */
private String newCustonerId; private String newCustomerId;
} }

30
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;
}

15
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 AUDIT_FAILED = "audit_failed";
String XML = "xml"; String XML = "xml";
String CREATE_TIME = "CreateTime"; 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 FORTY_THOUSAND_AND_THIRTEEN = 40013;
int EIGHTY_NINE_THOUSAND = 89000; int EIGHTY_NINE_THOUSAND = 89000;

4
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 BEGIN_CREATE_OPEN = "============================开始执行绑定开放平台账号===================================";
String CODE_AUDIT_RESULT = "----------------------------------代码审核结果即将插入,需要插入的内容为:%s-----------------------------------------"; 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";
} }

43
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<FixationAppIdEntity> {
/**
* @Description 查询固定AppId信息
* @author zxc
* @date 2020/8/3 4:25 下午
*/
List<FixationAppIdResultDTO> selectFixationInfos();
}

9
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.commons.mybatis.dao.BaseDao;
import com.epmet.dto.PaUserDTO; import com.epmet.dto.PaUserDTO;
import com.epmet.dto.form.CheckPaUserFormDTO; import com.epmet.dto.form.CheckPaUserFormDTO;
import com.epmet.dto.form.CustomerManagerFormDTO;
import com.epmet.entity.PaUserEntity; import com.epmet.entity.PaUserEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -58,4 +59,12 @@ public interface PaUserDao extends BaseDao<PaUserEntity> {
* @Description 根据数据来源和手机号查询公众号用户基本信息校验用户是否存在 * @Description 根据数据来源和手机号查询公众号用户基本信息校验用户是否存在
**/ **/
PaUserDTO selectUser(@Param("id") String id, @Param("source") String source); 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);
} }

56
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

38
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.PaCustomerUserAgencyDTO;
import com.epmet.dto.form.*; import com.epmet.dto.form.*;
import com.epmet.dto.result.*; import com.epmet.dto.result.*;
import com.epmet.feign.OperCrmOpenFeignClient;
import com.epmet.mpaes.WXBizMsgCrypt; import com.epmet.mpaes.WXBizMsgCrypt;
import com.epmet.mpaes.WXXmlToMapUtil; import com.epmet.mpaes.WXXmlToMapUtil;
import com.epmet.redis.RedisThird; import com.epmet.redis.RedisThird;
@ -79,6 +80,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
private AuthResultRecordDao authResultRecordDao; private AuthResultRecordDao authResultRecordDao;
@Autowired @Autowired
private PaCustomerUserAgencyDao paCustomerUserAgencyDao; private PaCustomerUserAgencyDao paCustomerUserAgencyDao;
@Autowired
private FixationAppIdDao fixationAppIdDao;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
@Autowired
private PaUserDao paUserDao;
@Autowired
private PaCustomerServiceImpl paCustomerServiceImpl;
@Value("${third.platform.appId}") @Value("${third.platform.appId}")
private String componentAppId; private String componentAppId;
@ -386,8 +395,11 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
String authCode = authCodeAndTime.getAuthCode(); String authCode = authCodeAndTime.getAuthCode();
String clientType = authCodeAndTime.getClientType(); String clientType = authCodeAndTime.getClientType();
String expiresIn = authCodeAndTime.getExpiresIn(); String expiresIn = authCodeAndTime.getExpiresIn();
// 公众号创建客户的id
String customerId = this.getLoginUserCustomerId(tokenDto); String customerId = this.getLoginUserCustomerId(tokenDto);
Date expiresInTime = this.countExpirationTime(expiresIn); Date expiresInTime = this.countExpirationTime(expiresIn);
//authCode存数据库 //authCode存数据库
AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setAuthCode(authCode); formDTO.setAuthCode(authCode);
@ -402,6 +414,32 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
// 1. 开始获取授权信息(使用授权码) // 1. 开始获取授权信息(使用授权码)
AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType); AuthorizationInfoResultDTO authorizationInfoResultDTO = this.authInfoByAuthCode(authCode, customerId, clientType);
String authAppId = authorizationInfoResultDTO.getAuthorizer_appid(); String authAppId = authorizationInfoResultDTO.getAuthorizer_appid();
List<FixationAppIdResultDTO> 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. 创建开放平台账号并绑定 或者 直接绑定开放平台 // 2. 创建开放平台账号并绑定 或者 直接绑定开放平台
this.createAndBindOpenAccount(customerId,authAppId,clientType); this.createAndBindOpenAccount(customerId,authAppId,clientType);
// 3. 更新 customer_mp 表授权状态和AuthAppId // 3. 更新 customer_mp 表授权状态和AuthAppId

8
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<PaCustomerDao, PaCust
public void modifyCustomer(ModifyCustomerFormDTO formDTO) { public void modifyCustomer(ModifyCustomerFormDTO formDTO) {
//1.修改pa_customer表主键 //1.修改pa_customer表主键
if (baseDao.updateIdById(formDTO) < NumConstant.ONE) { if (baseDao.updateIdById(formDTO) < NumConstant.ONE) {
logger.error(String.format("修改pa_customer表Id失败,待修改的客户Id->%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); throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
} }
//2.修改pa_customer_agency表customerId //2.修改pa_customer_agency表customerId
if (paCustomerAgencyDao.updateCustomerId(formDTO) < NumConstant.ONE) { 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); throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
} }
//3.修改customer_mp表customerId //3.修改customer_mp表customerId
if (customerMpDao.updateCustomerId(formDTO) < NumConstant.ONE) { 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); throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
} }
//4.修改pa_customer_user_agency表customerId //4.修改pa_customer_user_agency表customerId
if (paCustomerUserAgencyDao.updateCustomerId(formDTO) < NumConstant.ONE) { 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); throw new RenException(PaConstant.UPDATE_CUSTOMER_EXCEPTION);
} }

146
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; 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.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.ConvertUtils;
import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.constant.ModuleConstant; import com.epmet.constant.ModuleConstant;
import com.epmet.constant.ThirdRedisKeyConstant;
import com.epmet.constant.ThirdRunTimeInfoConstant; import com.epmet.constant.ThirdRunTimeInfoConstant;
import com.epmet.dao.*; import com.epmet.dao.*;
import com.epmet.dto.form.CodeAuditRecordFormDTO; import com.epmet.dto.form.CodeAuditRecordFormDTO;
import com.epmet.dto.form.MessagePushTextFormDTO; import com.epmet.dto.form.MessagePushTextFormDTO;
import com.epmet.dto.result.AuthorizationInfoResultDTO;
import com.epmet.dto.result.CustomerIdAndClientResultDTO; import com.epmet.dto.result.CustomerIdAndClientResultDTO;
import com.epmet.dto.result.TemplateAndAppIdResultDTO; import com.epmet.dto.result.TemplateAndAppIdResultDTO;
import com.epmet.mpaes.AesException; import com.epmet.mpaes.AesException;
import com.epmet.mpaes.WXBizMsgCrypt; import com.epmet.mpaes.WXBizMsgCrypt;
import com.epmet.mpaes.WXXmlToMapUtil; import com.epmet.mpaes.WXXmlToMapUtil;
import com.epmet.redis.RedisThird;
import com.epmet.service.WarrantService; 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
@ -26,6 +37,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -56,6 +68,8 @@ public class WarrantServiceImpl implements WarrantService {
private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl; private ComponentVerifyTicketServiceImpl componentVerifyTicketServiceImpl;
@Autowired @Autowired
private MessagePushTextDao messagePushTextDao; private MessagePushTextDao messagePushTextDao;
@Autowired
private RedisThird redisThird;
/** /**
* @Description 1.保存代码审核结果 2.更新代码上传结果 * @Description 1.保存代码审核结果 2.更新代码上传结果
@ -134,8 +148,140 @@ public class WarrantServiceImpl implements WarrantService {
Date date = componentVerifyTicketServiceImpl.sToDate(createTime.toString()); Date date = componentVerifyTicketServiceImpl.sToDate(createTime.toString());
messagePushTextFormDTO.setWeChatCreateTime(date); messagePushTextFormDTO.setWeChatCreateTime(date);
messagePushTextDao.insertMessageText(messagePushTextFormDTO); 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【代码审核结果】结束......"); log.info("消息与事件接收URL【代码审核结果】结束......");
return ModuleConstant.SUCCESS; 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("<xml>");
sb.append("<ToUserName><![CDATA["+toUserName+"]]></ToUserName>");
sb.append("<FromUserName><![CDATA["+fromUserName+"]]></FromUserName>");
sb.append("<CreateTime>"+createTime.toString()+"</CreateTime>");
sb.append("<MsgType><![CDATA[text]]></MsgType>");
sb.append("<Content><![CDATA["+content+"]]></Content>");
sb.append("</xml>");
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<String,Map> 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();
}
}
} }

5
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 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=";
/** /**
* 为授权的小程序帐号上传小程序代码. * 为授权的小程序帐号上传小程序代码.
*/ */

17
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/FixationAppIdDao.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.FixationAppIdDao">
<!-- 查询固定AppId信息 -->
<select id="selectFixationInfos" resultType="com.epmet.dto.result.FixationAppIdResultDTO">
SELECT
customer_id AS masterCustomerId,
client_type AS clientType,
app_id AS appId
FROM
fixation_app_id
WHERE
del_flag = 0
</select>
</mapper>

16
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/PaUserDao.xml

@ -50,4 +50,20 @@
AND source = #{source} AND source = #{source}
</select> </select>
<!-- 查询管理员基本信息 -->
<select id="selectManagerInfo" resultType="com.epmet.dto.form.CustomerManagerFormDTO">
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
</select>
</mapper> </mapper>
Loading…
Cancel
Save