Created
May 5, 2019 21:36
-
-
Save Adoonq/b39ecacba10ffc625d3d31f9449f48c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $user=array( | |
| 'USER_LOGIN'=>'', | |
| 'USER_HASH'=>'' | |
| ); | |
| $subdomain=''; | |
| curl_amocrm($user, $subdomain, 'private/api/auth.php?type=json'); | |
| $leads['request']['leads']['add'] = array( | |
| array( | |
| 'name' => $form_subject, | |
| 'created_at' => time(), | |
| // 'status_id' => 20663914, | |
| 'tags' => 'superlestnica.in.ua', | |
| 'custom_fields' => array( | |
| array( | |
| 'id' => 572505, | |
| 'values' => array( | |
| array( | |
| 'value' => $form_data['Форма'] | |
| ) | |
| ) | |
| ), | |
| array( | |
| 'id' => 572507, | |
| 'values' => array( | |
| array( | |
| 'value' => $form_data['Вопрос'] | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ); | |
| $leads_out = json_decode(curl_amocrm($leads, $subdomain, 'private/api/v2/json/leads/set'), true); | |
| $lead_id = $leads_out['response']['leads']['add'][0]['id']; | |
| $contacts['request']['contacts']['add'] = array( | |
| array( | |
| 'name' => $form_data['Имя'], | |
| 'created_at' => time(), | |
| 'tags'=> 'superlestnica.in.ua', | |
| 'linked_leads_id' => $lead_id, | |
| 'custom_fields'=>array( | |
| array( | |
| 'id' => 344251, | |
| 'values' => array( | |
| array( | |
| 'value' => $form_data['Телефон'], | |
| 'enum'=>'MOB' | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ); | |
| $out = curl_amocrm($contacts, $subdomain, 'private/api/v2/json/contacts/set'); | |
| function curl_amocrm($post, $subdomain, $method) { | |
| $curl=curl_init(); | |
| curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); | |
| curl_setopt($curl,CURLOPT_USERAGENT,'amoCRM-API-client/1.0'); | |
| curl_setopt($curl,CURLOPT_URL,'https://'.$subdomain.'.amocrm.ru/'.$method); | |
| curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'POST'); | |
| curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($post)); | |
| curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json')); | |
| curl_setopt($curl,CURLOPT_HEADER,false); | |
| curl_setopt($curl,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__ | |
| curl_setopt($curl,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__ | |
| curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0); | |
| curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0); | |
| $out=curl_exec($curl); | |
| curl_close($curl); | |
| return $out; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment