Commit b5947730 authored by Kulya's avatar Kulya 😊

Upd function for Headers

parent 25f1dbd5
......@@ -305,12 +305,124 @@ class AloVoiceRest
}
}
private function process_bx_product($data,$full=false) {
$conf = self::get_billzconf();
// $data["xmlId"] = "1226zz";
$arProduct = [];
$xmlId = (!empty($data["xmlId"])) ? $data["xmlId"] : $data["id"];
$select = ($full) ? [ 'id', 'iblockId', '*' ] : ['id', 'iblockId'];
$result = BxRest::call('catalog.product.list',[
"filter" => [
"xmlId" => $data["xmlId"],
"iblockId" => $conf["bx_catalog_id"],
],
"select" => $select
]);
if(!empty($result["result"]["products"])){
$arProduct = $result["result"]["products"][0];
}
if(empty($arProduct)){
$arNewProductParams = [];
}
return $arProduct;
}
private function billz_products_all_synch($r=false) {
$tms["0_begin"] = time();
$return = ["result"=>false];
$date = "2018-01-01T00:00:00Z";
echo "\nBegin loading billz products [date_from:".$date."]...";
$allProds = BillzRest::getProducts($date);
echo "\n Billz products loaded done!";
if(!empty($allProds["answer"]["result"])){
echo "\n Billz begin product saving...";
$tms["1_saving"] = time();
$jsProducts = json_encode($allProds);
$return["count"] = count($allProds["answer"]["result"]);
$return["result"] = file_put_contents(__DIR__."/billz_allproducts.json",$jsProducts);
$tms["2_saved"] = time();
echo "\n Billz products saved!";
}
$tms["3_end"] = time();
$tms["9_ALL"] = $tms["3_end"]-$tms["0_begin"];
echo "\n DONE!!";
$return["times"] = $tms;
return $return;
}
private function get_byinn($r=false) {
return ALVC::requesTaxInn($r["inn"]);
}
private function billz_catalog_infos_synch($r=false) {
$p=1;
$ps=10;
$loadedCnt = 0;
$bxlang = 'Ru';
$tms["0_begin"] = time();
$arAllProperties = [
"name" => 'Наименование', //"*Tahorat va namoz",
"sku" => 'Артикуль', //"Q001",
"barCode" => 'Баркод', //"9789943542556",
"price" => 'Цена', //23000,
"priceUSD" => 'ЦенаUSD', //23000,
"discountAmount" => 'Скидка', //0,
"qty" => 'Количество', //15,
"_imageUrls.url" => 'Изображение', //15,
"_offices" => 'В складах', //15,
/*{
"officeID": 1347,
"officeName" => "Qamar Kitoblar A.Navoiy",
"price": 23000,
"priceUSD": 23000,
"discountAmount": 0,
"qty": 15
}*/
];
$sdata = date("Y-m-d")."T".date("H").":00:00Z";
$first = BillzRest::getProducts($sdata);
if(!empty($first["answer"]["result"])){
if(!empty($first["answer"]["result"][0]["properties"])){
foreach( $first["answer"]["result"][0]["properties"] as $prk=>$prp){
$arAllProperties["properties_".$prk] = $prk;
}
}
}
$arConf = self::get_billzconf();
$arConf["billz_productfields"] = $arAllProperties;
self::save_billzconf(["conf"=>$arConf]);
$return = ["billzprops"=>count($arAllProperties)];
ALVC::eLog($return,"------ AloVoiceRest :: billz_catalog_infos_synch CRON Done!");
return $return;
}
private function billz_catalog_infos_synch_OLD($r=false) {
$p=1;
$ps=10;
$loadedCnt = 0;
$bxlang = 'Ru';
$tms["0_begin"] = time();
// $arAllBrands = [];
$arAllCategories = [];
......@@ -322,7 +434,7 @@ class AloVoiceRest
'officeId' => 'Номер магазина',
'officeName' => 'Магазин',
'prices_retailPriceUzs' => 'Цена',
'vendorCode' => 'Код производителя',
'vendorCode' => 'Артикуль',
];
$first = BillzRest::getCatalog();
......@@ -403,12 +515,9 @@ class AloVoiceRest
}
private function billz_load_product($r=false) {
$res = BxRest::call("catalog.product.list",[
"filter" => [
"id" => $conf["bx_catalog_id"],
"productType" => 1
]
]);
$products = BillzRest::getProducts();
return $products;
}
private function billz_catalog_synch($r=false) {
......
......@@ -10,6 +10,86 @@ require_once (__DIR__.'/keys.php');
const VERSION = '1.1';
const TYPE_TRANSPORT = 'json';
public static function getProducts($data=false) {
if(!empty($data)) {
$sdata = $data;
}
else {
$sdata = date("Y-m-d")."T".date("H").":00:00Z";
}
$getParams = [
"LastUpdatedDate" => $sdata,
"WithProductPhotoOnly" => 0,
"IncludeEmptyStocks" => 0
];
$result = static::callCurl("products.get",$getParams);
print_r($getParams);
return $result;
}
public static function getCatalog($page=1,$cnt=1) {
$result = static::callCurl("catalog.get",[
"PerPage" => (int)$cnt,
"Page" => (int)$page,
"Sort" => [
"type" => "num",
"field" => "id",
"order" => "desc"
]
]);
return $result;
}
public static function base64_url_encode($input) {
return trim(strtr(base64_encode($input), '+/', '-_'), '=');
}
public static function connectionSettings(){
$conf = self::getAppSettings();
$now = time();
$exp = $now+150000;
$headerArray = array(
'typ'=> 'JWT',
'alg'=> 'HS256'
);
$payloadArray = array(
'iss'=> $conf["iss"],
'iat'=> $now,
'exp'=> $exp,
'sub'=> $conf["sub"]
);
$header = self::base64_url_encode(json_encode($headerArray, JSON_FORCE_OBJECT));
$payload = self::base64_url_encode(json_encode($payloadArray, JSON_FORCE_OBJECT));
$unsignedToken = $header .'.'. $payload;
$signature = hash_hmac("sha256", $unsignedToken, $conf["secret"], true);
$encodedSignature = self::base64_url_encode($signature);
$token = $unsignedToken . '.' . $encodedSignature;
return ["token"=>$token, "url"=>$conf["url"]];
}
public static function getAppSettings()
{
return [
"url" => "https://api.billz.uz/v4/",
"iss" => "qam.bitrix24.ru",
"sub" => "qamar.bitrix24",
"secret" => "iRPiwoNhnyhyyLMtADtINSuxHyVmsrXpvtejrAuERdyhhj2EPtMxUorppLUnELVhRmIpnGWsHSpwCzCWsjJLENekd9WumpLjPHvUQDwWmcuwotmhvEyIzzSVkejywICwzKrSDXucLE3SGQtyDVcmpeFBneSMmxuKMjo6Q2kGIGbfQkupBm3mMGXmPIEpwMNYNV38VcemDd6fPYQnRcyYERXctSGMTXFwdmDLoYBE6btCfNZfkdoBFmbhpQJpBkifPUScyQRGeRbkFxjEwvnXjhCSCMbpkjjfWkFeesnPupKkiKKKL8MkSKx6HuRIzbmbcGNJNWtrkx3sSM1MjPzCTiWE2wM1SZQWVYu8hDBVUVDKxBeRisKTjjeidboGWJNhWcpzQEJe4cMSjBvNNxxBiveZ0iDdMpcSYsJNfoVTT8mSkavRzmHeeSGXKSDDTmwjUwfoPsHhWJTt7BrauLIRhIrjKnsYZscNvSGYRDyVwBXaS8YfELUBUMSFjYnpjJVs"
];
}
protected static function callCurl($method,$params=[])
{
if(!function_exists('curl_init'))
......@@ -95,84 +175,6 @@ require_once (__DIR__.'/keys.php');
return $result;
}
/**
* Generate a request for callCurl()
*
* @var $method string
* @var $params array method params
* @return mixed array|string|boolean curl-return or error
*/
public static function getProducts() {
$result = static::callCurl("products.get",[
"LastUpdatedDate" => "2021-12-01T09:00:25Z",
"WithProductPhotoOnly" => 0,
"IncludeEmptyStocks" => 0
]);
return $result;
}
public static function getCatalog($page=1,$cnt=1) {
$result = static::callCurl("catalog.get",[
"PerPage" => (int)$cnt,
"Page" => (int)$page,
"Sort" => [
"type" => "num",
"field" => "id",
"order" => "desc"
]
]);
return $result;
}
public static function base64_url_encode($input) {
return trim(strtr(base64_encode($input), '+/', '-_'), '=');
}
public static function connectionSettings(){
$conf = self::getAppSettings();
$now = time();
$exp = $now+15000;
$headerArray = array(
'typ'=> 'JWT',
'alg'=> 'HS256'
);
$payloadArray = array(
'iss'=> $conf["iss"],
'iat'=> $now,
'exp'=> $exp,
'sub'=> $conf["sub"]
);
$header = self::base64_url_encode(json_encode($headerArray, JSON_FORCE_OBJECT));
$payload = self::base64_url_encode(json_encode($payloadArray, JSON_FORCE_OBJECT));
$unsignedToken = $header .'.'. $payload;
$signature = hash_hmac("sha256", $unsignedToken, $conf["secret"], true);
$encodedSignature = self::base64_url_encode($signature);
$token = $unsignedToken . '.' . $encodedSignature;
return ["token"=>$token, "url"=>$conf["url"]];
}
public static function getAppSettings()
{
return [
"url" => "https://api.billz.uz/v2/",
"iss" => "qam.bitrix24.ru",
"sub" => "qamar.bitrix24",
"secret" => "iRPiwoNhnyhyyLMtADtINSuxHyVmsrXpvtejrAuERdyhhj2EPtMxUorppLUnELVhRmIpnGWsHSpwCzCWsjJLENekd9WumpLjPHvUQDwWmcuwotmhvEyIzzSVkejywICwzKrSDXucLE3SGQtyDVcmpeFBneSMmxuKMjo6Q2kGIGbfQkupBm3mMGXmPIEpwMNYNV38VcemDd6fPYQnRcyYERXctSGMTXFwdmDLoYBE6btCfNZfkdoBFmbhpQJpBkifPUScyQRGeRbkFxjEwvnXjhCSCMbpkjjfWkFeesnPupKkiKKKL8MkSKx6HuRIzbmbcGNJNWtrkx3sSM1MjPzCTiWE2wM1SZQWVYu8hDBVUVDKxBeRisKTjjeidboGWJNhWcpzQEJe4cMSjBvNNxxBiveZ0iDdMpcSYsJNfoVTT8mSkavRzmHeeSGXKSDDTmwjUwfoPsHhWJTt7BrauLIRhIrjKnsYZscNvSGYRDyVwBXaS8YfELUBUMSFjYnpjJVs"
];
}
/**
* @var $data mixed
* @var $encoding boolean true - encoding to utf8, false - decoding
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment