|
|
|
@ -3,23 +3,25 @@ package com.kiisoo.ic.wx.service;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.kiisoo.ic.common.utils.WeixinApi;
|
|
|
|
|
import com.kiisoo.ic.config.WxCpConfiguration;
|
|
|
|
|
import com.kiisoo.ic.customer.CustomerService;
|
|
|
|
|
import com.kiisoo.ic.customer.bean.CustomerDTO;
|
|
|
|
|
import com.kiisoo.ic.customer.bean.CustomerModifyDTO;
|
|
|
|
|
import com.kiisoo.ic.customer.entity.OpCustomerEnterpriseWechat;
|
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpCustomerEnterpriseWechatDOMapper;
|
|
|
|
|
import com.kiisoo.ic.customer.service.CustomerEnterpriseService;
|
|
|
|
|
import com.kiisoo.ic.employee.entity.QrCodeVO;
|
|
|
|
|
import com.kiisoo.ic.store.entity.PoiStore;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper;
|
|
|
|
|
import com.kiisoo.ic.wx.aes.AesException;
|
|
|
|
|
import com.kiisoo.ic.wx.aes.WXBizMsgCrypt;
|
|
|
|
|
import com.kiisoo.ic.wx.entity.FollowUserDTO;
|
|
|
|
|
import com.kiisoo.ic.wx.entity.FollowUserTag;
|
|
|
|
|
import com.sun.org.apache.regexp.internal.RE;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
@ -33,10 +35,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static com.kiisoo.ic.config.WxCpConfiguration.APPLICATIONID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author yechenhao
|
|
|
|
|
* @date 2020/03/16 16:45
|
|
|
|
@ -54,6 +57,15 @@ public class WxResponseService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private QWMailListManageService qwMailListManageService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageCpUserStoreDOMapper privilageCpUserStoreDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PoiStoreDOMapper poiStoreDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
|
|
|
|
|
/**
|
|
|
|
|
* 获取微信权限验证(认证服务器时使用)
|
|
|
|
|
*
|
|
|
|
@ -276,7 +288,8 @@ public class WxResponseService {
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public String customerParse(String sVerifyMsgSig, String sVerifyTimeStamp, String sVerifyNonce, String data) throws AesException, ParserConfigurationException, IOException, SAXException, WxErrorException {
|
|
|
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WeixinApi.CUSTOMER_TOKEN, WeixinApi.CUSTOMER_ENCODING_AES_KEY, WeixinApi.CORPID);
|
|
|
|
|
WxCpService cpService = WxCpConfiguration.getCpService(APPLICATIONID);
|
|
|
|
|
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(cpService.getWxCpConfigStorage().getToken(), cpService.getWxCpConfigStorage().getAesKey(), cpService.getWxCpConfigStorage().getCorpId());
|
|
|
|
|
String sMsg = wxcpt.DecryptMsg(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, data);
|
|
|
|
|
log.info(sMsg);
|
|
|
|
|
//解析xml
|
|
|
|
@ -349,10 +362,10 @@ public class WxResponseService {
|
|
|
|
|
//添加客户并添加店铺企业微信信息
|
|
|
|
|
addExternalContact(res);
|
|
|
|
|
|
|
|
|
|
welcomeCodeNode = root.getElementsByTagName("WelcomeCode");
|
|
|
|
|
welcomeCode = welcomeCodeNode.item(0).getTextContent();
|
|
|
|
|
|
|
|
|
|
sendWelcomeMsg(welcomeCode);
|
|
|
|
|
// welcomeCodeNode = root.getElementsByTagName("WelcomeCode");
|
|
|
|
|
// welcomeCode = welcomeCodeNode.item(0).getTextContent();
|
|
|
|
|
//
|
|
|
|
|
// sendWelcomeMsg(welcomeCode);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "add_half_external_contact":
|
|
|
|
@ -404,7 +417,7 @@ public class WxResponseService {
|
|
|
|
|
* @param
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public OpCustomerEnterpriseWechat analyticCustomerEnterprise(String res){
|
|
|
|
|
public OpCustomerEnterpriseWechat analyticCustomerEnterprise(String res){
|
|
|
|
|
JSONObject parseObject = JSON.parseObject(res);
|
|
|
|
|
//解析企业微信信息
|
|
|
|
|
OpCustomerEnterpriseWechat ocew = JSONObject.parseObject(parseObject.getString("external_contact"), OpCustomerEnterpriseWechat.class);
|
|
|
|
@ -442,7 +455,14 @@ public class WxResponseService {
|
|
|
|
|
String[] split = ocew.getState().split("-");
|
|
|
|
|
customerDTO.setShopCode(split[0]);
|
|
|
|
|
customerDTO.setStaffCode(split[1]);
|
|
|
|
|
};
|
|
|
|
|
}else{
|
|
|
|
|
String cpuserId = ocew.getUserid();
|
|
|
|
|
Long storeId = privilageCpUserStoreDOMapper.selectOneByCpUserId(cpuserId);
|
|
|
|
|
PoiStore poiStore = poiStoreDOMapper.selectById(storeId);
|
|
|
|
|
customerDTO.setShopCode(poiStore.getCode());
|
|
|
|
|
String staffCode = poiStoreStaffDOMapper.selectShopManagerByShop(storeId);
|
|
|
|
|
customerDTO.setStaffCode(staffCode);
|
|
|
|
|
}
|
|
|
|
|
//调添加客户接口
|
|
|
|
|
Long customerId = customerService.customerRelation(customerDTO);
|
|
|
|
|
if (null != customerId){
|
|
|
|
|