From b2d360d9113b6955287108ca9e90d76a1f3c1419 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期日, 29 九月 2024 15:05:11 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/zbomyoujia

---
 server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java |   92 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
index bd00ca2..b214562 100644
--- a/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/biz/zbom/impl/ZbomCRMServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.biz.zbom.ZbomCRMService;
 import com.doumee.biz.zbom.model.crm.*;
 import com.doumee.biz.zbom.model.crm.response.CRMBaseResponse;
@@ -17,14 +18,22 @@
 import com.doumee.dao.business.CustomerLogMapper;
 import com.doumee.dao.business.model.CrmInterfaceLog;
 import com.doumee.dao.business.model.CustomerLog;
+import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.model.Users;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.util.Base64Util;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Base64Utils;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.*;
 
@@ -41,9 +50,10 @@
     private CustomerLogMapper customerLogMapper;
     @Autowired
     private CrmInterfaceLogMapper crmInterfaceLogMapper;
-
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
 
 
 
@@ -54,7 +64,10 @@
      */
     @Override
     @Async
-    public int dealCustomerLogData(CustomerLog customerLog){
+    public void dealCustomerLogData(CustomerLog customerLog){
+        if(StringUtils.isBlank(customerLog.getPhone())){
+            return;
+        }
         CrmCustomerInfoRequest entity = new CrmCustomerInfoRequest();
         entity.setId(customerLog.getId());
         entity.setName(customerLog.getName());
@@ -62,6 +75,15 @@
         entity.setAreaname(customerLog.getAreaName());
         entity.setAreacode(customerLog.getAreaCode());
         entity.setOpenid(customerLog.getOpenid());
+        entity.setUserData(new ArrayList<>());
+        if(StringUtils.isNotBlank(customerLog.getUsernames())){
+            String[] names = customerLog.getUsernames().split(",");
+            for(String str:names){
+                CrmCustomerUsernameRequest usernameRequest = new CrmCustomerUsernameRequest();
+                usernameRequest.setUserName(str);
+                entity.getUserData().add(usernameRequest);//瀵艰喘鐧婚檰璐﹀彿闆嗗悎
+            }
+        }
 //        鎻愪氦绫诲瀷 0-娴嬭瘯瑁呬慨椋庢牸锛�1-0鍏冨畾鍒讹紱2瑁呬慨璁$畻鍣�
         if(Constants.equalsInteger(customerLog.getType(),Constants.ONE)){
             entity.setSource(CRMConstants.CRM_SOURCE.SOURCE_MP01);
@@ -70,6 +92,7 @@
             entity.setSource(CRMConstants.CRM_SOURCE.SOURCE_MP02);
             entity.setChannel(CRMConstants.CRM_SOURCE.SOURCE_MP02+"00");
         }
+//        entity.setOpenId(customerLog.getOpenid());
         entity.setOpenid(customerLog.getOpenid());
         entity.setDate(DateUtil.dateToString(customerLog.getCreateDate(),"yyyy/MM/dd HH:mm"));
         CrmCustomerPostRequest obj = new CrmCustomerPostRequest();
@@ -91,7 +114,6 @@
                 .set(CustomerLog::getCrmStatus,Constants.ONE )
                 .set(CustomerLog::getCrmInfo,crmInfo )
                 .set(CustomerLog::getCrmDate,new Date() ));// 鏇存柊鐘舵��
-        return status;// 榛樿澶辫触
     }
     /**
      * 鑾峰彇瀵艰喘缁戝畾鍒楄〃
@@ -129,7 +151,7 @@
 
     public   <T> CRMBaseResponse<T> sendCusHttpRequest(String interfaceUrl,  String name,  String param){
         log.info("銆�"+name+"銆�================寮�濮�===="+ JSONObject.toJSONString(param));
-        String appKey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_KEY);
+        String appKey = (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_POSTCUS_API_KEY);
         String url = redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL) + interfaceUrl ;
         long _t = System.currentTimeMillis();
         if (StringUtils.isNotBlank(appKey)||StringUtils.isNotBlank(url)) {
@@ -242,22 +264,66 @@
      * @return
      */
     @Override
-    public    String getCrmGoUrl(String userName){
-        StringBuffer sb = new StringBuffer();
-        String result = null;
+    public    String getCrmGoUrl(String userName,Integer type,String iamId){
         try {
             // 鍒涘缓StringBuffer瀵硅薄鐢ㄦ潵鎿嶄綔瀛楃涓�
             int _t = (int)(System.currentTimeMillis());
-            String  appkey =  (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_AUTH_API_KEY);
-            String  url =  (String) redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL)
-                    +CRMConstants.IntegerUrl.GO_CRM_AUTH_URL
-                    + "?timestamp="+_t
-                    +"&agent_phone_number=" + URLEncoder.encode(userName, "UTF-8")
-                    + "&bindKey=mp&sign="+ DigestUtils.md5Hex( _t + appkey);;
+            String pageKey ="mp";//瀹㈡埛鍒楄〃椤甸潰鐮�
+            String fileUrl = systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_URL_MP).getCode();
+            if(Constants.equalsInteger(type,Constants.ONE)){
+                pageKey = "mpAddIntention";//鏂板鎰忓悜椤甸潰鐮�
+                fileUrl = systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_URL_MP_ADDINTENTION).getCode();
+            }
+            String  url =   redisTemplate.opsForValue().get(Constants.RedisKeys.ZBOM_CRM_API_URL)
+                    + CRMConstants.IntegerUrl.GO_CRM_AUTH_URL
+                    + "?bindKey="+pageKey
+                    + "&tick=" + this.getTick(iamId, fileUrl);
             return url;
         }catch (Exception e){
             e.printStackTrace();
         }
        throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鑾峰彇璺宠浆鍦板潃澶辫触鍝︼紒");
     }
+
+    public String getTick(String iamId, String fileUrL) throws UnsupportedEncodingException {
+        Map<String,Object> map = new HashMap<>();
+        //鐢ㄦ埛IAM涓婚敭
+        map.put("ssouserid",iamId);
+        //鍞墠灏忕▼搴廰ppid
+        map.put("appid",systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_IAM_BUSINESS_APPID).getCode());
+        //璺宠浆鍦板潃
+        map.put("rediUrl",fileUrL);
+        //鏃堕棿鎴�
+        map.put("timestamp",System.currentTimeMillis()/1000+"");
+        //C绔皬绋嬪簭appid
+        map.put("sourceappid",systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_IAM_CUSTOMER_APPID).getCode());
+        System.out.println(JSONObject.toJSONString(map));
+        //鑾峰彇tick
+        String tick = ZbomCRMServiceImpl.encrypt(
+                systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_URL_PRIVATE_KEY).getCode()
+                ,JSONObject.toJSONString(map)
+                ,systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_CRM_API_URL_INIT_VECTOR).getCode());
+
+        String tickEncoder = URLEncoder.encode(tick,"UTF-8");
+
+        return tickEncoder;
+    }
+
+
+    public static String encrypt(String key, String value,String initVector) {
+        try {
+            IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
+            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
+            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
+            byte[] encrypted = cipher.doFinal(value.getBytes());
+            return Base64Utils.encodeToString(encrypted);
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return null;
+    }
+
+
 }

--
Gitblit v1.9.3