私はAliexpressからいくつかのCRMへの注文のエクスポートを自動化した私の経験を共有したいと思います。与えられた例はPHPで書かれていますが、他の言語のAliexpressを操作するためのライブラリもあります。リクエストとレスポンスの構造は似ています。あなたがAliexpressを統合するタスクに直面しているなら、私はあなたがこの記事がお役に立てば幸いです。
だから、あなたはすでにAliexpressに店を持っているとしましょう。そして、メニュー項目「開発者」を選択しました。公開時点で、開発者のコンソールのローカリゼーションにいくつかの不具合があり、将来修正される可能性がありますが、作成済みのアプリケーションがコンソールに表示されない場合、または販売者のオフィスからコンソールに入ることが機能しない場合は、いくつかのヒントがあります:
リンクhttps://seller.aliexpress.ru/login?return_url=https%3A%2F%2Fseller.aliexpress.ruをたどってください。これにより、中国語版のコンソールにリダイレクトされるグリッチが修正されます。アプリケーションを作成する
, . , - , . .. , . , «main account not auth subAccount»
SDK . - App Key App Secret. – access_token . . App Key, App Secret access_token, SDK, PHP-, appkey, secretKey sessionKey. , access_token :
. .. , Aliexpress CRM. Aliexpress, . code, curl https://oauth.aliexpress.com/token access_token
https://oauth.aliexpress.com/authorize. access_token
. , access_token – 1 . . «testing». - 1 . , AliPay ( ). , .. – , , , , .. . Aliexpress 2020 .
. , - .
Selenium , .. access_token .
, Ailexpress , CRM.
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new TopClient;
$c->appkey = 'xxxxxxxxxxx';
$c->secretKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
$sessionKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$i = 1;
$req = new AliexpressSolutionProductListGetRequest;
$aeop_a_e_product_list_query = new ItemListQuery;
$aeop_a_e_product_list_query->current_page=$i;
$aeop_a_e_product_list_query->product_status_type="onSelling";
$req->setAeopAEProductListQuery(json_encode($aeop_a_e_product_list_query));
$rez = $c->execute($req, $sessionKey);
var_dump($rez);
$rez . $i. 1, , $rez->result->total_page . . – . . . , . id ( , )
foreach($rez->result->aeop_a_e_product_display_d_t_o_list->item_display_dto as $item){
echo $item->product_id."\t".$item->subject."\n";
}
(, ..), id , . .
$req = new AliexpressSolutionProductInfoGetRequest;
$req->setProductId($id);
$rez = $c->execute($req, $sessionKey);
var_dump ($rez);
, , .
foreach($rez->result->aeop_ae_product_s_k_us->global_aeop_ae_product_sku as $sku){
echo $sku ->id."\t".$sku ->sku_code."\n";
}
c . , , API . , , , .
. , , Product code . . , , , Product code.
. CRM.
$req = new AliexpressSolutionOrderGetRequest;
$param0 = new OrderQuery;
$param0->create_date_end="2221-12-31 12:12:12";
$param0->create_date_start="2021-03-30 12:12:12";
$param0->order_status_list = array("PLACE_ORDER_SUCCESS","IN_CANCEL","WAIT_SELLER_SEND_GOODS","SELLER_PART_SEND_GOODS","WAIT_BUYER_ACCEPT_GOODS","FUND_PROCESSING","IN_ISSUE","IN_FROZEN","WAIT_SELLER_EXAMINE_MONEY","RISK_CONTROL", "FINISH");
$param0->current_page=$i;
$req->setParam0(json_encode($param0));
$rez = $c->execute($req, $sessionKey);
, , . order_status_list. , . , , , .
. «RU shopper» .., , . , . , Aliexpress, .
, . , Aliexpress , - « ». . , Aliexpress, , , 20 .
$req = new AliexpressSolutionOrderInfoGetRequest;
$param1 = new OrderDetailQuery;
$param1->ext_info_bit_flag="11111";
$param1->order_id=$order;
$req->setParam1(json_encode($param1));
$rez = $c->execute($req, $sessionKey);
$n = str_replace("'","''",$rez->result->data->receipt_address->contact_person); //
$p = $rez->result->data->receipt_address->phone_country . $rez->result->data->receipt_address->mobile_no;
//$p = normalize_phone($p) // ..
$zi = $rez->result->data->receipt_address->zip;
$gor = $rez->result->data->receipt_address->city;
$pro = $rez->result->data->receipt_address->province;
$adr = $rez->result->data->receipt_address->detail_address;
if(isset ($rez->result->data->receipt_address->address2)) $adr .=$rez->result->data->receipt_address->address2;
foreach($rez->result->data->child_order_ext_info_list->global_aeop_tp_order_product_info_dto as $item){
$pid = $item->product_id;
$j=json_decode($item->sku);
$s = "";
if(isset ($j->sku[0])) {
$s = $j->sku[0]->pValueId;
}
$cn =$item->quantity;
$pr =$item->unit_price->amount ;
echo $pid."\t". $s." \t " .$cn ." \t ".$pr."\n";
}
, Aliexpress .
, . CRM . , . , Aliexpress, - , .
私は自分のプロジェクトからそれらを取り出し、統合(Aliexpressを含む)からそれらを解きました。各例では、連絡先を作成し、次にリード/取引を作成し、連絡先を割り当てて1つの製品を追加します。あなたがAliexpressで販売を開始することを決定した場合、私は小額の料金で統合を喜んでお手伝いします。さらに、休暇の時期が近づいており、追加のお金が私にもあなたにも干渉することはありません。通信用メールtlx {dog} list.ru。フルフィルメント、テレフォニー、その他のAPIをさまざまなCRMや一般的な自動化スキルと統合した豊富な経験があります。
amoCRM
$subdomain = "xxxxxxxxx";
function amo_call($access_token, $link, $data) {
$headers = [
'Authorization: Bearer ' . $access_token
];
$curl = curl_init(); // cURL
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_CUSTOMREQUEST,'POST');
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($data));
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);
$out = curl_exec($curl); // API
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$code = (int)$code;
$errors = [
400 => 'Bad request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not found',
500 => 'Internal server error',
502 => 'Bad gateway',
503 => 'Service unavailable',
];
try
{
if ($code < 200 || $code > 204) {
return -1;
}
}
catch(\Exception $e)
{
return -1;
}
$response = json_decode($out, true);
return $response;
}
/*
// $access_token. , , .
$link = 'https://' . $subdomain . '.amocrm.ru/oauth2/access_token'; // URL
$data = [
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'grant_type' => 'authorization_code',
'code' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'redirect_uri' => 'http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
];
$curl = curl_init(); // cURL
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_encode($data));
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, 2);
$out = curl_exec($curl); // API
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$code = (int)$code;
$errors = [
400 => 'Bad request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not found',
500 => 'Internal server error',
502 => 'Bad gateway',
503 => 'Service unavailable',
];
try
{
if ($code < 200 || $code > 204) {
throw new Exception(isset($errors[$code]) ? $errors[$code] : 'Undefined error', $code);
}
}
catch(\Exception $e)
{
die(": ' . $e->getMessage() . PHP_EOL . ' : ' . $e->getCode());
}
$response = json_decode($out, true);
var_dump($response);
$access_token = $response['access_token']; //Access
$refresh_token = $response['refresh_token']; //Refresh
$token_type = $response['token_type']; //
$expires_in = $response['expires_in']; //
*/
$access_token ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// . . /api/v4/contacts filter[custom_fields_values]
//
$p ="+79000000000";
$n= " ";
$qnt = 1;
$ord = "xxxxxxxxxxxxxxxxx";
$link='https://'.$subdomain.'.amocrm.ru/api/v2/contacts';
$data = array (
'add' =>
array (
0 =>
array (
'name' => $n,
'custom_fields'=>array(
array(
'id' => '953127',
'values' => array(
array(
"value"=>$p,
"enum"=> "MOB"
),
),
),
),
) ,
) ,
) ;
$response = amo_call($access_token, $link, $data);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
$cid = $response["_embedded"]["items"][0]["id"];
//
$pipeline_id = '4188580';
$lead_status_id = '39384853';
$lead_name =" Aliexpress № " . $ord;
$link='https://'.$subdomain.'.amocrm.ru/api/v2/leads';
$data = array (
'add' =>
array (
0 =>
array (
'name' => $lead_name,
'status_id' => $lead_status_id, //id
'pipeline_id' => $pipeline_id,
'contacts_id'=> array (
$cid
),
),
),
);
$response = amo_call($access_token, $link, $data);
if ($response==-1) {
die("- /n");
} else {
$did = $response["_embedded"]["items"][0]["id"];
var_dump($response);
//
$link='https://'.$subdomain.'.amocrm.ru/api/v4/leads/'.$did.'/link';
$data = array (
0 =>array (
'to_entity_id' => 327219, //id api html ( )
'to_entity_type' =>'catalog_elements',
'metadata' => array(
"quantity" => $qnt,
"catalog_id" => 5321 // id ,
),
),
);
$response = amo_call($access_token, $link, $data);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
//
}
}
Bitrix24
function b24_call($queryUrl, $queryData) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $queryUrl,
CURLOPT_POSTFIELDS => $queryData,
));
$out = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code < 200 || $code > 204) {
return -1;
}
curl_close($curl);
$response = json_decode($out, true);
return $response;
}
$p ="+79000000000";
$n= " ";
$zi = "111111";
$pro = " ";
$gor = "";
$adr = ". 1";
$qnt = 1;
$ord = "xxxxxxxxxxxxxxxxx";
// crm.contact.list array('filter' => array('PHONE' => $ph))
$queryUrl = 'https://xxxxxxxxxx.ru/rest/48/xxxxxxxxxxxxxxxxx/crm.contact.add.json';
$queryData = http_build_query(array(
'fields' => array(
"NAME"=> $n,
"PHONE" => array(array('VALUE' =>$p, 'VALUE_TYPE' => 'MOBILE')),
),
'params' => array("REGISTER_SONET_EVENT" => "N")
));
$response= b24_call($queryUrl, $queryData);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
$cid = $response["result"];
echo "!".$cid."!\n";
$queryUrl = 'https://xxxxxxxxxx.ru/rest/48/xxxxxxxxxxxxxxxxx/crm.requisite.add.json';
$queryData = http_build_query(array(
'fields'=> array(
"PRESET_ID"=> 3,
"ENTITY_TYPE_ID"=> 3,
"ENTITY_ID"=> $cid,
"NAME"=>"",
"ACTIVE"=>"Y",
"SORT"=>100
)
));
$response= b24_call($queryUrl, $queryData);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
$rid = $response["result"];
$queryUrl = 'https://xxxxxxxxxx.ru/rest/48/xxxxxxxxxxxxxxxxx/crm.address.add.json';
$queryData = http_build_query(array(
'fields'=> array(
"TYPE_ID"=> 1,
"ENTITY_TYPE_ID"=> 8,
"ENTITY_ID"=> $rid,
"POSTAL_CODE"=> "$zi",
"PROVINCE"=> "$pro",
"CITY"=> "$gor",
"ADDRESS_1"=> "$adr",
"COUNTRY"=> ""
)
));
$response= b24_call($queryUrl, $queryData);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
$lead_name = " Aliexpress № " . $ord;
$queryUrl = 'https://xxxxxxxxxx.ru/rest/48/xxxxxxxxxxxxxxxxx/crm.lead.add.json';
$queryData = http_build_query(array(
'fields' => array(
"TITLE" => $lead_name,
"TYPE_ID" => "GOODS",
"STAGE_ID" => "NEW",
"CONTACT_ID"=> $cid,
"CURRENCY_ID"=> "RUB",
),
'params' => array("REGISTER_SONET_EVENT" => "Y")
));
$response= b24_call($queryUrl, $queryData);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
$did = $response["result"];
$items = array();
$items[] = array('PRODUCT_ID' => "2968", 'PRICE' => "1.00", 'QUANTITY' => $qnt);
$queryUrl = 'https://xxxxxxxxxx.ru/rest/48/xxxxxxxxxxxxxxxxx/crm.lead.productrows.set.json';
$queryData = http_build_query(array(
"id" => $did,
"rows"=>$items
));
$response= b24_call($queryUrl, $queryData);
if ($response==-1) {
die("- /n");
} else {
var_dump($response);
//
}
}
}
}
}
RetailCRM
$crmKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
function retail_call($url, $postData) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$out = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code < 200 || $code > 204) {
return -1;
}
curl_close($curl);
$response = json_decode($out, true);
return $response;
}
$p ="+79000000000";
$n= " ";
$zi = "111111";
$pro = " ";
$gor = "";
$adr = ". 1";
$qnt = 1;
$ord = "xxxxxxxxxxxxxxxxx";
$url = 'https://xxxxxxxxxx..ru/api/v5/customers/create';
$postData = array(
'site' =>'xxxxxxxxxx.ru',
'customer' => json_encode(array(
'firstName' =>$n,
)),
'apiKey' => $crmKey,
);
$rez = retail_call($url, $postData);
var_dump($rez);
$cid = $rez["id"];
$url = 'https://xxxxxxxxxx.ru/api/v5/orders/create';
$postData = array(
'site' =>'xxxxxxxxxx.ru',
'order' => json_encode(array(
'customer'=> array(
'id' => $cid,
),
'items' => array(
array(
'quantity' => 6,
'offer'=> array(
'externalId' => 'xxxxxxxxxxx',
)
),
))),
'apiKey' => $crmKey,
);
$rez = retail_call($url, $postData);
var_dump($rez);
echo "\n".$rez["id"]."\n";
セレン(access_tokenを取得するため)
from selenium import webdriver
from time import sleep
browser = webdriver.Firefox()
browser.get("https://seller.aliexpress.ru/")
sleep(5)
browser.switch_to.frame(browser.find_element_by_css_selector("iframe.iframe-with-loader_iframe__QQc_0"))
e = browser.find_element_by_id("fm-login-id")
e.send_keys("xxxxxx@xxxxxxxx.ru")
e = browser.find_element_by_id("fm-login-password")
e.send_keys("xxxxxxxxxxxxx")
e = browser.find_element_by_id("fm-login-submit")
e.click()
sleep(15)
browser.get("https://oauth.aliexpress.com/authorize?&response_type=token&client_id=XXXXXXXX&state=1212&view=web&sp=ae")
sleep(5)
try:
e = driver.find_element_by_id("sub")
e.click()
except Exception:
print('Session login')
sleep(5)
txt = "-1"
try:
e = driver.find_element_by_id("wrap")
print(e.get_attribute('innerHTML'))
txt = e.get_attribute('innerHTML')
except Exception:
print('Session login')
x = txt.split("access_token: ")
y = x[1].split("<br>")
print y[0]