]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правки по api
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 26 Apr 2024 14:19:44 +0000 (17:19 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 26 Apr 2024 14:19:44 +0000 (17:19 +0300)
16 files changed:
erp24/api1/actions/cron/GetTokenAction.php [new file with mode: 0644]
erp24/api1/controllers/CronController.php
erp24/api1/views/cron/get-token.php [new file with mode: 0644]
erp24/inc/amo/callback.php [new file with mode: 0644]
erp24/inc/amo/get_token.php [new file with mode: 0644]
erp24/inc/amo/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json [changed mode: 0644->0755]
erp24/inc/amo2/1token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json [new file with mode: 0755]
erp24/inc/amo2/amo_inc.php [new file with mode: 0644]
erp24/inc/amo2/amo_inc_php5.php [new file with mode: 0644]
erp24/inc/amo2/amo_insert.php [new file with mode: 0644]
erp24/inc/amo2/callback.php [new file with mode: 0644]
erp24/inc/amo2/get_lead.php [new file with mode: 0644]
erp24/inc/amo2/get_token.php [new file with mode: 0644]
erp24/inc/amo2/logi_status_upper.txt [new file with mode: 0644]
erp24/inc/amo2/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json [new file with mode: 0755]
erp24/inc/amo2/up_link_amo.php [new file with mode: 0644]

diff --git a/erp24/api1/actions/cron/GetTokenAction.php b/erp24/api1/actions/cron/GetTokenAction.php
new file mode 100644 (file)
index 0000000..1ceb3e5
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace app\actions\cron;
+
+use yii\base\Action;
+
+class GetTokenAction extends Action
+{
+    public function run() {
+        return $this->controller->renderPartial('get-token');
+    }
+}
\ No newline at end of file
index a541038affb23e975171f042b941136f0270977f..daad9bba2ba6630b4ed11647dbf901a156c4de5d 100644 (file)
@@ -21,7 +21,7 @@ class CronController extends BaseController
             'cloudpayments-region' => \app\actions\cron\CloudpaymentsRegionAction::class,
             'bonus-users-sale-update' => \app\actions\cron\BonusUsersSaleUpdateAction::class,
 //            '1c-check-1day' => \app\actions\cron\OneCCheckOneDayAction::class,
-//            'get-token' => \app\actions\cron\GetTokenAction::class,
+            'get-token' => \app\actions\cron\GetTokenAction::class,
         ];
     }
 }
diff --git a/erp24/api1/views/cron/get-token.php b/erp24/api1/views/cron/get-token.php
new file mode 100644 (file)
index 0000000..5f9fd70
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+
+if ($_GET["token_cloud"]!="iC04295J9HyD2H3GJF3btky") {
+    var_dump($_GET);
+    echo ' test 11  ' . time();
+    exit('234');
+}
+
+/*
+https://amo.bazacvetov24.ru/amo/callback.php
+
+создание токена
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=authorization_code&value=def502004504af4431893923ea29e99c05632ff963a20318c8f0d0f1b0ca3a716bcd0d4e9d19f42e0a2a19d2e3fbe603d6591249640cd5432267c83d6cc217e29d6af587aa30bfeae0291b009a152943f896b6a05a3a07f6f679e083603476180d7307e4468393bdf0061bdbb1fc1775e2c4f07d8f76fad8ba863baadb8b55859456ada564114bb0759201ab595da001c321892e5b06e767ae4c5bb92e2c1464a7c2f84d019180fb3614c5dad5793d1d8f3616d4d27f5f9b8cc03cc703cfbbb6748a643425b607a490a4c476e262d607b88b07f413bc13dbbd160ef9798a2674d4c5ede4e012f950415c7200b8d7455e68ea459c2f617c338ae9138e70b37f2974c522bba02425d5599a31491aabc5e0d281be4472d57bf8768be8f80f73600a0a0b4f6cb2f041a82a752d7aacaca186577a66887cbba3656b0614886a581a161fd2832da7c03e9cb1ebff3485c2fb779b902d766c038b90173860befa9ddbc2833bd1681951421c46bb1f9fba30880b46a44c74f22b3956adc36a139ee3a5b73328d84decace284de2d5fdd6924fbf6cec37a74b6f736a5461dbb59c5463da538f40d5683bc558c276d920dc6274fb25a13b873fefb1dd8ff4d4a1465213fa04f083a40043b8572fef12d7c94609112202ccc210825819f4715ee08f24e437fb10a7249ecda70&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+обновление токена
+
+https://amo.bazacvetov24.ru/amo/callback.php
+
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=refresh_token&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+ */
+
+header('Content-Type: text/html; charset=utf-8');
+
+$time = time();
+
+define('SECRET_PHRASE', 'VJJVkt467ltuXU__356XEtS');
+
+define('SUBDOMAIN', 'bazacvetov24');
+
+define('APP_URL', 'https://amo.bazacvetov24.ru/amo/callback.php');
+
+define('CLIENT_ID', 'a6156015-990f-4bbc-8fd1-309d51347407');
+
+define('CLIENT_SECRET', 'Z0mo0XadAR44kCEAOw5XvECLA8QbFYeLyHnCM81b9bKC96LjzTDd80cItLZ2wzmO');
+
+define('SECRET_FILE', 'token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
+
+if (SECRET_PHRASE != $_GET['secret_phrase']) {
+    exit('Incorrect secret phrase');
+}
+
+chmod(SECRET_FILE, 0740);
+
+if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'refresh_token') {
+
+    $grant_type = 'refresh_token';
+
+    $method = 'refresh_token';
+
+    $values = json_decode(file_get_contents(SECRET_FILE), true);
+
+    $value = $values['refresh_token'];
+
+} else if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'authorization_code') {
+
+    $grant_type = 'authorization_code';
+
+    $method = 'code';
+
+    $value = $_GET['value'];
+
+} else {
+
+    exit("Incorrect params!");
+
+}
+
+$link = 'https://' . SUBDOMAIN . '.amocrm.ru/oauth2/access_token';
+
+$data = [
+
+    'client_id' => CLIENT_ID,
+
+    'client_secret' => CLIENT_SECRET,
+
+    'grant_type' => $grant_type,
+
+    $method => $value,
+
+    'redirect_uri' => APP_URL,
+
+];
+
+$json = json_encode($data, JSON_UNESCAPED_SLASHES);
+
+$curl = curl_init();
+
+curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client/1.0');
+curl_setopt($curl, CURLOPT_URL, $link);
+curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
+curl_setopt($curl, CURLOPT_HEADER, false);
+curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
+curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
+curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
+curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+$out = curl_exec($curl);
+$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+echo $httpcode;
+curl_close($curl);
+
+$arr_token = json_decode($out, true);
+
+$arr_token['expires'] = time() + $arr_token['expires_in'];
+
+$response = json_encode($arr_token, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
+
+var_dump(file_put_contents(SECRET_FILE, $response));
+
+
+
+
+
diff --git a/erp24/inc/amo/callback.php b/erp24/inc/amo/callback.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/erp24/inc/amo/get_token.php b/erp24/inc/amo/get_token.php
new file mode 100644 (file)
index 0000000..cc2e24e
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+/*
+https://amo.bazacvetov24.ru/amo/callback.php
+
+создание токена
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=authorization_code&value=def502004504af4431893923ea29e99c05632ff963a20318c8f0d0f1b0ca3a716bcd0d4e9d19f42e0a2a19d2e3fbe603d6591249640cd5432267c83d6cc217e29d6af587aa30bfeae0291b009a152943f896b6a05a3a07f6f679e083603476180d7307e4468393bdf0061bdbb1fc1775e2c4f07d8f76fad8ba863baadb8b55859456ada564114bb0759201ab595da001c321892e5b06e767ae4c5bb92e2c1464a7c2f84d019180fb3614c5dad5793d1d8f3616d4d27f5f9b8cc03cc703cfbbb6748a643425b607a490a4c476e262d607b88b07f413bc13dbbd160ef9798a2674d4c5ede4e012f950415c7200b8d7455e68ea459c2f617c338ae9138e70b37f2974c522bba02425d5599a31491aabc5e0d281be4472d57bf8768be8f80f73600a0a0b4f6cb2f041a82a752d7aacaca186577a66887cbba3656b0614886a581a161fd2832da7c03e9cb1ebff3485c2fb779b902d766c038b90173860befa9ddbc2833bd1681951421c46bb1f9fba30880b46a44c74f22b3956adc36a139ee3a5b73328d84decace284de2d5fdd6924fbf6cec37a74b6f736a5461dbb59c5463da538f40d5683bc558c276d920dc6274fb25a13b873fefb1dd8ff4d4a1465213fa04f083a40043b8572fef12d7c94609112202ccc210825819f4715ee08f24e437fb10a7249ecda70&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+обновление токена
+
+https://amo.bazacvetov24.ru/amo/callback.php
+
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=refresh_token&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+ */
+
+header('Content-Type: text/html; charset=utf-8');
+
+$time = time();
+
+define('SECRET_PHRASE', 'VJJVkt467ltuXU__356XEtS');
+
+define('SUBDOMAIN', 'bazacvetov24');
+
+define('APP_URL', 'https://amo.bazacvetov24.ru/amo/callback.php');
+
+define('CLIENT_ID', 'a6156015-990f-4bbc-8fd1-309d51347407');
+
+define('CLIENT_SECRET', 'Z0mo0XadAR44kCEAOw5XvECLA8QbFYeLyHnCM81b9bKC96LjzTDd80cItLZ2wzmO');
+
+define('SECRET_FILE', 'token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
+
+if (SECRET_PHRASE != $_GET['secret_phrase']) {
+       exit('Incorrect secret phrase');
+}
+
+chmod(SECRET_FILE, 0740);
+
+if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'refresh_token') {
+
+       $grant_type = 'refresh_token';
+
+       $method = 'refresh_token';
+
+       $values = json_decode(file_get_contents(SECRET_FILE), true);
+
+       $value = $values['refresh_token'];
+
+} else if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'authorization_code') {
+
+       $grant_type = 'authorization_code';
+
+       $method = 'code';
+
+       $value = $_GET['value'];
+
+} else {
+
+       exit("Incorrect params!");
+
+}
+
+$link = 'https://' . SUBDOMAIN . '.amocrm.ru/oauth2/access_token';
+
+$data = [
+
+       'client_id' => CLIENT_ID,
+
+       'client_secret' => CLIENT_SECRET,
+
+       'grant_type' => $grant_type,
+
+       $method => $value,
+
+       'redirect_uri' => APP_URL,
+
+];
+
+$json = json_encode($data, JSON_UNESCAPED_SLASHES);
+
+$curl = curl_init();
+
+curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client/1.0');
+curl_setopt($curl, CURLOPT_URL, $link);
+curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
+curl_setopt($curl, CURLOPT_HEADER, false);
+curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
+curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
+curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
+curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+$out = curl_exec($curl);
+$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+echo $httpcode;
+curl_close($curl);
+
+$arr_token = json_decode($out, true);
+
+$arr_token['expires'] = time() + $arr_token['expires_in'];
+
+$response = json_encode($arr_token, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
+
+var_dump(file_put_contents(SECRET_FILE, $response));
\ No newline at end of file
diff --git a/erp24/inc/amo2/1token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json b/erp24/inc/amo2/1token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json
new file mode 100755 (executable)
index 0000000..aa8773a
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "token_type": "Bearer",
+    "expires_in": 86400,
+    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImNmMzgxNTNjMjE0NTQxNmFiZjc2ZjQ4YmI5YjVlYTRiOGJiNWU2OTllODk1OGEzOGI0M2ZjOTkxNjljZGQ3YzhkMGE0MjA4YzRmNzhiNWNlIn0.eyJhdWQiOiJhNjE1NjAxNS05OTBmLTRiYmMtOGZkMS0zMDlkNTEzNDc0MDciLCJqdGkiOiJjZjM4MTUzYzIxNDU0MTZhYmY3NmY0OGJiOWI1ZWE0YjhiYjVlNjk5ZTg5NThhMzhiNDNmYzk5MTY5Y2RkN2M4ZDBhNDIwOGM0Zjc4YjVjZSIsImlhdCI6MTY5NzQwMDkwMywibmJmIjoxNjk3NDAwOTAzLCJleHAiOjE2OTc0ODczMDMsInN1YiI6IjM0NTA3OTMiLCJncmFudF90eXBlIjoiIiwiYWNjb3VudF9pZCI6MjcxMjc5NzgsImJhc2VfZG9tYWluIjoiYW1vY3JtLnJ1IiwidmVyc2lvbiI6MSwic2NvcGVzIjpbInB1c2hfbm90aWZpY2F0aW9ucyIsImNybSIsIm5vdGlmaWNhdGlvbnMiXX0.K1csEGAVdfarWLqs-GPA3ps3HQNkWX7TD9hqOiN-nwmu2NRxnttvKaOr7IJMYyu6Ir60dBh3n66VlrF1Vgep0ZYNY1UB9QhrYdJsJBL50M8zqj2SBIWY-DzVMwF0Mu7N3Ejdmf5Pj-UgCX-5odWYEgpHGvDIGyZoWjh4TgTOsjtIha9qSYOV4yh-4KIP378MpuooxZqLrhbc0Tgfrr0_H90EYQeVE9kC33Qs_jLok_1m9MGTJoxNuPOaP_lRMlKYfyvggFwXzpbn6JWzwU79kQ7w6lHKtHuALuSxuxwVJtZtW-T72uUpxQpZREIQvL6wKRQk5rbzPZEZIneD3MYGCA",
+    "refresh_token": "def50200d386d4dc0104b119410b04f82a50c9eeb914d237faf3777d8c43342f78b19488dc4d0666ff6cb99e40957c489ac3eae2728cc81387fb1cc1e54587b79652bd7d8afa291672bbdb29272ac39a11aa84c3c75b95c13ee24ba659ece487078f286e6788bd560f54fdbd27f56b7887ec31e08383b4965518664d05a7487fad2ff26baf817e19c2810eb5f41a957ceb67a014c696b68b8dcfa0e43cc442cd0bb3aa966b73ea84b53ecb671537a71dd5128794e2e275a4b94896f4087c59a3fab39af1c6dbaf43eeaba772be21bd0bb8bfb5e75adfd9c6c5b51a0b66da0a60fe4ca4a4870d42c62bfc1f6e7cb67640dbcdfb39c40e44cb89bbbd70a418f75f01c8b6166ae0d45912226b74fc8c3cc15182ed946b0dba5c78fe2f3292b076119a14c4e6ace3e0247b0e213fdd4f018c9771e7f1fb42546c2e267d5b035805b5f6bb90b6d01c44bcd84b85bdc4ca940644fb52c3fb639240587c5d9fed3842d5e9692e3c2b055173bbd91c5aedb7039831e0ebbd1db76a939caf390a889e47e95954cb965337c3ff0c5039051d1a7e5c19655b7bfcc89d27ea555117f02a0386fcf194bd9b9c25344bb46a5b194106281e15c641a1aa7751834d0c07777b5cb19187c71bc242d872e83409a76395f1855d53e9264587",
+    "expires": 1697487303
+}
\ No newline at end of file
diff --git a/erp24/inc/amo2/amo_inc.php b/erp24/inc/amo2/amo_inc.php
new file mode 100644 (file)
index 0000000..9334a29
--- /dev/null
@@ -0,0 +1,48 @@
+<?
+header('Access-Control-Allow-Origin: *');
+define('SECRET_FILE', '/var/www/www-root/data/www/amo.bazacvetov24.ru/amo/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
+define('SUBDOMAIN', 'bazacvetov24');
+$arr_token = json_decode(file_get_contents(SECRET_FILE), true);
+$ACCESS_TOKEN = $arr_token['access_token'];
+function amo_rest($access_token, $end_point, $method = 'GET', $params) {
+
+       $root_link = 'https://' . SUBDOMAIN . '.amocrm.ru';
+
+       $headers = [
+
+               'Authorization: Bearer ' . $access_token,
+
+               'Content-Type: application/json',
+
+       ];
+
+       $curl = curl_init();
+
+       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+
+       curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client/1.0');
+
+       curl_setopt($curl, CURLOPT_URL, $root_link . $end_point);
+
+       curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+
+       curl_setopt($curl, CURLOPT_HEADER, false);
+
+       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
+
+       curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+
+       if ($method != 'GET') {
+
+               curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+
+               curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
+
+       }
+
+       $response = curl_exec($curl);
+
+       curl_close($curl);
+
+       return json_decode($response, true);
+}
\ No newline at end of file
diff --git a/erp24/inc/amo2/amo_inc_php5.php b/erp24/inc/amo2/amo_inc_php5.php
new file mode 100644 (file)
index 0000000..271986f
--- /dev/null
@@ -0,0 +1,48 @@
+<?
+header('Access-Control-Allow-Origin: *');
+define('SECRET_FILE', '/var/www/www-root/data/www/amo.bazacvetov24.ru/amo/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
+define('SUBDOMAIN', 'bazacvetov24');
+$arr_token = json_decode(file_get_contents(SECRET_FILE), true);
+$ACCESS_TOKEN = $arr_token['access_token'];
+function amo_rest($access_token, $end_point, $method = 'GET', $params) {
+
+       $root_link = 'https://' . SUBDOMAIN . '.amocrm.ru';
+
+       $headers = array(
+
+               'Authorization: Bearer ' . $access_token,
+
+               'Content-Type: application/json',
+
+       );
+
+       $curl = curl_init();
+
+       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+
+       curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client/1.0');
+
+       curl_setopt($curl, CURLOPT_URL, $root_link . $end_point);
+
+       curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+
+       curl_setopt($curl, CURLOPT_HEADER, false);
+
+       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
+
+       curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+
+       if ($method != 'GET') {
+
+               curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+
+               curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
+
+       }
+
+       $response = curl_exec($curl);
+
+       curl_close($curl);
+
+       return json_decode($response, true);
+}
\ No newline at end of file
diff --git a/erp24/inc/amo2/amo_insert.php b/erp24/inc/amo2/amo_insert.php
new file mode 100644 (file)
index 0000000..d61c79a
--- /dev/null
@@ -0,0 +1,246 @@
+<?
+//include_once"/var/www/mebel-online/data/www/bazacvetov24.ru/inc/db.php";
+//if($_REQUEST["p"]!="CJVKLT00eytudeDFBr6") exit();
+//if(!empty($_REQUEST["amo_id"])) $amo_id=(int)$_REQUEST["amo_id"];    
+// https://amo.bazacvetov24.biocrm.ru/amo_sync_crm.php?p=CJVKLT00eytudeDFBr6&amo_id=24645767
+
+
+if(!empty($amo_id)) {
+
+   
+    
+if(empty($ACCESS_TOKEN)) include_once"/var/www/www-root/data/www/amo.bazacvetov24.ru/amo/amo_inc.php";
+//header('Content-Type: text/html; charset=utf-8');
+
+
+$deal = amo_rest($ACCESS_TOKEN, '/api/v4/leads/'.$amo_id.'?with=contacts','GET', []);
+$id_contact = $deal['_embedded']['contacts'][0]['id'];
+$custom_fields = $deal['custom_fields_values'];
+
+$i=1;
+foreach($deal['_embedded']["tags"] as $ud => $tag) { 
+ if($i<count($deal['_embedded']["tags"])) $z=","; else $z="";  
+    $tags.="".$tag["name"]."$z";
+    $tags_arr .="".$tag["id"]."$z";
+ $i++;   
+    }
+
+$users[6247372]="Менеджер 1";
+$users[6807019]="Менеджер 2";
+$users[6807028]="РОП";
+$users[5992531]="Логист";
+$users[3450793]="Тех директор";
+$users[5992531]="Опреатор";
+$row=array();
+$row["amo_id"]=$amo_id;
+$row["price"]=$deal['price'];
+$row["responsible_user_id"]=$deal['responsible_user_id'];
+
+
+$row["created_at"]=date("Y-m-d H:i:s",$deal['created_at']);
+$row["updated_at"]=date("Y-m-d H:i:s",$deal['updated_at']);
+$row["closed_at"]=date("Y-m-d H:i:s",$deal['closed_at']);
+$row["pipeline_id"]=$deal['pipeline_id'];
+if(empty($status_id)) $row["status_id"]=$deal['status_id'];
+else $row["status_id"]=$status_id;
+$row["tags"]=$tags;
+$row["tags_arr"]=$tags_arr;
+$row["name"]=$deal['name'];;
+$row["responsible_user"]=$users[$row["responsible_user_id"]];
+
+$massiv=[
+655357=>"id",
+647945=>"pol_name",
+657129=>"text_card",
+647947=>"pol_phone",
+774807=>"delivery_time",
+//647937=>"delivery_time_old",
+647935 =>"delivery_date",
+774805 =>"delivery_time_extend",
+676231=>"delivery_oblast",
+647949=>"delivery_adress",
+676229=>"delivery_rayon",
+647931=>"pay",
+651887=>"payment_type_id",
+647927=>"delivery",
+647929=>"store_id",
+647929=>"store",
+647955=>"comment",
+661535=>"order_text",
+659607=>"toper",
+658099 =>"shariki",
+768387 =>"povod",
+647953 =>"istochnik",
+775235 =>"courier_id",
+775237 =>"courier",
+775239 =>"courier_zabor",
+775241 =>"courier_dostavil",
+775245 =>"florist_id",
+775247 =>"florist",
+775491 =>"florist_peredano",
+775289 =>"florist_zabor",
+775343 =>"florist_foto",
+775539 =>"dostavka_comment",
+775507 =>"price_dostavka",
+775495 =>"price_dostavka_zatrat",
+775513 =>"dostavka_povtor_tip",
+775505 =>"price_dostavka_povtor_zatrat",
+775509 =>"price_dostavka_povtor",
+658125 =>"otkaz_id",
+663239 =>"otkaz_text",
+775001 =>"otkaz_manager",
+775287 =>"otkaz_id_rop",
+775355 =>"client_comment_foto",
+775499 =>"client_adress_zamena",
+775501 =>"client_adress_zamena_cnt",
+775351 =>"client_ip",
+775357 =>"client_pravki_cnt",
+775349 =>"client_foro_prosmotr",
+774987 =>"uber_time",
+775545 =>"manager_time",
+775287 =>"otkaz_id_rop",
+776319 =>"manager_id",
+776321 =>"manager",
+776329 =>"phone_client",
+775955 =>"courier_gps",
+776259 =>"manager_courier_time",
+775365 =>"florist_sborka_night",
+//786559 =>"brend",
+
+
+
+775083 =>"key_code",
+];
+
+
+/*if($ma["id"]==786559) $brend=trim($valuecustom); 
+if($ma["id"]==655357) $lid_id=$valuecustom; 
+$json_new["custom_".$ma["id"].""]=array("name"=>$ma["name"], "value"=>$valuecustom);
+}
+
+$custom_brend='';
+if($brend=='') $brend='БазаЦветов24.ру';
+//$brend='Регион';$brend='ДомРоз24.ру';$brend='24-База-Цветов.ру';
+
+$custom_brend = ', {"field_id": 786559, "values": [ {"value":"'.$brend.'"}]}';*/
+
+
+
+$formapole=[
+"delivery_date"=>"date",     
+"florist_peredano"=>"datetime",    
+"florist_zabor"=>"datetime",  
+"florist_foto"=>"datetime",  
+"courier_zabor"=>"datetime",  
+"courier_dostavil"=>"datetime",  
+"manager_courier_time"=>"datetime",  
+
+
+];
+
+if (!function_exists('func_format')) {
+function func_format($tip="datetime",$pole) {
+    
+if($tip=="datetime") $pole=date("Y-m-d H:i:s",$pole);   
+if($tip=="date") $pole=date("Y-m-d",$pole);   
+return $pole;
+
+}
+}
+
+
+foreach($custom_fields as $if => $ma) {
+if(!empty($massiv[$ma["field_id"]])) {
+    if(!empty($formapole[$massiv[$ma["field_id"]]])) $ma["values"][0]["value"]=func_format($formapole[$massiv[$ma["field_id"]]],$ma["values"][0]["value"]);  
+    
+    $row[$massiv[$ma["field_id"]]]=$ma["values"][0]["value"];     
+    }
+}
+
+//if($row["delivery_time"]==$row["delivery_time_old"]) $row["delivery_time_old"]="";
+if($row["delivery_time_extend"]==$row["delivery_time"]) $row["delivery_time_extend"]="";
+if($row["delivery_time_extend"]==$row["delivery_time_old"]) $row["delivery_time_extend"]="";
+
+//foreach($row as $k => $v) echo"<br>$k => $v";
+//print'<pre>';print_r($deal);echo'</pre>';
+
+$contact = amo_rest($ACCESS_TOKEN, '/api/v4/contacts/' . $id_contact, $method = 'GET', []);
+//$arr = ['lead' => $deal,     'contact' => $contact];
+$phone=$contact["custom_fields_values"]["0"]["values"]["0"]["value"];
+$email=$contact["custom_fields_values"]["1"]["values"]["0"]["value"];
+$name=$contact["name"];
+$row["client"]=$name;
+$row["phone"]=$phone;
+$row["email"]=$email;
+$row["amo_sync_time"]=date("Y-m-d H:i:s",time());
+if(empty($row["phone"])) $row["phone"]=$row["phone_client"];
+//echo "id= ".$contact["id"]." $name phone =$phone $email";
+//print_r($contact);
+$i=0;
+$sql1 =""; $sql2 ="";
+foreach($row as $n => $value) {
+
+$value=str_replace("'","",$value);      
+     if($i>0) { $sql1 .=","; $sql2 .=","; }
+$sql1 .=" $n ";
+$sql2 .="'$value'";
+
+//echo" <br> $n => $value ";    
+ $i++;   
+}
+
+
+if(!empty($row["amo_id"])) {
+
+
+$db::sql("DELETE FROM orders_amo WHERE amo_id=? AND status_id!='142' AND status_id!='143'",[$row["amo_id"]]);
+//echo"<br>DELETE FROM orders_amo WHERE amo_id=? AND status_id!='142' AND status_id!='143'";
+$data_cnt=$db::getRows("SELECT amo_id FROM orders_amo  WHERE amo_id=? AND status_id='142'",[$row["amo_id"]]);
+
+if($update_amo==1 and count($data_cnt)>0) {
+    
+echo"НЕ удаляем тарую информацию";    
+}  //else 
+
+if(count($data_cnt)>0) {
+
+}
+
+
+
+
+if(count($data_cnt)==0) {
+    
+//$db::sql("DELETE FROM orders_amo WHERE id=?",[$row["id"]]);    
+    
+if(empty($row["id"])) {    
+$s="INSERT INTO  orders_amo (id, $sql1) VALUES ('".time()."', $sql2);"; 
+}
+else {    
+$s="INSERT INTO  orders_amo ($sql1) VALUES ($sql2);"; 
+}
+echo $s;
+sleep(1);
+$db::sql($s);
+
+}
+
+/*
+$data=$db::getRows("SELECT id, adress_amo FROM city_store  WHERE 1");
+foreach ($data as $row2) {
+  if(!empty($row2["id"])) $db::sql("UPDATE  orders_amo SET store_id='".$row2["id"]."' WHERE store='".$row2["adress_amo"]."' AND store_id=''");
+}  
+*/
+
+//file_put_contents('sunc_142.txt', ''.$s.'   ', FILE_APPEND);
+}
+
+
+}    
+    
+?>
diff --git a/erp24/inc/amo2/callback.php b/erp24/inc/amo2/callback.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/erp24/inc/amo2/get_lead.php b/erp24/inc/amo2/get_lead.php
new file mode 100644 (file)
index 0000000..53730a0
--- /dev/null
@@ -0,0 +1,92 @@
+<?
+include"amo_inc.php";
+include"/var/www/www-root/data/www/bazacvetov24.ru/inc/db.php";
+header('Content-Type: text/html; charset=utf-8');
+$deal_id = 25742061;
+if(!empty($_GET["amo_id"])) $deal_id=(int)$_GET["amo_id"];
+
+$n=4;
+$date1=time()-86400*$n;
+$date2=time()-86400*($n-1);
+
+
+$date1=mktime(0,0,0,3,4,2022);
+$date2=mktime(0,0,0,3,4,2022);
+
+//updated_at
+$dt="created_at";
+//$dt="updated_at";
+$deal0 = amo_rest($ACCESS_TOKEN, '/api/v4/leads?order[updated_at]=desc&limit=250&filter[statuses][0][pipeline_id]=4021495&filter[statuses][0][status_id]=142&filter['.$dt.'][from]='.$date1.'&filter['.$dt.'][to]='.$date2.'', 'GET', []);
+echo print_r($deal);
+
+foreach($deal0["_embedded"]["leads"] as $lid_id => $arr0) {
+    
+if($arr0["status_id"]==142) { echo"<hr><br>  ".date("d.m.Y в H:i",$arr0["updated_at"])."   ".$arr0["id"]."  ".$arr0["name"]."  ".$arr0["price"]."   ".$arr0["status_id"]."  ";    
+$lid_id=0; // or $arr0["status_id"]==143
+foreach($arr["custom_fields_values"] as $fid => $arr20) {
+  //  echo"<br> ".$arr2["field_id"]." ".$arr2["field_name"]."  ".$arr2["field_name"]." = ".$arr2["values"][0]["value"]." ";  
+ if($arr20["field_id"]==655357) $lid_id=$arr20["values"][0]["value"];
+}
+
+$idn=$db::getValue("SELECT id FROM orders_amo WHERE amo_id='".$arr0["id"]."' AND status_id='142'");
+
+if(empty($idn))  { 
+echo"<font color=red>Заказа ".$arr0["id"]." нет в базе $idn</font>";
+$update_amo=1;
+$_REQUEST["p"]="CJVKLT00eytudeDFBr6"; 
+$amo_id=$arr0["id"];
+include"/var/www/www-root/data/www/amo.bazacvetov24.biocrm.ru/amo/amo_insert.php";
+}
+
+
+
+
+
+
+} else {
+    
+echo"<hr><br>  ".date("d.m.Y в H:i",$arr0["updated_at"])."   ".$arr0["id"]."  ".$arr0["name"]."  ".$arr0["price"]."   ".$arr0["status_id"]."  ";    
+    
+    
+}
+//    
+    
+    
+}
+
+exit();
+
+$deal = amo_rest($ACCESS_TOKEN, '/api/v4/leads/' . $deal_id . '', $method = 'GET', []);
+echo json_encode($deal);;
+
+$input2=json_encode($deal);
+
+
+exit();
+$id_contact = $deal['_embedded']['contacts'][0]['id'];
+
+
+
+print'<pre>';
+print_r($deal);
+echo'</pre>';
+
+exit();
+
+$contact = amo_rest($ACCESS_TOKEN, '/api/v4/contacts/' . $id_contact, $method = 'GET', []);
+$arr = ['lead' => $deal,       'contact' => $contact];
+
+
+
+$phone=$contact["custom_fields_values"]["0"]["values"]["0"]["value"];
+$name=$contact["name"];
+$first_name=$contact["first_name"];
+$last_name=$contact["last_name"];
+//$name="$name $first_name $last_name";
+echo "id= ".$contact["id"]." $name phone =$phone ";
+
+
+print'<pre>';
+print_r($arr);
+echo'</pre>';
+
diff --git a/erp24/inc/amo2/get_token.php b/erp24/inc/amo2/get_token.php
new file mode 100644 (file)
index 0000000..cc2e24e
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+
+/*
+https://amo.bazacvetov24.ru/amo/callback.php
+
+создание токена
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=authorization_code&value=def502004504af4431893923ea29e99c05632ff963a20318c8f0d0f1b0ca3a716bcd0d4e9d19f42e0a2a19d2e3fbe603d6591249640cd5432267c83d6cc217e29d6af587aa30bfeae0291b009a152943f896b6a05a3a07f6f679e083603476180d7307e4468393bdf0061bdbb1fc1775e2c4f07d8f76fad8ba863baadb8b55859456ada564114bb0759201ab595da001c321892e5b06e767ae4c5bb92e2c1464a7c2f84d019180fb3614c5dad5793d1d8f3616d4d27f5f9b8cc03cc703cfbbb6748a643425b607a490a4c476e262d607b88b07f413bc13dbbd160ef9798a2674d4c5ede4e012f950415c7200b8d7455e68ea459c2f617c338ae9138e70b37f2974c522bba02425d5599a31491aabc5e0d281be4472d57bf8768be8f80f73600a0a0b4f6cb2f041a82a752d7aacaca186577a66887cbba3656b0614886a581a161fd2832da7c03e9cb1ebff3485c2fb779b902d766c038b90173860befa9ddbc2833bd1681951421c46bb1f9fba30880b46a44c74f22b3956adc36a139ee3a5b73328d84decace284de2d5fdd6924fbf6cec37a74b6f736a5461dbb59c5463da538f40d5683bc558c276d920dc6274fb25a13b873fefb1dd8ff4d4a1465213fa04f083a40043b8572fef12d7c94609112202ccc210825819f4715ee08f24e437fb10a7249ecda70&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+обновление токена
+
+https://amo.bazacvetov24.ru/amo/callback.php
+
+https://amo.bazacvetov24.ru/amo/get_token.php?grant_type=refresh_token&secret_phrase=VJJVkt467ltuXU__356XEtS
+
+ */
+
+header('Content-Type: text/html; charset=utf-8');
+
+$time = time();
+
+define('SECRET_PHRASE', 'VJJVkt467ltuXU__356XEtS');
+
+define('SUBDOMAIN', 'bazacvetov24');
+
+define('APP_URL', 'https://amo.bazacvetov24.ru/amo/callback.php');
+
+define('CLIENT_ID', 'a6156015-990f-4bbc-8fd1-309d51347407');
+
+define('CLIENT_SECRET', 'Z0mo0XadAR44kCEAOw5XvECLA8QbFYeLyHnCM81b9bKC96LjzTDd80cItLZ2wzmO');
+
+define('SECRET_FILE', 'token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
+
+if (SECRET_PHRASE != $_GET['secret_phrase']) {
+       exit('Incorrect secret phrase');
+}
+
+chmod(SECRET_FILE, 0740);
+
+if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'refresh_token') {
+
+       $grant_type = 'refresh_token';
+
+       $method = 'refresh_token';
+
+       $values = json_decode(file_get_contents(SECRET_FILE), true);
+
+       $value = $values['refresh_token'];
+
+} else if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'authorization_code') {
+
+       $grant_type = 'authorization_code';
+
+       $method = 'code';
+
+       $value = $_GET['value'];
+
+} else {
+
+       exit("Incorrect params!");
+
+}
+
+$link = 'https://' . SUBDOMAIN . '.amocrm.ru/oauth2/access_token';
+
+$data = [
+
+       'client_id' => CLIENT_ID,
+
+       'client_secret' => CLIENT_SECRET,
+
+       'grant_type' => $grant_type,
+
+       $method => $value,
+
+       'redirect_uri' => APP_URL,
+
+];
+
+$json = json_encode($data, JSON_UNESCAPED_SLASHES);
+
+$curl = curl_init();
+
+curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+curl_setopt($curl, CURLOPT_USERAGENT, 'amoCRM-oAuth-client/1.0');
+curl_setopt($curl, CURLOPT_URL, $link);
+curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
+curl_setopt($curl, CURLOPT_HEADER, false);
+curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
+curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
+curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
+curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
+$out = curl_exec($curl);
+$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+echo $httpcode;
+curl_close($curl);
+
+$arr_token = json_decode($out, true);
+
+$arr_token['expires'] = time() + $arr_token['expires_in'];
+
+$response = json_encode($arr_token, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
+
+var_dump(file_put_contents(SECRET_FILE, $response));
\ No newline at end of file
diff --git a/erp24/inc/amo2/logi_status_upper.txt b/erp24/inc/amo2/logi_status_upper.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/erp24/inc/amo2/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json b/erp24/inc/amo2/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json
new file mode 100755 (executable)
index 0000000..b2fcecc
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "token_type": "Bearer",
+    "expires_in": 86400,
+    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjRhMmYxY2E1MjAxNzMxN2U0OGUwZDRkMWFiNzg5YjRmNjg4N2RkMjY2NDRiODcxZGE1MmU1ZmU4MGZiZTY1MmJlNGE4NzE3MDIyMWQ3NjRiIn0.eyJhdWQiOiJhNjE1NjAxNS05OTBmLTRiYmMtOGZkMS0zMDlkNTEzNDc0MDciLCJqdGkiOiI0YTJmMWNhNTIwMTczMTdlNDhlMGQ0ZDFhYjc4OWI0ZjY4ODdkZDI2NjQ0Yjg3MWRhNTJlNWZlODBmYmU2NTJiZTRhODcxNzAyMjFkNzY0YiIsImlhdCI6MTcxNDA3NzY2OCwibmJmIjoxNzE0MDc3NjY4LCJleHAiOjE3MTQxNjQwNjgsInN1YiI6IjM0NTA3OTMiLCJncmFudF90eXBlIjoiIiwiYWNjb3VudF9pZCI6MjcxMjc5NzgsImJhc2VfZG9tYWluIjoiYW1vY3JtLnJ1IiwidmVyc2lvbiI6Miwic2NvcGVzIjpbInB1c2hfbm90aWZpY2F0aW9ucyIsImNybSIsIm5vdGlmaWNhdGlvbnMiXSwiaGFzaF91dWlkIjoiNzFhNGFkZmMtY2JlNS00YjM0LTlkNDYtMjNjYmMxMGNhZjEyIn0.Hv5mMeXSrED20GQLiio95kwfPfW3eHT0iYggya6oDVV9KZpHhCIoDmLCcqVho805rr7U4O_b1wgGdriUqWEvQQQBHAibTVqc8EISt3s0xd9jk58Ea5Je0o0QJspnxcOUlq_jquOA2vZgFeA0S1knXlOf6jnChkGbvNhOmiAoJ1xqPjlRD2yURhRU2P6AnD8O7ynUTfx5QAeW0XmzG88p-2NgS4rn4rwuiAlZKHZbJHY5AVgiNMCWnnt3LHrmtFo2iZiyowlwbvgXg24rFVbBQphp9IhIoRz92s8c7hFB-i7F4EEWZzHrM0Ibe4hpDZ2n3vOQirMdqF4qWzsH9gvesg",
+    "refresh_token": "def50200187c5926011ec7973e41ffc4c66f43b7dbbb40a9be2065821f00eceb8a8b03a5a6ea1370595878b0a45938b20d2884d89221ce8861ddc67e93be1bd9387d58d25608489ab6cb05716955590cb05585c9a7bc1ced26ba51d2ce44e43df9b09dc8fccc4496307713b54d9ce839caa141cc514a1c27373e0901b8a1190fd9038863fb37d03d84fda83ce6632171c26e6467d8ca0034f32e4cac6cf7e37fe911b58d622f9b22031292a818fc7e1121d032fe681b386012eebd4441dd45908d2c54aae3a5a7ebf3f1a3ddaf0fc390e2a0aacbefbac0efc7f3a7bca762c42dd262fe085991ff8828082d1c06b9cfdd6e967f1a3353233ccdb9f301ce9749c77999d4f396b569a42203180da867bdf975ebfd982e93a8b0c0e39eceabb64d20b2246f24c1a2d0acd0fee0fb09ebfaa1d87e3bd46836784023a750c5a35e41252bd09ff1fd394c96b151edca7031b44691f03686d32e22162443049b0ddca289a3ba6da062d69122dc945e0772f71b1893ec6ecb4947acc99dbbbd5490a8680bc5110ae31afb7042b9b57c71c40d78238bbccaa4817d3fae329e0a15e35f86efeaafe774501bd7d0527e0f09c55d7607225fff4b1bddffbbe00f1006519137c43ef603a8cf0d3c6656884a4d6f7a2352c74bd7f1da8e",
+    "expires": 1714164069
+}
\ No newline at end of file
diff --git a/erp24/inc/amo2/up_link_amo.php b/erp24/inc/amo2/up_link_amo.php
new file mode 100644 (file)
index 0000000..bfd29e3
--- /dev/null
@@ -0,0 +1,72 @@
+<?
+include_once"/var/www/www-root/data/www/bazacvetov24.ru/inc/db.php";
+function gpass2($number)
+{
+  $chars="qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
+  $size=StrLen($chars)-1;
+  $password="";
+  while($number--)
+  $password.=$chars[rand(0,$size)];
+  return $password;
+}
+
+
+
+
+if(!empty($order_id)) $lid_id= $db::getValue("SELECT amo_link FROM site_orders  WHERE id=? order by id desc LIMIT 1",[$order_id]);
+
+if(!empty($lid_id)) {
+include"/var/www/www-root/data/www/amo.bazacvetov24.ru/amo/amo_inc.php";
+header('Content-Type: text/html; charset=utf-8');
+
+
+$order_id= $db::getRow("SELECT id,keygen FROM site_orders  WHERE amo_link=? order by id desc LIMIT 1",[$lid_id]);
+$order_id=$row["id"];
+$keygen=$row["keygen"];
+
+if(empty($keygen)) {$keygen=gpass2(12);
+$db::sql("UPDATE site_orders SET keygen=? WHERE amo_link=?",[$keygen,$lid_id]);}
+
+$patch='[
+    {
+        "id": '.$lid_id.',
+        "custom_fields_values": [
+         {
+        "field_id": 775089,
+        "values": [
+            {
+                "value": "https://amo.bazacvetov24.ru/amo_doc.php?p=CFtyyrtDFBr6&lid_id='.$lid_id.'&order_id='.$order_id.'&keygen='.$keygen.'"
+            }
+        ] 
+    },
+
+         {
+        "field_id": 775101,
+        "values": [
+            {
+                "value": "https://amo.bazacvetov24.ru/sostav.php?p=J4CK22UEF4rFGBr6&amo_id='.$lid_id.'&lid_id='.$order_id.'&keygen='.$keygen.'"
+            }
+        ] 
+    },   
+      {
+        "field_id": 775083,
+        "values": [
+            {
+                "value": "'.$keygen.'"
+            }
+        ]
+    }    
+    
+   ]
+ }]';
+$gh=amo_rest($ACCESS_TOKEN, '/api/v4/leads', $method = 'PATCH', $patch);
+//print'<pre>';print_r($gh);echo'</pre>';
+
+file_put_contents('logi_status_upper.txt', '
+'.$lid_id.' ='.$keygen.'', FILE_APPEND);
+
+
+}
+
+
+$text_linka ="  link_id= $lid_id $order_id $keygen";