EasyTBK Documentation

repository·master·Indexed 20 days ago

https://github.com/flutterbest/easytbk

A Laravel-based SDK wrapper providing a unified interface for interacting with multiple Chinese affiliate platforms, including Taobao, Jingdong (JD), Pinduoduo (PDD), Vipshop, and Suning. Supports Laravel versions 5 through 8.

Tokens
11.2K
Snippets
26
Records
28
Agent score
69%

What's inside EasyTBK

  1. Install the EasyTBK package

    master

    EasyTBK is a Laravel-compatible SDK wrapper for various affiliate platforms (Taobao, JD, Pinduoduo, Vip, and Suning). It supports Laravel versions 5 through 8.

    To install, use Composer to add the package to your Laravel project.

    composer require niugengyun/easytbk
  2. Publish the EasyTBK configuration

    master

    After installing the package via Composer, you must publish the configuration file to your Laravel project. Once published, you can modify config/easytbk.php to set your platform credentials.

    php artisan vendor:publish --provider "NiuGengYun\EasyTBK\ServiceProvider"
  3. Initialize the Vip (Vipshop) SDK

    master

    The Vip SDK follows a different usage pattern compared to other platforms. You must use the UnionPidServiceClient::getService() method to obtain the service instance, and call Factory::vip() to ensure the environment is set up.

    <?php
    use NiuGengYun//EasyTBK//Factory;
    use NiuGengYun//EasyTBK//Vip//Request//PidGenRequest;
    use NiuGengYun//EasyTBK//Vip//Request//UnionPidServiceClient;
    
    // 唯品会官方的sdk写的比较垃圾,用法和其他平台稍微不一样
    $service= UnionPidServiceClient::getService();
    Factory::vip();
    $pidGenRequest1 = new PidGenRequest();
    $pidNameList2 = array();
    $pidNameList2[0] = "value";
    $pidGenRequest1->pidNameList = $pidNameList2;
    $pidGenRequest1->requestId = "requestId";
    dd($service->genPidWithOauth($pidGenRequest1));
  4. Initialize the Pinduoduo (PDD) SDK

    master

    Use Factory::pinduoduo() to get a Pinduoduo client instance. Use DdkGoodsDetailRequest to fetch goods details by providing a list of goods IDs.

    <?php
    use NiuGengYun//EasyTBK//Factory;
    use NiuGengYun//EasyTBK//pinduoduo//request//DdkGoodsDetailRequest;
    
    $pdd = Factory::pinduoduo();
    $req = new DdkGoodsDetailRequest();
    $req->setGoodsIdList("[$itemid]");
    return  $pdd->execute($req);
  5. Initialize the Suning Alliance SDK

    master

    Use Factory::suning() to get a Suning client instance. You can use request classes like CouponproductQueryRequest to query coupon products by setting parameters such as pageNo, pageSize, and positionId.

    <?php
    use NiuGengYun//EasyTBK//Factory;
    use NiuGengYun//EasyTBK//suning//Request//netalliance//CouponproductQueryRequest;
    
    $c = Factory::suning();
    $req = new CouponproductQueryRequest();
    $req->setPageNo("1");
    $req->setPageSize("10");
    $req->setPositionId("12");
    $resp = $c->execute($req);
    dd($resp);
  6. Initialize the Taobao SDK

    master

    Use Factory::taobao() to get a Taobao client instance. You can then create specific request objects (e.g., TbkItemInfoGetRequest) and execute them using the client's execute() method.

    <?php
    use NiuGengYun//EasyTBK//Factory;
    use NiuGengYun//EasyTBK//taobao//request//TbkItemInfoGetRequest;
    
    $client = Factory::taobao ();
    $req = new TbkItemInfoGetRequest();
    $req->setNumIids ($numIids);
    return $client->execute ($req);
  7. Initialize the Jingdong (JD) SDK

    master

    Use Factory::jingdong() to get a Jingdong client instance. Use request classes like JdUnionGoodsPromotiongoodsinfoQueryRequest to query product information by SKU IDs.

    <?php
    use NiuGengYun//EasyTBK//Factory;
    use NiuGengYun//EasyTBK//jingdong//request//JdUnionGoodsPromotiongoodsinfoQueryRequest;
    
    $jd = Factory::jingdong();
    $req = new JdUnionGoodsPromotiongoodsinfoQueryRequest();
    $req->setSkuIds("$itemid");
    return $jd->execute($req);
  8. Add a hotel room via taobao.hotel.room.add

    master

    The HotelRoomAddRequest class is used to construct a request for the TaoBao TOP API taobao.hotel.room.add. This API allows you to add or update hotel room availability, pricing, and policies.

    Key configuration areas include:

    • Identification: Requires hid (Hotel ID) and rid (Room Type ID).
    • Pricing & Inventory: Use roomQuotas to provide a JSON array of availability for up to 90 days. Each entry includes date (YYYY-MM-DD), price (in cents), and num (available quantity).
    • Policies: Define refundPolicyInfo as a JSON string to specify cancellation fees and timing.
    • Sales Control: Set startTime and endTime for daily sales, and gmtEffective/gmtDeadline to control the validity period of the rate plan.
    • Invoicing: Configure receiptType (A: Hotel Accommodation, B: Other) and associated descriptions.
    use NiuGengYun\EasyTBK\TaoBao\request\HotelRoomAddRequest;
    
    $request = new HotelRoomAddRequest();
    $request->setHid(12345); // Hotel ID
    $request->setRid(67890); // Room Type ID
    $request->setTitle("Deluxe Ocean View");
    $request->setRoomQuotas([
        ["date" => "2023-10-01", "price" => 10000, "num" => 5],
        ["date" => "2023-10-02", "price" => 12000, "num" => 3]
    ]);
    $request->setRefundPolicyInfo('{"cancelPolicyType":1}'); // Any cancellation is allowed
  9. Query Jingdong seckill goods with JdUnionGoodsSeckillQueryRequest

    master

    Use the JdUnionGoodsSeckillQueryRequest class to query Jingdong (JD) Union seckill (flash sale) goods. This request object maps to the jd.union.open.goods.seckill.query API method.

    Available Parameters

    ParameterTypeDescription
    secKillPriceFrommixedStart of the seckill price range (in Yuan).
    secKillPriceTomixedEnd of the seckill price range.
    skuIdsmixedA collection of SKU IDs (maximum length of 30).
    sortmixedSort order: desc (descending, default) or asc (ascending).
    isBeginSecKillmixedWhether to return seckill goods that haven't started yet. 1 to include, 0 to exclude.
    pageSizemixedNumber of items per page (maximum 30, default 30).
    pageIndexmixedThe page number to retrieve (default 1).
    cid1mixedLevel 1 category ID.
    cid2mixedLevel 2 category ID.
    cid3mixedLevel 3 category ID.
    sortNamemixedField to sort by. Allowed values: seckillPrice, commissionShare, inOrderCount30Days, inOrderComm30Days. (Default is comprehensive sorting).
    commissionShareFrommixedStart of the commission ratio range.
    commissionShareTomixedEnd of the commission ratio range.
    ownermixedOwner type: g for self-operated (自营), p for POP (platform).

    Usage Note

    When calling getParamJson(), the object filters out all null values and wraps the remaining parameters in a JSON object under the key goodsReq.

    use NiuGengYun\
    EasyTBK\
    JingDong\
    Request\
    JdUnionGoodsSeckillQueryRequest;
    
    $request = new JdUnionGoodsSeckillQueryRequest();
    $request->setSkuIds(['SKU123', 'SKU456']);
    $request->setPageSize(20);
    $request->setSort('asc');
    $request->setSortName('seckillPrice');
    
    // To get the JSON payload for the API call:
    $jsonPayload = $request->getParamJson();
  10. Configure the taobao.tbk.dg.material.optional request

    master

    The TbkDgMaterialOptionalRequest class is used to construct a request for the TaoBao TOP API taobao.tbk.dg.material.optional. This API allows you to search for DG (Direct Goods) materials with various filters such as category, price range, commission rates, and sorting options.

    To use this request object, instantiate it and use the provided setter methods to populate the required and optional parameters. Once configured, you can retrieve the parameters for the API call using getApiParas().

    Key Parameters

    ParameterTypeDescription
    adzone_idstringThe third part of mm_xxx_xxx_xxx. (Required)
    qstringSearch query term.
    catstringCategory IDs, separated by commas (max 10).
    page_nointPage number (default: 1).
    page_sizeintPage size, 1-100 (default: 20).
    sortstringSorting method: _des (descending), _asc (ascending), total_sales, tk_rate, tk_total_sales, tk_total_commi, or price.
    start_price / end_pricefloatPrice range limits in Yuan.
    start_tk_rate / end_tk_rateintTaoBao commission rate limits (e.g., 1234 represents 12.34%).
    platformintLink type: 1 for PC, 2 for Mobile (default: 1).
    is_tmallboolWhether to filter for Tmall products.
    need_free_shipmentboolWhether to filter for free shipping.
    material_idintOfficial material ID (default: 2836).
    use NiuGengYun\EasyTBK\TaoBao\request\TbkDgMaterialOptionalRequest;
    
    $request = new TbkDgMaterialOptionalRequest();
    $request->setAdzoneId('your_adzone_id');
    $request->setQ('search term');
    $request->setPageSize(50);
    $request->setSort('total_sales');
    $request->setStartTkRate(1000); // 10.00%
    
    // Retrieve parameters for the API call
    $params = $request->getApiParas();
  11. Use JdUnionPromotionByunionidGetRequest to get promotion links by unionId

    master

    The JdUnionPromotionByunionidGetRequest class is used to request promotion links from the Jingdong (JD) Union platform using a unionId. It implements RequestInterface and maps to the JD API method jd.union.open.promotion.byunionid.get.

    Parameters

    ParameterDescription
    subUnionIdSub-union ID (requires specific permissions from operations)
    materialIdPromotion material link (using the 微Q prefix is recommended for WeChat compatibility)
    positionIdPromotion position ID
    unionIdThe Union ID of the target promoter
    pidSub-account identity identifier (Format: sub_station_id_sub_station_website_id_sub_station_position_id)
    couponUrlCoupon redemption link (required when using coupon/product two-in-one features; materialId must be a product detail page link)
    chainTypeLink type: 1 (Long link), 2 (Short link), 3 (Long + Short link). Defaults to 2 (Short link)

    To use this request, instantiate the class, set the required parameters using the provided setter methods, and call getParamJson() to retrieve the JSON payload for the API call.

    use NiuGengYun\EasyTBK\JingDong\Request\JdUnionPromotionByunionidGetRequest;
    
    $request = new JdUnionPromotionByunionidGetRequest();
    $request->setUnionId('TARGET_UNION_ID');
    $request->setPid('SUB_ID_WEBSITE_ID_POSITION_ID');
    $request->setMaterialId('https://...');
    $request->setChainType(2); // Short link
    
    // Get the JSON payload for the API request
    $jsonPayload = $request->getParamJson();
  12. Use TbkScMaterialOptionalRequest for Taobao SC Material Selection

    master

    The TbkScMaterialOptionalRequest class is used to construct a request for the Taobao TOP API taobao.tbk.sc.material.optional. This API allows you to search for and filter Taobao promotional materials (SC materials) based on various criteria such as category, price range, commission rate, and more.

    To use this class, instantiate it and use the provided setter methods to populate the request parameters. Required fields include adzone_id and site_id.

    use NiuGengYun\EasyTBK\TaoBao\request\TbkScMaterialOptionalRequest;
    
    $request = new TbkScMaterialOptionalRequest();
    $request->setAdzoneId('YOUR_ADZONE_ID');
    $request->setSiteId('YOUR_SITE_ID');
    $request->setQ('search keyword');
    $request->setPageSize(50);
    $request->setSort('total_sales'); // Options: _des, _asc, total_sales, tk_rate, tk_total_sales, tk_total_commi, price
    
    // Validate the request
    $request->check();
    
    // Get parameters for the API call
    $params = $request->getApiParas();