$postData]; $params['lead']['lead_source'] = 'form'; $leadData = makePostRequest('/v1/zcrm/leads', $params); if (isset($leadData['status'], $leadData['data'], $leadData['data']['id']) && $leadData['status'] === 'success' && (isset($postData['comment']) && !empty($postData['comment'])) ) { //Если клиент создан то оставим текстовую заметку в ленту $addFeedMethod = sprintf('/v1/zcrm/customers/%s/feed', $leadData['data']['id']); $messageData = ['content' => $postData['comment']]; makePostRequest($addFeedMethod, $messageData); } var_dump($leadData); } exit(); function makePostRequest($method, $params) { // userKey и secret заменить на свои из личного кабинета $userKey = '838255803f5db6115648'; $secret = 'd3b022a8ac9c9162d31c'; $apiUrl = 'https://api.zadarma.com'; ksort($params); $paramsStr = makeParamsStr($params); $sign = makeSign($paramsStr, $method, $secret); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $apiUrl . $method); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POSTFIELDS, $paramsStr); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Authorization: ' . $userKey . ':' . $sign ]); $response = curl_exec($curl); $error = curl_error($curl); curl_close($curl); if ($error) { return null; } else { return json_decode($response, true); } } /** * @param array $params * @return string */ function makeParamsStr($params) { return http_build_query($params, null, '&', PHP_QUERY_RFC1738); } /** * @param string $paramsStr * @param string $method * @param string $secret * * @return string */ function makeSign($paramsStr, $method, $secret) { return base64_encode( hash_hmac( 'sha1', $method . $paramsStr . md5($paramsStr), $secret ) ); }
Made on
Tilda