1C-Bitrixäžã®ã¹ãã¢ãMindboxãã©ãããã©ãŒã ãšçµ±åããããã«å¿ èŠãªããŒã¿ãAPIãšSDKã䜿çšããŠããŒã¿ãååŸããæ¹æ³ãããã³éåæããŒã¿éä¿¡ãšçµã¿åãããã¢ãããŒãã䜿çšããæ¹æ³ã«ã€ããŠèª¬æããŸãã
Customer Data PlatformãµãŒãã¹ã®å©ããåããŠãå°å£²æ¥è ã¯è¡åããŒã¿ãå«ã顧客ã®èåããèªèãããŸãããã®æ å ±ã¯CDPã«å®å šã«ä¿åãããå°å£²æ¥è ãããŒã±ãã£ã³ã°ãã£ã³ããŒã³ãåæãè¡ãã®ã«åœ¹ç«ã¡ãŸãã
顧客ããã¬ããŸãã¯ãã®ä»ã®è£œåãã«ãŒãã«è¿œå ãããšãCDPã¯ãã®ããŒã¿ãä¿åããŸãããããã«åºã¥ããŠãå°å£²æ¥è ã¯ãŠãŒã¶ãŒãšã®ããåããæ¡å€§ã§ããŸããããšãã°ãåæ§ã®è£œåã®æšå¥šäºé ãå²åŒãæäŸã§ããŸãã
ç§ãã¡ã®ã¯ã©ã€ã¢ã³ãã®1ã€ã§ããé»æ°åºã®ãã§ãŒã³ã¯ãMindbox CDPãã©ãããã©ãŒã ã«æ¥ç¶ããããšã決å®ããçµ±åã®æ¯æŽãæ±ããŸãããäž»èŠãªãŠãŒã¶ãŒã·ããªãªïŒæ¿èªãã«ãŒããžã®è¿œå ãæ¯æããªã©ïŒã®çµ±åãå®è¡ããŸããã
ããã¯ã°ã©ãŠã³ã
ãªã³ã©ã€ã³ã¹ãã¢ã¯ãAPIãŸãã¯JavaScript SDKã䜿çšãã2ã€ã®äž»ãªæ¹æ³ã§Mindboxã«æ¥ç¶ã§ããŸãïŒéãã«ã€ããŠã¯åŸã§èª¬æããŸãïŒã
æåã®æ¹æ³ãéžæããããã«ãMindboxã®ããã¥ã¡ã³ããåç §ããååãªæ å ±ããªãå Žåã¯ããããŒãžã£ãŒã«è³ªåããŸãããç§ãã¡ã®ã³ã©ãã¬ãŒã·ã§ã³ã¯ãMindboxãã©ãããã©ãŒã ã®æ¥éãªæé·ã®ææãšäžèŽããŠããããšãããããŸãããMindboxAPIåŒã³åºãã®1æ¥ã®å¹³åè² è·ã¯ã2åã«ãªããŸããïŒ1åãããæ倧12äžãªã¯ãšã¹ããããŒã¯æã¯æ倧25äžãªã¯ãšã¹ãïŒãã€ãŸãããã©ãã¯ãã©ã€ããŒããã®ä»ã®è²©å£²ã§ã¯ãè² è·ãããã«å¢å ãââããããCDPãµãŒãã¹ãå©çšã§ããªããªããçµ±åããããªã³ã©ã€ã³ã¹ãã¢ããããŒã¿ãåä¿¡ã§ããªããªããªã¹ã¯ããããŸããã
Mindboxã¯ãã®åé¡ã«è¿ éã«å¯Ÿå¿ããITã·ã¹ãã ã®ã¢ãŒããã¯ãã£ãšã€ã³ãã©ã¹ãã©ã¯ãã£ãæ¹åããŠ4åã®å®å šä¿æ°ãéæãå§ããŸããã次ã«ãè³Œå ¥ããŒã¿ãMindboxã«ã¹ã ãŒãºã«éä¿¡ãããããã«ããå¿ èŠããããŸãããããã«ã¯ãæãä¿¡é Œæ§ã®é«ãçµ±åæ¹æ³ãéžæããå¿ èŠããããŸããã
ãã€ã³ãããã¯ã¹ã®çµ±åæ¹æ³
äžèšã®ããã«ãMindboxã¯APIãŸãã¯JavaScriptSDKã䜿çšããŠæ¥ç¶ããããšããå§ãããŸãã次ã«ããããã®æ©èœã«ã€ããŠæ€èšããŸãã
JavaScript SDK
ã©ã€ãã©ãªã¯ããµãŒãã¹ã«ãã£ãŠæäŸãããAPIã®ãã©ãããŒãã§ãããã®å©ç¹ã¯ãçµ±åã容æã§ãããéåæããŒã¿è»¢éãå¯èœã§ããããšã§ããWebãã©ãããã©ãŒã ã®ã¿ããµããŒãããå¿ èŠãããå Žåã«æé©ã§ãã
å¶éäºé ïŒéä¿¡æã«Mindboxã䜿çšã§ããªãå ŽåãããŒã¿ã倱ãããå¯èœæ§ããããŸãããªã³ã©ã€ã³ã¹ãã¢åŽã§jsãšã©ãŒãçºçããå Žåããã©ãããã©ãŒã ã¹ã¯ãªããã¯èªã¿èŸŒãŸããŸããã
APIçµ±å
ã¹ãã¢ãšMindboxã®çµ±åã¯ãAPIãä»ããŠå®è¡ã§ããŸãããã®æ¹æ³ã¯ãJavaScriptãžã®äŸåãæžãããéåæããŒã¿éä¿¡ã®èšå®ã«ãé©ããŠããŸãã
å¶éäºé ïŒäžéšã®CookieããŒã¿ãã€ãŸãããã€ã¹äžã®ãŠãŒã¶ãŒã®äžæã®èå¥åïŒmindboxDeviceUUIDïŒãåä¿¡ããªãã£ããšããäºå®ã«çŽé¢ããŸããããŠãŒã¶ãŒæ å ±ãæ¥çããã«ã¯ãã»ãšãã©ã®Mindboxæäœã§æž¡ãå¿ èŠããããŸãã
ããã¥ã¡ã³ãã§ã¯ããããã®Cookieã¯ãã¹ãŠã®æäœã«å¿ èŠãªããã§ã¯ãããŸãããããã§ããäžæã®ãªãããŒã¿éä¿¡ãç®æããŠããã®åé¡ã«ã€ããŠMindboxã®ãããŒãžã£ãŒãšè©±ãåããŸãããä¿¡é Œæ§ãæ倧åããã«ã¯ãåžžã«Cookieãéä¿¡ããããšããå§ãããŸãããã ããCookieãåä¿¡ããã«ã¯JavaScriptSDKã䜿çšããå¿ èŠããããŸãã
çµã¿åãããæ¹æ³
äžèšã®çµ±åæ¹æ³ãæ€èšããŸããããçŽç²ãªåœ¢ã§ã¯ãããžã§ã¯ãã«é©ããŠããŸããã§ãããå°å£²æ¥è ã®ããžãã¹äžã®åé¡ã解決ãããã€ã€ã«ãã£ã·ã¹ãã ãæ§ç¯ããã«ã¯ãCookieã®èå¥åãå«ãããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã«é¢ããããŒã¿ã®å®å šãªã»ãããMindboxã«è»¢éããå¿ èŠããããŸãããåæã«ãJavaScriptãžã®äŸåãšãMindboxãäžæçã«å©çšã§ããªããªã£ãå Žåã®ããŒã¿æ倱ã®ãªã¹ã¯ãæžããããšãç®æããŸããã
ãããã£ãŠã3çªç®ã®çµã¿åãããæ¹æ³ã«ç®ãåããŸããããã¥ãŒã¢ãžã¥ãŒã«ã䜿çšããŠãAPIãšJavaScriptSDKã®äž¡æ¹ãæäœããŸãã
Javascript SDKã䜿çšããŠããµã€ãäžã®ãŠãŒã¶ãŒãèå¥ããŸãïŒmindboxDeviceUUIDïŒã次ã«ããµãŒããŒåŽã§ãå¿ èŠãªãã¹ãŠã®ããŒã¿ã䜿çšããŠèŠæ±ãäœæãããã¥ãŒã«å ¥ããŸãã APIãä»ãããã¥ãŒããã®èŠæ±ã¯ãMindboxãµãŒãã¹ã«éä¿¡ãããŸããçãããããããã®å ŽåãèŠæ±ã¯åãã¥ãŒã€ã³ã°ãããŸãããããã£ãŠãããŒã¿ãéä¿¡ãããšããMindboxã¯å¿ èŠãªæ å ±ã®å®å šãªã»ãããåãåããŸãã
以äžã®äŸã§ã¯ãSenderã¯ã©ã¹ã䜿çšãããšãå¿çã®åæåŠçãå®è¡ããããšã«ãããèŠæ±ãåéããŠéä¿¡ã§ããŸãããã®ã¯ã©ã¹ã¯ãã³ãã³ãèªäœïŒèŠæ±/å¿çã®ã¿ã€ããdeviceUUIDãªã©ïŒããã³ã¢ãžã¥ãŒã«èšå®ïŒAPIãããŒã¯ã³ãªã©ãæäœããããã®ãã©ã¡ãŒã¿ãŒïŒããã®ããŒã¿ã䜿çšããŸãã
<?php
declare(strict_types=1);
namespace Simbirsoft\MindBox;
use Bitrix\Main\Web\Uri;
use Bitrix\Main\Web\HttpClient;
use Simbirsoft\Base\Converters\ConverterFactory;
use Simbirsoft\MindBox\Contracts\SendableCommand;
class Sender
{
/** @var Response */
protected $response;
/** @var SendableCommand */
protected $command;
/**
* Sender constructor.
*
* @param SendableCommand $command
*/
public function __construct(SendableCommand $command)
{
$this->command = $command;
}
/**
* .
*
* @return array
*/
protected function getHeaders(): array
{
return [
'Accept' => Type\ContentType::REQUEST[$this->command->getRequestType()],
'Content-Type' => Type\ContentType::RESPONSE[$this->command->getResponseType()],
'Authorization' => 'Mindbox secretKey="'. Options::get('secretKey') .'"',
'User-Agent' => $this->command->getHttpInfo('HTTP_USER_AGENT'),
'X-Customer-IP' => $this->command->getHttpInfo('REMOTE_ADDR'),
];
}
/**
* .
*
* @return string
*/
protected function getUrl(): string
{
$uriParts = [
Options::get('apiUrl'),
$this->command->getOperationType(),
];
$uriParams = [
'operation' => $this->command->getOperation(),
'endpointId' => Options::get('endpointId'),
];
$deviceUUID = $this->command->getHttpInfo('deviceUUID');
if (!empty($deviceUUID)) {
$uriParams['deviceUUID'] = $deviceUUID;
}
return (new Uri(implode('/', $uriParts)))
->addParams($uriParams)
->getUri();
}
/**
* .
*
* @return bool
*/
public function send(): bool
{
$httpClient = new HttpClient();
$headers = $this->getHeaders();
foreach ($headers as $name => $value) {
$httpClient->setHeader($name, $value, false);
}
$encodedData = null;
$request = $this->command->getRequestData();
if (!empty($request)) {
$converter = ConverterFactory::factory($this->command->getRequestType());
$encodedData = $converter->encode($request);
}
$url = $this->getUrl();
if ($httpClient->query($this->command->getMethod(), $url, $encodedData)) {
$converter = ConverterFactory::factory($this->command->getResponseType());
$response = $converter->decode($httpClient->getResult());
$this->response = new Response($response);
return true;
}
return false;
}
/**
* @return Response
*/
public function getResponse(): Response
{
return $this->response;
}
}
Sendableãã¬ã€ãã«ã¯ãMindboxã«ãªã¯ãšã¹ããéä¿¡ããããã®ãã¹ãŠã®å¯èœãªã³ãã³ãèšå®ãå«ãŸããŠããŸããããã«ã¯ããªã¯ãšã¹ã/ã¬ã¹ãã³ã¹ã®ã¿ã€ãããªã¯ãšã¹ãã¡ãœãããsync / asyncãã©ã¡ãŒã¿ãªã©ã®äºåå®çŸ©ããããã®ãå«ãŸããŸãããŸãããã¹ãŠã®ã³ãã³ãã«å ±éã®ã¡ãœãããå«ãŸããŠããŸãã
<?php
declare(strict_types=1);
namespace Simbirsoft\MindBox\Traits;
use RuntimeException;
use Bitrix\Main\Context;
use Simbirsoft\MindBox\Type;
use Simbirsoft\MindBox\Sender;
use Simbirsoft\MindBox\Response;
use Bitrix\Main\Localization\Loc;
use Simbirsoft\MindBox\Contracts\SendableCommand;
Loc::loadMessages($_SERVER['DOCUMENT_ROOT'] .'/local/modules/simbirsoft.base/lib/Contracts/Command.php');
trait Sendable
{
/** @var string (GET/POST) */
protected $method = Type\OperationMethod::POST;
/** @var string (sync/async) */
protected $operationType = Type\OperationType::ASYNC;
/** @var string (json/xml) */
protected $requestType = Type\ContentType::JSON;
/** @var string (json/xml) */
protected $responseType = Type\ContentType::JSON;
/** @var array */
protected $data = [];
/**
* .
* @return string
*/
abstract public function getOperation(): string;
/**
* .
*
* @return array
*/
abstract public function getRequestData(): array;
/**
* HTTP
*
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
*
*
* @return string
*
* @noinspection PhpUnused
*/
public function getOperationType(): string
{
return $this->operationType;
}
/**
* .
*
* @return string
*
* @noinspection PhpUnused
*/
public function getRequestType(): string
{
return $this->requestType;
}
/**
* .
*
* @return string
*
* @noinspection PhpUnused
*/
public function getResponseType(): string
{
return $this->responseType;
}
/**
*
*
* @return void
*/
public function initHttpInfo(): void
{
$server = Context::getCurrent()->getServer();
$request = Context::getCurrent()->getRequest();
$this->data = [
'X-Customer-IP' => $server->get('REMOTE_ADDR'),
'User-Agent' => $server->get('HTTP_USER_AGENT'),
'deviceUUID' => $request->getCookieRaw('mindboxDeviceUUID'),
];
}
/**
*
*
* @param string $key
* @param string $default
*
* @return string
*
* @noinspection PhpUnused
*/
public function getHttpInfo(string $key, string $default = ''): string
{
return $this->data[$key] ?? $default;
}
/**
* .
*
* @return void
*
* @throws RuntimeException
*/
public function execute(): void
{
/** @var SendableCommand $thisCommand */
$thisCommand = $this;
$sender = new Sender($thisCommand);
if ($sender->send()) {
throw new RuntimeException(Loc::getMessage('BASE_COMMAND_NOT_EXECUTED'));
}
$response = $sender->getResponse();
if (!$response->isSuccess()) {
throw new RuntimeException(Loc::getMessage('BASE_COMMAND_NOT_EXECUTED'));
}
if (!$this->prepareResponse($response)) {
throw new RuntimeException(Loc::getMessage('BASE_COMMAND_NOT_EXECUTED'));
}
}
/**
* .
*
* @param Response $response
*
* @return bool
*/
public function prepareResponse(Response $response): bool
{
// $body = $response->getBody();
// $status = $body['customer']['processingStatus'];
/**
* :
* AuthenticationSucceeded -
* AuthenticationFailed -
* NotFound -
*/
return true;
}
}
äŸãšããŠããŠãŒã¶ãŒèªèšŒã€ãã³ãã«ã€ããŠèããŠã¿ãŸããæ¿èªã€ãã³ããã³ãã©ãŒã§ãAuthorizationCommandã¯ã©ã¹ã®ãªããžã§ã¯ãããã¥ãŒã«è¿œå ããŸãããã®ã¯ã©ã¹ã§ã¯ãã³ãã³ãã®å®è¡æã«ããŒã¿ããŒã¹å ã®ããŒã¿ãå€æŽãããå¯èœæ§ããããããããä¿åããå¿ èŠããããããå¿ èŠæå°éã®æ å ±ã®æºåãè¡ãããŸãããŸããMindboxã®ãªã¯ãšã¹ãã«å¯Ÿå¿ãããã©ã¡ãŒã¿ãèšå®ãããŸãããã®å Žåãããã¯æäœã®ååã§ãïŒMindbox管çããã«ã«ãããŸãïŒãããã«ãSendableç¹æ§ã«åŸã£ãŠãèŠæ±/å¿çã®ã¿ã€ããèŠæ±ã¡ãœãããããã³sync / asyncãã©ã¡ãŒã¿ãŒãæå®ã§ããŸãã
<?php
declare(strict_types=1);
namespace Simbirsoft\MindBox\Commands;
use Simbirsoft\Queue\Traits\Queueable;
use Simbirsoft\MindBox\Traits\Sendable;
use Simbirsoft\Queue\Contracts\QueueableCommand;
use Simbirsoft\MindBox\Contracts\SendableCommand;
final class AuthorizationCommand implements QueueableCommand, SendableCommand
{
use Queueable, Sendable;
/** @var array */
protected $user;
/**
* AuthorizationCommand constructor.
*
* @param array $user
*/
public function __construct(array $user)
{
$keys = ['ID', 'EMAIL', 'PERSONAL_MOBILE'];
$this->user = array_intersect_key($user, array_flip($keys));
$this->initHttpInfo();
}
/**
* .
*
* @return string
*/
public function getOperation(): string
{
return 'AuthorizationOnWebsite';
}
/**
* .
*
* @return array
*/
public function getRequestData(): array
{
return [
'customer' => [
'email' => $this->user['EMAIL'],
],
];
}
}
ã¢ãžã¥ãŒã«çžäºäœçšã¹ããŒã
ç§ãã¡ã®ãããžã§ã¯ãã§ã¯ã次ã®3ã€ã®ã¢ãžã¥ãŒã«ãç¹å®ããŸããã
ããŒã¹
ãããžã§ã¯ãå šäœã§äœ¿çšã§ããäžè¬çãªãŠãŒãã£ãªãã£ã¯ã©ã¹ãšã€ã³ã¿ãŒãã§ã€ã¹ïŒã³ãã³ãã€ã³ã¿ãŒãã§ã€ã¹ãªã©ïŒãæ ŒçŽããŸãã
ãã¥ãŒã¢ãžã¥ãŒã«
Mindboxãšã®çžäºäœçšã¯ãã³ãã³ããä»ããŠå®è£ ãããŸããããããé çªã«å®è¡ããã«ã¯ããã¥ãŒã¢ãžã¥ãŒã«ã䜿çšããŸãããã®ã¢ãžã¥ãŒã«ã¯ãçä¿¡ã³ãã³ããä¿åããæãæ¥ããšãã«ããããå®è¡ããŸãã
ãã€ã³ãããã¯ã¹çµ±åã¢ãžã¥ãŒã«
ãã®ã¢ãžã¥ãŒã«ã¯ãæ¿èªãç»é²ã泚æã®äœæãã«ãŒããžã®è¿œå ãªã©ããµã€ãäžã®ã€ãã³ããããã£ãããããã³ãã³ããçæããŠãã¥ãŒã¢ãžã¥ãŒã«ã«éä¿¡ããŸãã
Mindboxã¢ãžã¥ãŒã«ã¯ãCookieããã®ãã®ãå«ãããµã€ãäžã®ã€ãã³ããšé¢é£æ å ±ãç£èŠãããããããã³ãã³ããäœæããŠãã¥ãŒã«å ¥ããŸãããã¥ãŒã¢ãžã¥ãŒã«ããã¥ãŒããã³ãã³ããååŸããŠå®è¡ãããšãããŒã¿ãéä¿¡ãããŸãããã€ã³ãããã¯ã¹ããã®åçãåŠå®çãªå Žåã倱æããã³ãã³ãã¯ãã¥ãŒã®æåŸã«ç§»åãããè¯å®çãªå Žåãæåããã³ãã³ãã¯ãã¥ãŒããåé€ãããŸãã
ãããã£ãŠãäžèšã®çµã¿åãããæ¹æ³ã䜿çšããŠãMindboxãžã®ã¹ã ãŒãºãªããŒã¿è»¢éãä¿èšŒããããšãã§ããŸããã
ãŸãšã
ãã®èšäºã§ã¯ããªã³ã©ã€ã³ã¹ãã¢ãã«ã¹ã¿ããŒããŒã¿ãã©ãããã©ãŒã ã«æ¥ç¶ããŠãã€ã€ã«ãã£ã·ã¹ãã ãéçºããæ¹æ³ãæ€èšããŸããã
ãã®äŸã§ã¯ã2ã€ã®äž»èŠãªæ¥ç¶æ¹æ³ãMindboxã®ããã¥ã¡ã³ãã§èª¬æãããŠããŸããJavascriptSDKçµç±ãšAPIçµç±ã§ããCDPãµãŒãã¹ãäžæçã«å©çšã§ããªããªã£ãå Žåã§ããããŒã¿éä¿¡ã®ä¿¡é Œæ§ãåäžãããããã«ãAPIãšJavascript SDKã䜿çšããéåæããŒã¿éä¿¡ãè¡ã3çªç®ã®çµã¿åããæ¹æ³ãéžæããŠå®è£ ããŸããã
æž èŽããããšãããããŸããïŒãã®èšäºãã圹ã«ç«ãŠã°å¹žãã§ãã