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)]; } }