瀏覽代碼

客资聊天内容

cqp 1 月之前
父節點
當前提交
643ac5f461

+ 22 - 0
app/Http/Controllers/Api/DaHuangFengController.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\DaHuangFengService;
+use Illuminate\Http\Request;
+
+class DaHuangFengController extends BaseController
+{
+    public function getChatDetail(Request $request)
+    {
+        $service = new DaHuangFengService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->getOrderDetail($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 1 - 1
app/Service/CustomerService.php

@@ -531,7 +531,7 @@ class CustomerService extends Service
 
     public function customerCommonSearch($data,$user, $field = []){
         if(empty($field)){
-            $field = ['title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','consulting_product_new','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time'];
+            $field = ['title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','consulting_product_new','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time','c_third_platform_id'];
         }
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)

+ 145 - 0
app/Service/DaHuangFengService.php

@@ -0,0 +1,145 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\BasicType;
+use App\Model\CustomerFromThreePlatForm;
+use App\Model\Product;
+use App\Model\SalesOrder;
+use App\Model\SalesOrderInfo;
+use App\Model\SalesOrderProductInfo;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class DaHuangFengService extends Service
+{
+    public $appKey = 'b993bb5a17ce4d2db6cb038f02c9d646';
+    public $appSecret = '054f5839ac624572916fc661f1412060';
+    public $host = 'https://open.byering.com/';
+
+    //聊天信息
+    public $url_order_detail = 'saas/open/api/chat/getChatFlow';
+
+    public function getOrderDetail($data){
+        if(empty($data['customer_id'])) return [false, "客户ID不能为空"];
+        $plat_customer = CustomerFromThreePlatForm::where('del_time',3)
+            ->where('customer_id',$data['customer_id'])
+            ->first();
+        if(empty($plat_customer)) return [false, "第三方客户信息不存在,无法获取到聊天信息"];
+        $plat_customer = $plat_customer->toArray();
+        $cursor = $data['cursor'] ?? 0;
+        $pageSize = $data['pageSize'] ?? 20;
+
+        $timestamp = time();
+        $param['appKey'] = $this->appKey;
+        $param['timestamp'] = $timestamp;
+        $data = [
+            'clueId' => $plat_customer['clueId'],
+            'userOpenId' => $plat_customer['fromUserId'],
+            'cursor' => $cursor,
+            'pageSize' => $pageSize,
+        ];
+//        $data = ["clueId" => "558a9a7e-a17c-4672-b67d-8788b6356f2e", "userOpenId" => "6f7e4ef2-c43b-4c79-9b39-ac97aa77f2ee", "cursor" => 0, "pageSize" => 20];
+        $json_data = json_encode($data);
+        $param['data'] = $json_data;
+        $sign = $this->makeSign($param);
+        $param['sign'] = $sign;
+        list($status, $msg) = $this->post_big($this->host . $this->url_order_detail, $param);
+        if(! $status) return [false, $msg];
+
+        return [true, $msg];
+    }
+
+    public function curlForOrderDetail($data){
+    }
+
+    public function makeSign($params)
+    {
+        // 1. 去掉 sign 字段
+        unset($params['sign']);
+
+        // 2. 按字段名升序排序
+        ksort($params);
+
+        // 3. 拼接成 key=value&key=value...
+        $paramsStr = '';
+        foreach ($params as $key => $value) {
+            $paramsStr .= ($paramsStr === '' ? '' : '&') . $key . '=' . $value;
+        }
+
+        // 4. Base64 编码
+        $base64Str = base64_encode($paramsStr);
+
+        // 5. appSecret:Base64Str 拼接
+        $strToEncrypt = $this->appSecret . ':' . $base64Str;
+
+        // 6. SHA1 加密
+        return sha1($strToEncrypt);
+    }
+
+    public function getSign($timestamp, $data){
+        $appKey = $this->appKey;
+        $appSecret = $this->appSecret;
+
+        $params = [
+            'appKey'   => $appKey,
+            'timestamp'=> (string)$timestamp,
+            'data'     => $data,
+        ];
+
+        ksort($params);
+
+        $paramsStr = '';
+        foreach ($params as $key => $value) {
+            $paramsStr .= ($paramsStr === '' ? '' : '&') . $key . '=' . $value;
+        }
+
+//        echo "拼接结果: {$paramsStr}\n";
+
+        $base64Str = base64_encode($paramsStr);
+
+        $strToEncrypt = $appSecret . ':' . $base64Str;
+
+        $sign = sha1($strToEncrypt);
+
+//        echo "sign: {$sign}\n";
+
+        return $sign;
+    }
+
+    //发送请求
+    public function post_big($url, $data, $timeout = 20){
+        $header = array("Content-type:application/json;charset='utf-8'");
+
+        Log::channel('apiLog')->info('bigPOST', ["api" => $url , "param" => $data ,"header" => $header]);
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_ENCODING, '');
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+
+        if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        $r = curl_exec($ch);
+
+        if ($r === false) {
+            // 获取错误号
+            $errorNumber = curl_errno($ch);
+            // 获取错误信息
+            $errorMessage = curl_error($ch);
+            $message = "cURL Error #{$errorNumber}: {$errorMessage}";
+
+            Log::channel('apiLog')->info('bigPOST结果', ["message" => $message]);
+            return [false, "cURL Error #{$errorNumber}: {$errorMessage}"];
+        }
+        curl_close($ch);
+
+        Log::channel('apiLog')->info('bigPOST结果', ["message" => json_decode($r, true)]);
+
+        return [true, json_decode($r, true)];
+    }
+}

+ 2 - 1
routes/api.php

@@ -425,5 +425,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('douShopOrderList', 'Api\DouShopController@douShopOrderList');
     $route->any('douShopOrderDetail', 'Api\DouShopController@douShopOrderDetail');
     $route->any('insertDouOrder', 'Api\DouShopController@insertDouOrder');
-
+    //大黄蜂
+    $route->any('getChatDetail', 'Api\DaHuangFengController@getChatDetail');
 });