crenata/affiliate-connector

两个 Laravel 框架之间的连接器

v1.0.0 2022-08-15 09:45 UTC

This package is auto-updated.

Last update: 2024-09-05 06:58:53 UTC


README

GitHub top language GitHub all releases GitHub issues GitHub GitHub release (latest by date including pre-releases)

连接器

一个 Laravel 包,用作 Affiliate 和产品之间的连接器。

警告

此包仅供内部使用,任何问题将不会得到响应。

安装

在您的 Laravel 项目文件夹中运行以下命令。

composer require crenata/affiliate-connector

发布配置

您需要发布包的配置。要发布配置,请运行以下命令。

php artisan vendor:publish --tag=connector-config

生成身份验证桥

为了保护桥,您必须在您的 serverclient 项目中生成 secret keyprivate key。要生成密钥,请运行以下命令。

php artisan connector:generate

您将看到。

Server : CONNECTOR_SERVER=dc6917876732a081d1d35b225aedab5bae8e5438
Client : CONNECTOR_CLIENT=ba770d272202ad9b938638687760e2ec96a7e954b19447fd5f412c615e2c7ef7

Copy the key to the .env file each projects.

在服务器部分,将 CONNECTOR_SERVER 添加到 .env 文件中。同样,在客户端部分,将 CONNECTOR_CLIENT 添加到 .env 文件中。

用法

请确保您遵循以下步骤。

创建获取所有产品的查询

创建获取所有产品的查询,并将 config/connector.php 中的默认控制器更改为您创建的控制器。

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "products",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@getProducts" // Replace with your controller.
    ],
    ...
]

预期返回值

[
    [
        "id" => int,
        "name" => string,
        "description" => string,
        "price" => int
    ],
    ...
]

创建获取具有 ID 的产品的查询

创建使用 WHERE id IN() 获取产品的查询,并将 config/connector.php 中的默认控制器更改为您创建的控制器。在此请求中,您将收到带有 ids 参数的查询字符串,该参数为 string 类型,包含用逗号分隔的 product ids

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "product-with-ids",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@getProductWithIds" // Replace with your controller.
    ],
    ...
]

预期返回值

[
    [
        "id" => int,
        "name" => string,
        "description" => string,
        "price" => int
    ],
    ...
]

创建查找产品

创建使用 WHERE id 获取产品的查询,并将 config/connector.php 中的默认控制器更改为您创建的控制器。在此请求中,您将收到带有 id 参数的查询字符串,该参数为 int 类型。

"api" => [
    [
        "method" => HttpMethodConstant::GET,
        "url" => "find-product",
        "controller" => "Crenata\AffiliateConnector\Http\Controllers\ConnectorController@findProduct" // Replace with your controller.
    ],
    ...
]

预期返回值

[
    "id" => int,
    "name" => string,
    "description" => string,
    "price" => int
]

提交交易

将交易数据提交到 Affiliate 数据库。这样,Affiliate 就可以计算奖励。

$response = ConnectorRequest::getInstance()
    ->setUrl(
        ConnectorUrl::getInstance()
            ->affiliate()
            ->getUrl("submit_transaction")
    )
    ->setMethod(HttpMethodConstant::POST) // Refer to Crenata\AffiliateConnector\Constants\HttpMethodConstant
    ->setBody([
        "product_id" => 1,
        "user_email" => "user@gmail.com",
        "transaction_code" => "INV-2022-IX-05-12-00",
        "product_name" => "Product Name",
        "product_description" => "Product Desc",
        "product_price" => 100000,
        "status" => TransactionStatusConstant::PENDING // Refer to Crenata\AffiliateConnector\Constants\TransactionStatusConstant
    ])
    ->setTimeout(5)
    ->send();

$result = ConnectorResponse::getInstance()->response($response);

if ($result->isSuccess()) {
    // your code here ...
}

作者