Fix image upload structure for Miravia API compliance

🔧 Bug Fixes:
- Fixed product image structure to match Miravia API requirements
- Updated MiraviaProduct.php getData() method to wrap images in {"Image": [...]} format
- Updated MiraviaCombination.php getData() method to wrap SKU images properly
- Resolved error "[4224] The Main image of the product is required"

📋 Changes:
- Modified getData() methods to transform flat image arrays to nested structure
- Product images: images[] → Images: {"Image": [...]}
- SKU images: images[] → Images: {"Image": [...]}
- Maintains backward compatibility for empty image arrays

🎯 Impact:
- Product uploads will now pass Miravia's image validation
- Both product-level and SKU-level images properly formatted
- Complies with official Miravia API documentation structure

🤖 Generated with Claude Code (https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Miravia Connector Bot
2025-07-21 11:34:59 +02:00
parent dc50508c1c
commit 752600f337
79 changed files with 7970 additions and 36 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Aliexpress;
use Sweeper\DesignPattern\Traits\MultiPattern;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
abstract class Base
{
use MultiPattern;
/**
* 校验必填参数
* User: Sweeper
* Time: 2023/1/11 11:26
* @param array $params
* @param array $requiredFields
* @return bool
*/
public static function verifyParams(array $requiredFields = [], array $params = []): bool
{
foreach ($requiredFields as $requiredField) {
if (!isset($params[$requiredField])) {
throw new \InvalidArgumentException("字段[{$requiredField}]为必填参数");
}
}
return true;
}
/**
* 执行 API 请求
* User: Sweeper
* Time: 2023/4/4 16:38
* @param array $accountInfo 账号信息
* @param string $apiName API 名称
* @param array $paramVal 平台请求参数
* @param string $paramKey 平台请求参数 KEY
* @param array $requiredFields 接口必填字段,自动校验
* @param string $httpMethod 请求方式,默认 POST
* @param callable|null $callback 方法不兼容/不适用可以直接指定闭包处理
* @return mixed
*/
public static function executeRequest(array $accountInfo, string $apiName, array $paramVal = [], string $paramKey = 'param0', array $requiredFields = [], string $httpMethod = 'POST', callable $callback = null)
{
$simplify = isset($paramVal['simplify']) && $paramVal['simplify'] ? 'true' : 'false';// 精简返回
unset($paramVal['simplify']);
static::verifyParams($requiredFields, $paramVal);
try {
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest($apiName, $httpMethod);
// 执行回调函数并且返回
if ($callback && is_callable($callback)) {
return $callback($client, $request, $accountInfo);
}
$paramVal && $request->addApiParam($paramKey ?: 'param0', json_encode($paramVal));
$request->simplify = $simplify;
$request->addApiParam('simplify', $simplify);// 设置为精简返回
return $client->execute($request, $accountInfo['access_token']);
} catch (\Throwable $ex) {
throw new \RuntimeException("{$ex->getFile()}#{$ex->getLine()} ({$ex->getMessage()})");
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* 获取卖家地址信息
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/18 16:46
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\Address
*/
class Address extends Base
{
/**
* 获取卖家地址
* 目录API文档/AE-物流/获取卖家地址
* api: https://developers.aliexpress.com/doc.htm?docId=30133&docType=2
* api: https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193531.0.0.13b33b53KFl1Q9#/api?cid=20892&path=aliexpress.logistics.redefining.getlogisticsselleraddresses&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/18 16:46
* @param $accountInfo
* @return false
*/
public function getAddressInfo($accountInfo): bool
{
return static::executeRequest($accountInfo, 'aliexpress.logistics.redefining.getlogisticsselleraddresses', [], 'seller_address_query', [], 'POST', function($client, $request) use ($accountInfo) {
$request->addApiParam('seller_address_query', 'sender,pickup,refund');
return $client->execute($request, $accountInfo['access_token']);
});
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Attributes extends Base
{
/**
* 获取用户运费模板列表信息
* 目录API文档/AE-商品/AE-运费/用户运费模板列表信息
* api: https://developers.aliexpress.com/doc.htm?docId=30126&docType=2
* api: https://open.aliexpress.com/doc/api.htm#/api?cid=20900&path=aliexpress.freight.redefining.listfreighttemplate&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/18 17:42
* @param $accountInfo
* @return false
*/
public function getAttributesList($accountInfo): ?bool
{
return static::executeRequest($accountInfo, 'aliexpress.freight.redefining.listfreighttemplate');
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Category extends Base
{
/**
* 类目预测,可以筛选卖家已经通过准入申请的类目
* api: https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.postproduct.redefining.categoryforecast&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 14:41
* @param array $accountInfo
* @param array $params
* @return mixed
* @throws \Throwable
*/
public function categoryForecast(array $accountInfo, array $params = [])
{
$c = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('aliexpress.category.tree.list', 'GET');
if (!empty($params['channel_seller_id'])) {
$request->addApiParam('channel_seller_id', $params['channel_seller_id']);
}
if (!empty($params['only_with_permission'])) {
$request->addApiParam('only_with_permission', $params['only_with_permission']);
}
if (!empty($params['channel'])) {
$request->addApiParam('channel', $params['channel']);
}
if (!empty($params['category_id']) || $params['category_id'] === 0) {
$request->addApiParam('category_id', $params['category_id']);
}
$rs = $c->execute($request, $accountInfo['access_token']);
return $rs->cainiao_global_handover_content_query_response->result ?? $rs->result ?? $rs;
}
/**
* 根据发布类目id、父属性路径可选获取子属性信息只返回有权限品牌
* api: https://open.aliexpress.com/doc/api.htm#/api?cid=20897&path=aliexpress.category.redefining.getchildattributesresultbypostcateidandpath&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 14:42
* @param array $accountInfo
* @param array $params
* @return false|mixed
* @throws \Throwable
*/
public function getAttributesList(array $accountInfo, array $params = [])
{
$c = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('aliexpress.category.redefining.getchildattributesresultbypostcateidandpath', 'POST');
if (!empty($params['channel_seller_id'])) {
$request->addApiParam('channel_seller_id', $params['channel_seller_id']);
}
if (!empty($params['channel'])) {
$request->addApiParam('channel', $params['channel']);
}
if (!empty($params['locale'])) {
$request->addApiParam('locale', $params['locale']);
}
if (!empty($params['param1'])) {
$request->addApiParam('param1', $params['param1']);
}
if (!empty($params['param2'])) {
$request->addApiParam('param2', $params['param2']);
}
$rs = $c->execute($request, $accountInfo['access_token']);
return $rs->cainiao_global_handover_content_query_response->result ?? $rs->result ?? $rs;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2022/12/29 15:06
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Decrypt extends Base
{
/**
* 买家订单物流详情解密
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 14:46
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.6dc86f3dwkNxPS#/api?cid=20905&path=aliexpress.trade.seller.order.decrypt&methodType=GET/POST
* @param array $accountInfo
* @param $orderId
* @param $oaid
* @return mixed
* @throws \Throwable
*/
public function decrypt(array $accountInfo, $orderId, $oaid)
{
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('aliexpress.trade.seller.order.decrypt');
$request->addApiParam('orderId', $orderId);
$request->addApiParam('oaid', $oaid);
$response = $client->execute($request, $accountInfo['access_token']);
return $response->aliexpress_trade_seller_order_decrypt_response ?? $response;
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2022/12/27 9:46
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* AE-评价
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 14:49
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Evaluation
*/
class Evaluation extends Base
{
/**
* 查询待卖家评价的订单信息
* User: Sweeper
* Time: 2022/12/27 14:24
* @doc https://developers.aliexpress.com/doc.htm?docId=30247&docType=2
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20896&path=aliexpress.appraise.redefining.querysellerevaluationorderlist&methodType=GET/POST
* @param array $accountInfo 用户信息
* @param array $params 参数数组
* @return mixed
*/
public function querySellerEvaluationOrderList(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.appraise.redefining.querysellerevaluationorderlist', $params, 'query_d_t_o');
return $response->aliexpress_appraise_redefining_querysellerevaluationorderlist_response->result ?? $response->result ?? $response;
}
/**
* 卖家对未评价的订单进行评价
* User: Sweeper
* Time: 2022/12/27 14:24
* @doc https://developers.aliexpress.com/doc.htm?docId=30250&docType=2
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20896&path=aliexpress.appraise.redefining.savesellerfeedback&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function saveSellerFeedback(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.appraise.redefining.savesellerfeedback', $params, 'param1');
return $response->aliexpress_appraise_redefining_savesellerfeedback_response ?? $response;
}
/**
* 查询订单已生效的评价信息
* @doc https://developers.aliexpress.com/doc.htm?docId=35927&docType=2
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20896&path=aliexpress.evaluation.listorderevaluation.get&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
* @author linzj
* @date 2023-01-12 14:10
*/
public function getListOrderEvaluation(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.evaluation.listorderevaluation.get', $params, 'trade_evaluation_request');
return $response->aliexpress_evaluation_listorderevaluation_get_response->target_list ?? $response->target_list ?? $response;
}
/**
* 回复评价
* @doc https://developers.aliexpress.com/doc.htm?docId=35905&docType=2
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20896&path=aliexpress.evaluation.evaluation.reply&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
* @author linzj
* @date 2023-01-12 14:27
*/
public function replyEvaluation(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.evaluation.evaluation.reply', [], '', [], 'POST', function($client, $request) use ($params, $accountInfo) {
$request->addApiParam('child_order_id', $params['child_order_id']);
$request->addApiParam('parent_order_id', $params['parent_order_id']);
$request->addApiParam('text', $params['text']);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_evaluation_evaluation_reply_response->target ?? $response->target ?? $response;
}
}

View File

@@ -0,0 +1,186 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2023/4/4 15:52
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\HelperPhp\Traits\RedisCache;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* OpenAPI 统一跨境商家工作台-商家相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 14:56
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\GlobalSeller
*/
class GlobalSeller extends Base
{
use RedisCache;
/** @var string 全托管店铺类型 */
public const BUSINESS_TYPE_TRUSTEESHIP = 'ONE_STOP_SERVICE';
/** @var string 半托管店铺类型 */
public const BUSINESS_TYPE_POP_CHOICE = 'POP_CHOICE';
/**
* 获取商家账号列表
* User: Sweeper
* Time: 2023/4/4 17:16
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21387&path=global.seller.relation.query&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
* @response
* //{
* // "seller_relation_list": {// 渠道账号列表
* // "seller_relation": [
* // {
* // "channel_currency": "USD", // 渠道商品币种
* // "channel_shop_name": "DKSHETOY Official Store", // 渠道店铺名称
* // "business_type": "POP_CHOICE", // 业务类型: ONE_STOP_SERVICE 全托管店铺; POP_CHOICEPOP与半托管店铺
* // "channel_seller_id": 223525827, // 渠道sellerId
* // "channel": "AE_GLOBAL", // 渠道标识
* // "seller_id": 223525827, // 全球sellerId
* // },
* // ]
* // },
* // "global_currency": "USD", // 全球商品币种
* // "success": true,// 成功失败
* // "request_id": "2102e2b216953763075105129"
* //}
*/
public function relationQuery(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'global.seller.relation.query', $params, 'param', [], 'GET');
return $response->global_seller_relation_query_response->seller_relation_list ?? $response->seller_relation_list ?? $response;
}
/**
* 通过缓存获取 - 商家账号列表
* User: Sweeper
* Time: 2023/7/19 9:52
* @param array $accountInfo
* @param array $params
* @param bool $refresh
* @return array|mixed
*/
public function getSellerRelationListByCache(array $accountInfo, array $params = [], $refresh = false)
{
$unique = md5(json_encode($accountInfo));
$cacheKey = "middleware_cache:aliexpress:seller_relation_list:{$unique}";
[$cacheData, $errors] = $this->getCacheData($cacheKey, function($accountInfo, $params) {
$result = $this->relationQuery($accountInfo, $params);
$sellerRelationList = json_decode(json_encode($result), true);
$errorResponse = $sellerRelationList['error_response'] ?? [];
if ($errorResponse && isset($errorResponse['msg'])) {
throw new \LogicException($errorResponse['msg']);
}
return $sellerRelationList['seller_relation_list']['seller_relation'] ?? $sellerRelationList['seller_relation'] ?? [];
}, 86400, $refresh, $accountInfo, $params);
return $cacheData;
}
/**
* 获取全球卖家信息
* User: Sweeper
* Time: 2023/7/7 16:45
* @param array $accountInfo
* @param array $params
* @param string $key 要获取的 key
* @param string $channel 指定渠道名称
* @return array|mixed
*/
public function getGlobalSellerInfo(array $accountInfo, array $params = [], string $key = '', string $channel = 'ARISE_ES')
{
$sellerRelationList = $this->getSellerRelationListByCache($accountInfo, $params);
$globalSellerInfo = current($sellerRelationList);
foreach ($sellerRelationList as $sellerRelation) {
// 跳过全托管店铺渠道
if (!empty($sellerRelation['business_type']) && $sellerRelation['business_type'] === static::BUSINESS_TYPE_TRUSTEESHIP) {
continue;
}
// 指定要使用的渠道
if (!empty($channel)) {
if ($sellerRelation['channel'] === $channel) {
$globalSellerInfo = $sellerRelation;
break;
}
continue;// 没匹配中继续下一轮匹配
}
$globalSellerInfo = $sellerRelation;
break;
}
return $key ? ($globalSellerInfo[$key] ?? $globalSellerInfo) : $globalSellerInfo;
}
/**
* 获取全球卖家信息
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/20 17:14
* @param array $accountInfo
* @param array $params
* @param string $businessType
* @param string $channel
* @param array $where
* @return mixed
*/
public function getGlobalSellerInfoByWhere(array $accountInfo, array $params = [], string $businessType = self::BUSINESS_TYPE_TRUSTEESHIP, string $channel = 'AE_GLOBAL', array $where = [])
{
$sellerRelationList = $this->getSellerRelationListByCache($accountInfo, $params);
$globalSellerInfo = count($sellerRelationList) === 1 ? current($sellerRelationList) : [];
foreach ($sellerRelationList as $sellerRelation) {
// {
// "channel_currency": "USD", // 渠道商品币种
// "channel_shop_name": "DKSHETOY Official Store", // 渠道店铺名称
// "business_type": "POP_CHOICE", // 业务类型: ONE_STOP_SERVICE 全托管店铺; POP_CHOICEPOP与半托管店铺
// "channel_seller_id": 223525827, // 渠道sellerId
// "channel": "AE_GLOBAL", // 渠道标识
// "seller_id": 223525827, // 全球sellerId
// },
// 指定要使用的业务类型: ONE_STOP_SERVICE 全托管店铺; POP_CHOICEPOP与半托管店铺
if (!empty($businessType) && (empty($sellerRelation['business_type']) || $sellerRelation['business_type'] !== $businessType)) {
continue;// 没匹配中继续下一轮匹配
}
// 指定要使用的渠道标识
if (!empty($channel) && (empty($sellerRelation['channel']) || $sellerRelation['channel'] !== $channel)) {
continue;// 没匹配中继续下一轮匹配
}
foreach ($where as $key => $val) {
if (!isset($sellerRelation[$key]) || $sellerRelation[$key] !== $val) {
break 2;
}
}
$globalSellerInfo = $sellerRelation;
}
return $globalSellerInfo ?: $sellerRelationList;
}
/**
* 商家半托管基本信息查询
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:09
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21439&path=aliexpress.pop.choice.info.query&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getChoiceInfo(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.pop.choice.info.query', $params, 'param', [], 'GET');
return $response->aliexpress_pop_choice_info_query_response->result ?? $response->result ?? $response;
}
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2022/12/27 9:46
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* OpenAPI 物流相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 15:15
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Logistics
*/
class Logistics extends Base
{
/**
* 创建子交易单线上物流订单
* User: Sweeper
* Time: 2023/1/11 10:02
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20892&path=aliexpress.logistics.order.createorder&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function createOrder(array $accountInfo, array $params = [])
{
static::verifyParams(['trade_order_from', 'trade_order_id', 'declare_product_d_t_os', 'warehouse_carrier_service', 'address_d_t_os'], $params);
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('aliexpress.logistics.order.createorder');
// 必填参数
$request->addApiParam('trade_order_from', $params['trade_order_from']);
$request->addApiParam('trade_order_id', $params['trade_order_id']);
$request->addApiParam('declare_product_d_t_os', $params['declare_product_d_t_os']);
$request->addApiParam('warehouse_carrier_service', $params['warehouse_carrier_service']);
$request->addApiParam('address_d_t_os', $params['address_d_t_os']);
// 条件非必填
isset($params['domestic_logistics_company']) && $request->addApiParam('domestic_logistics_company', $params['domestic_logistics_company']);
isset($params['domestic_logistics_company_id']) && $request->addApiParam('domestic_logistics_company_id', $params['domestic_logistics_company_id']);
isset($params['domestic_tracking_no']) && $request->addApiParam('domestic_tracking_no', $params['domestic_tracking_no']);
// 非必填参数
isset($params['is_agree_upgrade_reverse_parcel_insure']) && $request->addApiParam('is_agree_upgrade_reverse_parcel_insure', $params['is_agree_upgrade_reverse_parcel_insure']);
isset($params['oaid']) && $request->addApiParam('oaid', $params['oaid']);
isset($params['pickup_type']) && $request->addApiParam('pickup_type', $params['pickup_type']);
isset($params['package_num']) && $request->addApiParam('package_num', $params['package_num']);
isset($params['undeliverable_decision']) && $request->addApiParam('undeliverable_decision', $params['undeliverable_decision']);
isset($params['invoice_number']) && $request->addApiParam('invoice_number', $params['invoice_number']);
isset($params['top_user_key']) && $request->addApiParam('top_user_key', $params['top_user_key']);
isset($params['insurance_coverage']) && $request->addApiParam('insurance_coverage', $params['insurance_coverage']);
$response = $client->execute($request, $accountInfo['access_token']);
return $response->aliexpress_logistics_order_createorder_response->result ?? $response->result ?? $response;
}
/**
* 查询物流订单信息(推荐)
* 目录API文档/AE物流/查询物流订单信息(推荐)
* api: https://open.aliexpress.com/doc/api.htm#/api?cid=20892&path=aliexpress.logistics.querylogisticsorderdetail&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:01
* @param array $accountInfo
* @param array $params
* @return mixed
* @throws \Throwable
*/
public function getLogisticsOrderDetail(array $accountInfo, array $params = [])
{
// 参数验证和组装 交易订单号
if (empty($params['trade_order_id'])) {
throw new \InvalidArgumentException('参数trade_order_id必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'aliexpress.logistics.querylogisticsorderdetail', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
$request->addApiParam('trade_order_id', $params['trade_order_id']);
if (!empty($params['current_page'])) {
$request->addApiParam('current_page', $params['current_page']);
} //当前页
if (!empty($params['domestic_logistics_num'])) {
$request->addApiParam('domestic_logistics_num', $params['domestic_logistics_num']);
} //国内运单号
if (!empty($params['gmt_create_end_str'])) {
$request->addApiParam('gmt_create_end_str', $params['gmt_create_end_str']);
} //起始创建时间
if (!empty($params['gmt_create_start_str'])) {
$request->addApiParam('gmt_create_start_str', $params['gmt_create_start_str']);
} //截止创建时间
if (!empty($params['international_logistics_num'])) {
$request->addApiParam('international_logistics_num', $params['international_logistics_num']);
} //国际运单号
if (!empty($params['logistics_status'])) {
$request->addApiParam('logistics_status', $params['logistics_status']);
} //订单状态
if (!empty($params['page_size'])) {
$request->addApiParam('page_size', $params['page_size']);
} //页面大小
if (!empty($params['warehouse_carrier_service'])) {
$request->addApiParam('warehouse_carrier_service', $params['warehouse_carrier_service']);
} //物流服务编码
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_logistics_querylogisticsorderdetail_response->result ?? $rs->result ?? $rs;
}
/**
* 查询仓发物流订单信息
* 目录API文档/AE物流/查询仓发物流订单信息
* api: https://open.aliexpress.com/doc/api.htm#/api?cid=20892&path=aliexpress.logistics.warehouse.querydetail&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return false || object
*/
public function getLogisticsWarehouseQueryDetail(array $accountInfo, array $params = [])
{
// 参数验证和组装 交易订单号
if (empty($params['trade_order_id'])) {
throw new \InvalidArgumentException('参数trade_order_id必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'aliexpress.logistics.warehouse.querydetail', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
$request->addApiParam('trade_order_id', $params['trade_order_id']);
if (!empty($params['consign_type'])) {
$request->addApiParam('consign_type', $params['consign_type']);
} //仓发订单类型 DOMESTIC 优选仓
if (!empty($params['current_page'])) {
$request->addApiParam('current_page', $params['current_page']);
} //当前页
if (!empty($params['domestic_logistics_num'])) {
$request->addApiParam('domestic_logistics_num', $params['domestic_logistics_num']);
} //国内运单号
if (!empty($params['gmt_create_end_str'])) {
$request->addApiParam('gmt_create_end_str', $params['gmt_create_end_str']);
} //起始创建时间
if (!empty($params['gmt_create_start_str'])) {
$request->addApiParam('gmt_create_start_str', $params['gmt_create_start_str']);
} //截止创建时间
if (!empty($params['international_logistics_num'])) {
$request->addApiParam('international_logistics_num', $params['international_logistics_num']);
} //国际运单号
if (!empty($params['logistics_status'])) {
$request->addApiParam('logistics_status', $params['logistics_status']);
} //订单状态
if (!empty($params['page_size'])) {
$request->addApiParam('page_size', $params['page_size']);
} //页面大小
if (!empty($params['warehouse_carrier_service'])) {
$request->addApiParam('warehouse_carrier_service', $params['warehouse_carrier_service']);
} //物流服务编码
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_logistics_warehouse_querydetail_response->return_result ?? $rs->return_result ?? $rs;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2023/4/4 15:52
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* OpenAPI AE-商家相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 15:20
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Merchant
*/
class Merchant extends Base
{
/**
* 商家地址列表查询
* User: Sweeper
* Time: 2023/4/4 17:16
* channel_seller_id Number 请输入全托管店铺的id。 渠道seller id 可以在这个API中查询global.seller.relation.query 请使用 business_type = ONE_STOP_SERVICE 的全托管店铺 channel_seller_id
* address_types String[] 地址类型SALESRETURN退货地址WAREHOUSE发货地址
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20895&path=aliexpress.merchant.Address.list&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function merchantAddressList(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.merchant.Address.list', $params, 'param', ['channel_seller_id', 'address_types']);
return $response->aliexpress_merchant_Address_list_response->result ?? $response->result ?? $response;
}
/**
* 查询卖家资料,如刊登数量
* api: https://open.aliexpress.com/doc/api.htm#/api?cid=20895&path=aliexpress.merchant.profile.get&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:27
* @param array $accountInfo
* @return mixed
*/
public function getMerchantProfile(array $accountInfo)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.merchant.profile.get');
return $rs->aliexpress_merchant_profile_get_response->profile ?? $rs->profile ?? $rs;
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2022/12/27 9:46
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
use function GuzzleHttp\json_encode;
/**
* OpenAPI 订单相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 15:21
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Order
*/
class Order extends Base
{
/**
* 订单收货信息查询
* User: Sweeper
* Time: 2023/1/11 10:06
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.6dc86f3dAv7fsz#/api?cid=20905&path=aliexpress.trade.redefining.findorderreceiptinfo&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function findOrderReceiptInfo(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.trade.redefining.findorderreceiptinfo', $params, 'param1');
return $response->aliexpress_trade_redefining_findorderreceiptinfo_response->result ?? $response->result ?? $response;
}
/**
* 获取订单列表
* User: Sweeper
* Time: 2023/2/24 10:19
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.6dc86f3dAv7fsz#/api?cid=20905&path=aliexpress.trade.seller.orderlist.get&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getOrderList(array $accountInfo, array $params = [])
{
static::verifyParams(['current_page', 'page_size'], $params);
$response = static::executeRequest($accountInfo, 'aliexpress.trade.seller.orderlist.get', $params, 'param_aeop_order_query');
return $response->aliexpress_trade_seller_orderlist_get_response ?? $response->result ?? $response;
}
/**
* 订单列表简化查询
* User: Sweeper
* Time: 2023/2/24 10:22
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.6dc86f3dAv7fsz#/api?cid=20905&path=aliexpress.trade.redefining.findorderlistsimplequery&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function findOrderListSimpleQuery(array $accountInfo, array $params = [])
{
static::verifyParams(['page', 'page_size'], $params);
$response = static::executeRequest($accountInfo, 'aliexpress.trade.redefining.findorderlistsimplequery', $params, 'param1');
return $response->aliexpress_trade_redefining_findorderlistsimplequery_response ?? $response->result ?? $response;
}
/**
* 新版交易订单详情查询
* User: Sweeper
* Time: 2023/1/11 10:09
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.6dc86f3dAv7fsz#/api?cid=20905&path=aliexpress.trade.new.redefining.findorderbyid&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function findOrderById(array $accountInfo, array $params = [])
{
static::verifyParams(['order_id'], $params);
$response = static::executeRequest($accountInfo, 'aliexpress.trade.new.redefining.findorderbyid', $params, 'param1');
return $response->aliexpress_trade_new_redefining_findorderbyid_response ?? $response->result ?? $response;
}
/**
* 卖家同意取消订单
* User: Sweeper
* Time: 2023/4/20 11:09
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20905&path=aliexpress.trade.seller.order.acceptcancel&methodType=GET/POST
* @param array $accountInfo
* @param array $params [buyer_login_id: String, order_id: Number]
* @return mixed
*/
public function acceptCancelOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.trade.seller.order.acceptcancel', $params, 'param_order_cancel_request');
return $response->aliexpress_trade_seller_order_acceptcancel_response ?? $response->result ?? $response;
}
/**
* 卖家拒绝取消订单
* User: Sweeper
* Time: 2023/4/20 11:10
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=20905&path=aliexpress.trade.seller.order.refusecancel&methodType=GET/POST
* @param array $accountInfo
* @param array $params ['buyer_login_id','memo','order_id']
* @return mixed
*/
public function refuseCancelOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.trade.seller.order.refusecancel', $params, 'param_order_cancel_request', ['buyer_login_id', 'memo', 'order_id']);
return $response->aliexpress_trade_seller_order_refusecancel_response ?? $response->result ?? $response;
}
}

View File

@@ -0,0 +1,264 @@
<?php
/**
* Created by PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 9:51
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Product extends Base
{
/**
* 商品查询新接口
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:07
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.offer.product.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getProductDetail(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.offer.product.query', $params, 'product_id', ['product_id'], 'POST', function($client, $request) use ($accountInfo, $params) {
$request->addApiParam('product_id', $params['product_id']);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_offer_product_query_response->result ?? $response->result ?? $response;
}
/**
* 查询半托管已加入/待加入/待预存商品列表
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:10
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21439&path=aliexpress.pop.choice.products.list&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getPopChoiceProductList(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.pop.choice.products.list', $params, 'param', [], 'GET');
return $response->aliexpress_pop_choice_products_list_response->result ?? $response->result ?? $response;
}
/**
* 半托管商品详情查询
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:10
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21439&path=aliexpress.pop.choice.product.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getPopChoiceProductDetail(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.pop.choice.product.query', $params, 'product_id', ['product_id'], 'POST', function($client, $request) use ($accountInfo, $params) {
$request->addApiParam('product_id', $params['product_id']);
$request->addApiParam('language', 'zh_CN');
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_pop_choice_product_query_response->result ?? $response->result ?? $response;
}
/**
* AE-全托管-商品列表查询
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:10
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21403&path=aliexpress.choice.products.list&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getChoiceProductList(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.choice.products.list', $params, 'param', ['channel_seller_id', 'channel', 'search_condition_do'], 'POST',
function($client, $request) use ($accountInfo, $params) {
$request->addApiParam('channel_seller_id', $params['channel_seller_id']);
$request->addApiParam('channel', $params['channel']);
$request->addApiParam('page_size', $params['page_size'] ?? 20);
$request->addApiParam('current_page', $params['current_page'] ?? 1);
$request->addApiParam('search_condition_do', json_encode($params['search_condition_do']));
$request->addApiParam('version', $params['version'] ?? 1);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_choice_products_list_response->result ?? $response->result ?? $response;
}
/**
* AE-全托管-全托管店铺-查询单个商品详情
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:10
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21403&path=aliexpress.choice.product.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getChoiceProductDetail(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.choice.product.query', $params, 'param', ['channel_seller_id', 'channel', 'product_id'], 'POST',
function($client, $request) use ($accountInfo, $params) {
$request->addApiParam('product_id', $params['product_id']);
$request->addApiParam('channel_seller_id', $params['channel_seller_id']);
$request->addApiParam('channel', $params['channel']);
$request->addApiParam('version', $params['version'] ?? 1);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_choice_product_query_response->result ?? $response->result ?? $response;
}
/**
* AE-全托管-按照商家查询仓库编码
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/26 10:30
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getChoiceProductWarehouseList(array $accountInfo, array $params)
{
$response = static::executeRequest($accountInfo, 'aliexpress.choice.product.warehouse.list', $params, 'param', ['channel_seller_id', 'channel'], 'POST',
function($client, $request) use ($accountInfo, $params) {
$request->addApiParam('product_id', $params['product_id']);
$request->addApiParam('channel_seller_id', $params['channel_seller_id']);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_choice_product_query_response->result ?? $response->result ?? $response;
}
/**
* 商品删除接口
* api: https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.offer.product.delete&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:03
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function deleteProduct(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.offer.product.delete', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
if (!empty($params['product_id'])) {
$request->addApiParam('product_id', $params['product_id']);
}
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_offer_product_delete_response->product_id ?? $rs->product_id ?? $rs;
}
/**
* 商品列表查询接口
* api: https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.postproduct.redefining.findproductinfolistquery&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:05
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getProductsList(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.postproduct.redefining.findproductinfolistquery', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
$request->addApiParam('aeop_a_e_product_list_query', $params['aeop_a_e_product_list_query']);
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_postproduct_redefining_findproductinfolistquery_response->result ?? $rs->result ?? $rs;
}
/**
* 分页查询待优化商品列表
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:08
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.product.diagnosis.pageQueryProblem&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getProductProblemList(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.product.diagnosis.pageQueryProblem', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
isset($params['operate_status']) && $request->addApiParam('operate_status', $params['operate_status']);
isset($params['problem_type_list']) && $request->addApiParam('problem_type_list', $params['problem_type_list']);
isset($params['page_size']) && $request->addApiParam('page_size', $params['page_size']);
isset($params['current_page']) && $request->addApiParam('current_page', $params['current_page']);
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_product_diagnosis_pageQueryProblem_response ?? $rs;
}
/**
* 查询商家下待优化的商品问题类型列表
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:12
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.product.diagnosis.queryProblem&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getProductProblemTypeList(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.product.diagnosis.queryProblem', [], '');
return $rs->aliexpress_product_diagnosis_queryProblem_response->product_problem_type_list ?? $rs->product_problem_type_list ?? $rs;
}
/**
* 商品新的编辑接口
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:14
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.offer.product.edit&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function editProductNew(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.offer.product.edit', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
$request->addApiParam('aeop_a_e_product', $params['aeop_a_e_product']);
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_offer_product_edit_response->result ?? $rs->result ?? $rs;
}
/**
* 商品发布新接口
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:15
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20904&path=aliexpress.offer.product.post&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function uploadListing(array $accountInfo, array $params)
{
$rs = static::executeRequest($accountInfo, 'aliexpress.offer.product.post', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
$request->addApiParam('aeop_a_e_product', $params['aeop_a_e_product']);
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->aliexpress_offer_product_edit_response->result ?? $rs->result ?? $rs;
}
}

View File

@@ -0,0 +1,2 @@
## API 文档
https://console-docs.apipost.cn/preview/a8b356c4e7ad1bd6/8b42e455151dbc70 pwd444421

View File

@@ -0,0 +1,244 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Ship extends Base
{
/**
* 组包提交
* 目录API文档/菜鸟国际出口/提供给ISV通过该接口提交发布交接单
* api:https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21215&path=cainiao.global.handover.commit&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:22
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function commitBigBag(array $accountInfo, array $params = [])
{
if (empty($params['pickup_info'])) {
throw new \InvalidArgumentException('参数pickup_info必填且不能为空');
}
if (empty($params['user_info'])) {
throw new \InvalidArgumentException('参数user_info必填且不能为空');
}
if (empty($params['client'])) {
throw new \InvalidArgumentException('参数client必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'cainiao.global.handover.commit', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
if (!empty($params['seller_parcel_order_list'])) {
if (is_array($params['seller_parcel_order_list']) || is_object($params['seller_parcel_order_list'])) {
$request->addApiParam('seller_parcel_order_list', json_encode($params['seller_parcel_order_list']));
} else {
$request->addApiParam('seller_parcel_order_list', $params['seller_parcel_order_list']);
}
}
if (is_array($params['pickup_info']) || is_object($params['pickup_info'])) {
$request->addApiParam('pickup_info', json_encode($params['pickup_info']));
} else {
$request->addApiParam('pickup_info', $params['pickup_info']);
}
if (!empty($params['order_code_list'])) {
if (is_array($params['order_code_list']) || is_object($params['order_code_list'])) {
$request->addApiParam('order_code_list', json_encode($params['order_code_list']));
} else {
$request->addApiParam('order_code_list', $params['order_code_list']);
}
}
if (!empty($params['weight'])) {
$request->addApiParam('weight', $params['weight']);
}
if (!empty($params['handover_order_id'])) {
$request->addApiParam('handover_order_id', $params['handover_order_id']);
}
if (!empty($params['remark'])) {
$request->addApiParam('remark', $params['remark']);
}
if (!empty($params['return_info'])) {
if (is_array($params['return_info']) || is_object($params['return_info'])) {
$request->addApiParam('return_info', json_encode($params['return_info']));
} else {
$request->addApiParam('return_info', $params['return_info']);
}
}
if (is_array($params['user_info']) || is_object($params['user_info'])) {
$request->addApiParam('user_info', json_encode($params['user_info']));
} else {
$request->addApiParam('user_info', $params['user_info']);
}
if (!empty($params['weight_unit'])) {
$request->addApiParam('weight_unit', $params['weight_unit']);
}
if (!empty($params['skip_invalid_parcel'])) {
$request->addApiParam('skip_invalid_parcel', $params['skip_invalid_parcel']);
} else {
$request->addApiParam('skip_invalid_parcel', 'true');
}
if (!empty($params['type'])) {
$request->addApiParam('type', $params['type']);
}
$request->addApiParam('client', $params['client']);
if (!empty($params['locale'])) {
$request->addApiParam('locale', $params['locale']);
}
if (!empty($params['features'])) {
if (is_array($params['features']) || is_object($params['features'])) {
$request->addApiParam('features', json_encode($params['features']));
} else {
$request->addApiParam('features', $params['features']);
}
}
if (!empty($params['appointment_type'])) {
$request->addApiParam('appointment_type', $params['appointment_type']);
}
if (!empty($params['domestic_tracking_no'])) {
$request->addApiParam('domestic_tracking_no', $params['domestic_tracking_no']);
}
if (!empty($params['domestic_logistics_company_id'])) {
$request->addApiParam('domestic_logistics_company_id', $params['domestic_logistics_company_id']);
}
if (!empty($params['domestic_logistics_company'])) {
$request->addApiParam('domestic_logistics_company', $params['domestic_logistics_company']);
}
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->cainiao_global_handover_commit_response->result ?? $rs->result ?? $rs;
}
/**
* 批次追加大包
* 目录API文档/菜鸟国际出口/批次追加大包
* api:https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21215&path=cainiao.global.handover.content.subbag.add&methodType=POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:19
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function addSubBag(array $accountInfo, array $params = [])
{
// 参数验证和组装
if (empty($params['user_info'])) {
throw new \InvalidArgumentException('参数user_info必填且不能为空');
}
if (empty($params['add_subbag_quantity'])) {
throw new \InvalidArgumentException('参数order_code必填且不能为空');
}
if (empty($params['order_code'])) {
throw new \InvalidArgumentException('参数order_code必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'cainiao.global.handover.content.subbag.add', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
if (is_array($params['user_info']) || is_object($params['user_info'])) {
$request->addApiParam('user_info', json_encode($params['user_info']));
} else {
$request->addApiParam('user_info', $params['user_info']);
}
$request->addApiParam('order_code', $params['order_code']);
$request->addApiParam('add_subbag_quantity', $params['add_subbag_quantity']);
if (empty($params['locale'])) {
$request->addApiParam('locale', 'zh_CN');
} else {
$request->addApiParam('locale', $params['locale']);
}
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->cainiao_global_handover_content_subbag_add_response->result ?? $rs->result ?? $rs;
}
/**
* 获取大包面单
* 目录API文档/菜鸟国际出口/返回指定大包面单的PDF文件数据
* api:https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21215&path=cainiao.global.handover.pdf.get&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:14
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getBigBagPdf(array $accountInfo, array $params = [])
{
// 参数验证和组装
if (empty($params['user_info'])) {
throw new \InvalidArgumentException('参数user_info必填且不能为空');
}
if (empty($params['client'])) {
throw new \InvalidArgumentException('参数client必填且不能为空');
}
if (empty($params['handover_content_id'])) {
throw new \InvalidArgumentException('参数handover_content_id必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'cainiao.global.handover.pdf.get', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
if (is_array($params['user_info']) || is_object($params['user_info'])) {
$request->addApiParam('user_info', json_encode($params['user_info']));
} else {
$request->addApiParam('user_info', $params['user_info']);
}
$request->addApiParam('client', $params['client']);
if (!empty($params['locale'])) {
$request->addApiParam('locale', $params['locale']);
}
$request->addApiParam('handover_content_id', $params['handover_content_id']);
if (!empty($params['type'])) {
$request->addApiParam('type', $params['type']);
}
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->cainiao_global_handover_pdf_get_response->result ?? $rs->result ?? $rs;
}
/**
* 查询大包详情
* 目录API文档/菜鸟国际出口/查询大包详情
* api: https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21215&path=cainiao.global.handover.pdf.get&methodType=GET/POST
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:12
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getBigBagInfo(array $accountInfo, array $params = [])
{
if (empty($params['client'])) {
throw new \InvalidArgumentException('参数client必填且不能为空');
}
$rs = static::executeRequest($accountInfo, 'cainiao.global.handover.content.query', [], '', [], 'POST', function($client, $request, $accountInfo) use ($params) {
// 参数验证和组装
if (!empty($params['user_info'])) {
if (is_array($params['user_info']) || is_object($params['user_info'])) {
$request->addApiParam('user_info', json_encode($params['user_info']));
} else {
$request->addApiParam('user_info', $params['user_info']);
}
}
if (!empty($params['order_code'])) {
$request->addApiParam('order_code', $params['order_code']);
}
if (!empty($params['tracking_number'])) {
$request->addApiParam('tracking_number', $params['tracking_number']);
}
$request->addApiParam('client', $params['client']);
if (!empty($params['locale'])) {
$request->addApiParam('locale', $params['locale']);
}
return $client->execute($request, $accountInfo['access_token']);
});
return $rs->cainiao_global_handover_content_query_response->result ?? $rs->result ?? $rs;
}
}

View File

@@ -0,0 +1,250 @@
<?php
/**
* Created by PhpStorm.
* User: Sweeper
* Time: 2023/4/4 15:52
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* OpenAPI AE-供应链相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 15:22
* @Package \Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Supply
*/
class Supply extends Base
{
/** 行业账套编码[业务租户Id全托管场景请填写5110000] AER 221000AEG 288000 aechoice 5110000 */
/** @var int 行业账套编码[业务租户Id] AER */
public const BIZ_TYPE_AER = 221000;
/** @var int 行业账套编码[业务租户Id] AEG */
public const BIZ_TYPE_AEG = 288000;
/** @var int 行业账套编码[业务租户Id] aechoice */
public const BIZ_TYPE_AE_CHOICE = 5110000;
/** 单据类型 10:普通仓发 50:JIT */
/** @var int 订单类型 - 普通仓发 */
public const ORDER_TYPE_NORMAL = 10;
/** @var int 订单类型 - JIT */
public const ORDER_TYPE_JIT = 50;
/** 单据状态 10:待确认 15:已确认 17:待发货 20:待收货 21:已到仓 30:部分收货 40:收货完成 -99:已取消,不传则返回所有状态的采购单 */
/** biz_type Number 是 业务租户Id全托管场景请填写5110000 */
/** channel_user_id Number 是 渠道seller id 可以在这个API中查询global.seller.relation.query 请使用 business_type = ONE_STOP_SERVICE 的全托管店铺 channel_seller_id */
/**
* 采购单分页查询
* User: Sweeper
* Time: 2023/4/4 15:52
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.pageQuery&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function pageQuery(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.pageQuery', $params, 'param0', ['order_type', 'biz_type', 'channel_user_id']);
return $response->aliexpress_ascp_po_pageQuery_response->result ?? $response->result ?? $response;
}
/**
* 采购单确认
* User: Sweeper
* Time: 2023/4/4 16:17
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.confirmPurchaseOrder&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function confirmPurchaseOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.confirmPurchaseOrder', $params, 'param0', ['purchase_order_no', 'biz_type', 'all_quantity_confirm', 'channel_user_id']);
return $response->aliexpress_ascp_po_confirmPurchaseOrder_response->result ?? $response->result ?? $response;
}
/**
* 创建揽收单
* User: Sweeper
* Time: 2023/4/4 16:50
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.createPickupOrder&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function createPickupOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.createPickupOrder', $params, 'param0', [
'order_type',
'estimated_pickup_date',
'biz_type',
'estimated_weight',
'estimated_box_number',
'contact_info_dto',
'estimated_volume',
'order_no_list',
'channel_user_id',
]);
return $response->aliexpress_ascp_po_createPickupOrder_response->result ?? $response->result ?? $response;
}
/**
* 查询揽收单
* User: Sweeper
* Time: 2023/4/4 16:54
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.queryPickupOrder&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function queryPickupOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.queryPickupOrder', $params, 'param0', ['pickup_order_number', 'biz_type', 'channel_user_id']);
return $response->aliexpress_ascp_po_queryPickupOrder_response->result ?? $response->result ?? $response;
}
/**
* 打印箱唛
* User: Sweeper
* Time: 2023/4/4 16:58
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.query.createShippingMarkPdf&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function createShippingMarkPdf(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.query.createShippingMarkPdf', $params, 'param0', ['biz_type', 'channel_user_id', 'purchase_order_no']);
return $response->aliexpress_ascp_po_query_createShippingMarkPdf_response->result ?? $response->result ?? $response;
}
/**
* 打印货品标签
* User: Sweeper
* Time: 2023/4/4 16:59
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.createScItemBarcodePdf&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function createScItemBarcodePdf(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.createScItemBarcodePdf', $params, 'param0', ['purchase_order_no', 'biz_type', 'channel_user_id']);
return $response->aliexpress_ascp_po_createScItemBarcodePdf_response->result ?? $response->result ?? $response;
}
/**
* 打印揽收面单
* User: Sweeper
* Time: 2023/4/4 17:01
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.createPickupShippingMarkPdf&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function createPickupShippingMarkPdf(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.createPickupShippingMarkPdf', $params, 'param0', ['pickup_order_number', 'biz_type', 'channel_user_id']);
return $response->aliexpress_ascp_po_createScItemBarcodePdf_response->result ?? $response->result ?? $response;
}
/**
* AliExpress采购单明细查询API
* User: Sweeper
* Time: 2023/4/4 17:18
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.item.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function purchaseOrderDetail(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.item.query', $params, 'purchase_order_item_query', ['biz_type', 'purchase_order_no']);
return $response->aliexpress_ascp_po_item_query_response->result ?? $response->result ?? $response;
}
/**
* AliExpress采购单查询API
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/21 14:24
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function purchaseOrderQuery(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.query', $params, 'purchase_order_query', ['biz_type', 'purchase_order_no']);
return $response->aliexpress_ascp_po_query_response->result ?? $response->result ?? $response;
}
/**
* 采购单货品详情
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/20 16:58
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.item.detail&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function purchaseOrderItemDetail(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.item.detail', $params, 'param0', ['sc_item_id', 'channel', 'channel_seller_id'], 'GET');
return $response->aliexpress_ascp_item_detail_response->result ?? $response->result ?? $response;
}
/**
* AliExpress货品查询API
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/21 13:49
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.item.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function purchaseOrderItemQuery(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.item.query', $params, 'sc_item_query', ['biz_type']);
return $response->aliexpress_ascp_item_query_response->result ?? $response->result ?? $response;
}
/**
* 取消揽收单
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2023/9/21 13:49
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=21022&path=aliexpress.ascp.po.cancelPickupOrder&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function purchaseCancelPickOrder(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'aliexpress.ascp.po.cancelPickupOrder', $params, 'param0', ['pickup_order_number','biz_type','channel_user_id','cancel_reason']);
return $response->aliexpress_ascp_po_cancelPickupOrder_response->result ?? $response->result ?? $response;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: czq
* Time: 2023/1/17 15:06
*/
namespace Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
class Trade extends Base
{
/**
* 延长买家收货时间
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 16:55
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=20905&path=aliexpress.trade.redefining.extendsbuyeracceptgoodstime&methodType=GET/POST
* @param array $accountInfo
* @param $orderId
* @param $day
* @return mixed
*/
public function extendsBuyerAcceptGoodsTime(array $accountInfo, $orderId, $day)
{
$response = static::executeRequest($accountInfo, 'aliexpress.trade.redefining.extendsbuyeracceptgoodstime', [], '', [], 'POST', function($client, $request, $accountInfo) use ($orderId, $day) {
$request->addApiParam('param0', $orderId);
$request->addApiParam('param1', $day);
return $client->execute($request, $accountInfo['access_token']);
});
return $response->aliexpress_trade_redefining_extendsbuyeracceptgoodstime_response ?? $response;
}
}

View File

@@ -0,0 +1,142 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Mirakl;
use Mirakl\MMP\Shop\Request\Order\Document\DownloadOrdersDocumentsRequest;
use Mirakl\MMP\Shop\Request\Order\Document\GetOrderDocumentsRequest;
use Mirakl\MMP\Shop\Request\Order\Get\GetOrdersRequest;
use Mirakl\MMP\Shop\Request\Order\Tracking\UpdateOrderTrackingInfoRequest;
use Sweeper\GuzzleHttpRequest\Response;
/**
* Mirakl - Catch 订单相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:18
* @Package \Sweeper\PlatformMiddleware\Services\Mirakl\Order
*/
class Order extends Request
{
/**
* 获取订单列表
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:42
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR11
* @param array $params
* @return Response
*/
public function getOrders(array $params = []): Response
{
// Building request
$request = new GetOrdersRequest($params);
// Calling the API
// $response = $this->clientMMP()->run($request);
// $response = $this->clientMMP()->getOrders($request);
// $response = $this->clientMMP()->raw()->getOrders($request);
return $this->execute($this->clientMMP(), $request);
}
/**
* 接受或拒绝订单行
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:44
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR21
* @param string $orderId
* @param array $orderLines {'order_lines':[{'accepted':true,'id':'Order_00012-B-1'}]}
* @return Response
*/
public function acceptRefuseOrder(string $orderId, array $orderLines): Response
{
// return static::handleResponse($this->clientMMP()->run(new AcceptOrderRequest($orderId, $orderLines)));// 官方SDK调不通不知道错误信息只提示400
return static::put($this->buildRequestUri("orders/{$orderId}/accept"), $orderLines, static::buildHeaders($this->getConfig('api_key')));
}
/**
* 取消订单
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:45
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR29
* @param string $orderId
* @return Response
*/
public function cancelOrder(string $orderId): Response
{
// return static::handleResponse($this->clientMMP()->run(new CancelOrderRequest($orderId)));
return static::put($this->buildRequestUri("orders/{$orderId}/cancel"), [], static::buildHeaders($this->getConfig('api_key')));
}
/**
* 更新特定订单的承运商跟踪信息
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:45
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR23
* @param string $orderId
* @param array $trackingOrderInfo {'carrier_code':'UPS','carrier_name':'UPS','carrier_url':'https://ups.com','tracking_number':'5555'}
* @return Response
*/
public function updateOrderTrackingInfo(string $orderId, array $trackingOrderInfo): Response
{
return $this->execute($this->clientMMP(), new UpdateOrderTrackingInfoRequest($orderId, $trackingOrderInfo));
}
/**
* 获取订单文档
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:46
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR72
* @param array $orderIds
* @return Response
* @throws \Mirakl\Core\Exception\RequestValidationException
*/
public function getOrderDocuments(array $orderIds): Response
{
// Building request
$request = new GetOrderDocumentsRequest($orderIds);
// Calling the API
return $this->execute($this->clientMMP(), $request);
}
/**
* 下载订单文档
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:47
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR73
* @param array $orderIds
* @param bool $download
* @return Response
*/
public function downloadOrdersDocuments(array $orderIds, bool $download = false): Response
{
// Building request
$request = new DownloadOrdersDocumentsRequest();
$request->setOrderIds($orderIds);
$result = $this->clientMMP()->downloadOrdersDocuments($request);
if ($download) {
$result->download();
}
if (ob_get_length()) {
ob_clean();
}
$result->getFile()->rewind();
return Response::success('Success', [$result->getFile()->fpassthru()]);
}
/**
* 校验订单发货 Valid the shipment of the order
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:48
* @doc https://help.mirakl.net/help/api-doc/seller/mmp.html#OR24
* @param string $orderId
* @return Response
*/
public function shipOrder(string $orderId): Response
{
// return static::handleResponse($this->clientMMP()->run(new ShipOrderRequest($orderId)));
return static::put($this->buildRequestUri("orders/{$orderId}/ship"), [], static::buildHeaders($this->getConfig('api_key')));
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Mirakl;
use Mirakl\MMP\Shop\Request\Shipping\GetShippingCarriersRequest;
use Sweeper\GuzzleHttpRequest\Response;
/**
* Mirakl - Catch 平台配置相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:16
* @Package \Sweeper\PlatformMiddleware\Services\Mirakl\PlatformSetting
*/
class PlatformSetting extends Request
{
/**
* 列出所有承运商信息
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:17
* @param array $params
* @return Response
*/
public function carriers(array $params = []): Response
{
return $this->execute($this->clientMMP(), new GetShippingCarriersRequest($params));
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Mirakl;
use Mirakl\Core\Client\AbstractApiClient;
use Mirakl\Core\Request\AbstractRequest;
use Mirakl\MCI\Shop\Client\ShopApiClient as MCIShopApiClient;
use Mirakl\MCM\Shop\Client\ShopApiClient as MCMShopApiClient;
use Mirakl\MMP\Shop\Client\ShopApiClient as MMPShopApiClient;
use Sweeper\GuzzleHttpRequest\Response;
use Sweeper\HelperPhp\Tool\ClientRequest;
/**
* Mirakl - Catch - 请求处理
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:01
* @Package \Sweeper\PlatformMiddleware\Services\Mirakl\Request
*/
class Request extends ClientRequest
{
public const OPEN_API_URI = 'https://marketplace.catch.com.au/';
public const OPEN_API_URL = 'https://marketplace.catch.com.au/api/';
/** @var string */
public const TYPE_MCI = 'MCI';
/** @var string */
public const TYPE_MCM = 'MCM';
/** @var string Marketplace for Products Seller API */
public const TYPE_MMP = 'MMP';
/**
* 获取 API 服务URL
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @return string
*/
protected function getServerDomain(): string
{
return static::OPEN_API_URI;
}
/**
* 获取服务请求的路径
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @param string $path
* @return string
*/
protected function getServerPath(string $path): string
{
return $this->getVersion() ? "/api/{$this->getVersion()}/{$path}" : "/api/{$path}";
}
/**
* 实例化客户端
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @param string $type
* @return AbstractApiClient
*/
public function getClientByType(string $type = self::TYPE_MMP): AbstractApiClient
{
// Instantiating the Mirakl API Client
switch ($type) {
case static::TYPE_MCM:
$shopApiClient = $this->clientMCM();
break;
case static::TYPE_MCI:
$shopApiClient = $this->clientMCI();
break;
case static::TYPE_MMP:
default:
$shopApiClient = $this->clientMMP();
break;
}
return $shopApiClient;
}
/**
* MMP 客户端
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @return MMPShopApiClient
*/
public function clientMMP(): MMPShopApiClient
{
// Instantiating the Mirakl API Client
$shopApiClient = new MMPShopApiClient($this->getConfig('api_url'), $this->getConfig('api_key'), $this->getConfig('shop_id'));
return $shopApiClient->setOptions(['verify' => false, 'connect_timeout' => static::getConnectTimeout(), 'timeout' => static::getTimeout()]);
}
/**
* MCI 客户端
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @return MCIShopApiClient
*/
public function clientMCI(): MCIShopApiClient
{
// Instantiating the Mirakl API Client
$shopApiClient = new MCIShopApiClient($this->getConfig('api_url'), $this->getConfig('api_key'), $this->getConfig('shop_id'));
return $shopApiClient->setOptions(['verify' => false, 'connect_timeout' => static::getConnectTimeout(), 'timeout' => static::getTimeout()]);
}
/**
* MCM 客户端
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @return MCMShopApiClient
*/
public function clientMCM(): MCMShopApiClient
{
// Instantiating the Mirakl API Client
$shopApiClient = new MCMShopApiClient($this->getConfig('api_url'), $this->getConfig('api_key'), $this->getConfig('shop_id'));
return $shopApiClient->setOptions(['verify' => false, 'connect_timeout' => static::getConnectTimeout(), 'timeout' => static::getTimeout()]);
}
/**
* 执行请求 -> 解析响应
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:05
* @param AbstractApiClient $client
* @param AbstractRequest $request
* @return Response
*/
public function execute(AbstractApiClient $client, AbstractRequest $request): Response
{
/** @var \GuzzleHttp\Psr7\Response $result */
// Calling the API
// $response = $client->run($request);// $this->client()->getOrders($request); $this->client()->raw()->getOrders($request);
return $this->resolveResponse($client->run($request));// return json_decode($result->getBody()->getContents() ?? '', true) ?: [];
}
/**
* 构建头选项
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:07
* @param string $authorization
* @param array $options
* @return array
*/
protected static function buildHeaders(string $authorization, array $options = []): array
{
return array_replace([
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => $authorization,
'Accept' => "*/*",
],
'verify' => false,
'connect_timeout' => 10,
'timeout' => 60,
], $options);
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Miravia;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopClient;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\IopRequest;
use Sweeper\PlatformMiddleware\Sdk\AeSdk\UrlConstants;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* AliExpress - Miravia 账号/授权相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/15 15:17
* @Package \Sweeper\PlatformMiddleware\Services\Miravia\Account
*/
class Account extends Base
{
public const APP_KEY = '24800759';
public const APP_CALLBACK_URL = 'xxx';
/**
* 生成授权地址
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 14:47
* @doc https://open.aliexpress.com/doc/doc.htm?nodeId=27493&docId=118729#/?docId=989
* @param string $appKey
* @param string $appCallbackUrl
* @return string|string[]
*/
public function generateAuthUrl(string $appKey = self::APP_KEY, string $appCallbackUrl = self::APP_CALLBACK_URL)
{
$uri = 'https://api-sg.aliexpress.com/oauth/authorize?response_type=code&force_auth=true&redirect_uri={app_callback_url}&client_id={app_key}';
return str_replace(['{app_callback_url}', '{app_key}'], [$appCallbackUrl ?: static::APP_CALLBACK_URL, $appKey ?: static::APP_KEY], $uri);
}
/**
* 生成安全令牌
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 14:48
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=3&path=/auth/token/security/create&methodType=GET/POST
* @param array $accountInfo
* @param string $code
* @param string|null $uuid
* @return mixed
*/
public function generateSecurityToken(array $accountInfo, string $code, string $uuid = null)
{
try {
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('/auth/token/security/create');
$request->addApiParam('code', $code);
$uuid && $request->addApiParam('uuid', $uuid);
return $client->execute($request);
} catch (\Throwable $ex) {
throw new \RuntimeException("{$ex->getFile()}#{$ex->getLine()} ({$ex->getMessage()})");
}
}
/**
* 生成令牌
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 14:49
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=3&path=/auth/token/create&methodType=GET/POST
* @param array $accountInfo
* @param string $code
* @param $uuid
* @return mixed
*/
public function generateToken(array $accountInfo, string $code, $uuid = null)
{
try {
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('/auth/token/create');
$request->addApiParam('code', $code);
$uuid && $request->addApiParam('uuid', $uuid);
return $client->execute($request);
} catch (\Throwable $ex) {
throw new \RuntimeException("{$ex->getFile()}#{$ex->getLine()} ({$ex->getMessage()})");
}
}
/**
* 刷新安全令牌
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 14:50
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=3&path=/auth/token/security/refresh&methodType=GET/POST
* @param array $accountInfo
* @param string $refreshToken
* @return mixed
*/
public function refreshSecurityToken(array $accountInfo, string $refreshToken)
{
try {
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('/auth/token/security/refresh');
$request->addApiParam('refresh_token', $refreshToken);
return $client->execute($request);
} catch (\Throwable $ex) {
throw new \RuntimeException("{$ex->getFile()}#{$ex->getLine()} ({$ex->getMessage()})");
}
}
/**
* 刷新令牌
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 14:50
* @doc https://open.aliexpress.com/doc/api.htm#/api?cid=3&path=/auth/token/refresh&methodType=GET/POST
* @param array $accountInfo
* @param string $refreshToken
* @return mixed
*/
public function refreshToken(array $accountInfo, string $refreshToken)
{
try {
$client = new IopClient(UrlConstants::API_GATEWAY_URL, $accountInfo['app_key'], $accountInfo['secret_key']);
$request = new IopRequest('/auth/token/refresh');
$request->addApiParam('refresh_token', $refreshToken);
return $client->execute($request);
} catch (\Throwable $ex) {
throw new \RuntimeException("{$ex->getFile()}#{$ex->getLine()} ({$ex->getMessage()})");
}
}
}

View File

@@ -0,0 +1,160 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Miravia;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* AliExpress - Miravia 物流相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 16:25
* @Package \Sweeper\PlatformMiddleware\Services\Miravia\Logistics
*/
class Logistics extends Base
{
/**
* Miravia包裹声明发货
* User: Sweeper
* Time: 2023/7/7 18:56
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.pkg.shipment.declare&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsPkgShipmentDeclare(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.pkg.shipment.declare', $params, 'package_declare_shipment_request', ['package_id_list', 'channel_type', 'seller_id']);
return $response->arise_logistics_pkg_shipment_declare_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流作废包裹
* User: Sweeper
* Time: 2023/7/7 18:59
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.repack&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsRepack(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.repack', $params, 'repack_request', ['package_id_list', 'channel_type', 'seller_id']);
return $response->arise_logistics_repack_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流修改声明发货
* User: Sweeper
* Time: 2023/7/7 19:02
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsShipmentUpdate(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.shipment.update', $params, 'package_update_request', ['channel_type', 'seller_id']);
return $response->arise_logistics_shipment_update_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流声明发货
* User: Sweeper
* Time: 2023/7/7 19:05
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.shipment.declare&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsShipmentDeclare(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.shipment.declare', $params, 'declare_shipment_request', ['trade_order_id', 'trade_order_item_id_list', 'shipment_provider_code', 'tracking_number', 'channel_type', 'seller_id']);
return $response->arise_logistics_shipment_declare_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流打包
* User: Sweeper
* Time: 2023/7/7 19:07
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.pack&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsPack(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.pack', $params, 'pack_request', ['seller_id', 'operate_way', 'trade_order_id', 'trade_order_item_id_list', 'channel_type']);
return $response->arise_logistics_pack_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流打包V2
* User: Sweeper
* Time: 2023/7/7 19:07
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.packing&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsPacking(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.packing', $params, 'pack_request', ['seller_id', 'operate_way', 'trade_order_id', 'trade_order_item_id_list', 'channel_type']);
return $response->arise_logistics_packing_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流打印面单
* User: Sweeper
* Time: 2023/7/7 19:10
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.awb.print&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsAwbPrint(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.awb.print', $params, 'print_awb_request', ['seller_id', 'package_id_list', 'channel_type', 'file_type'], 'GET');
return $response->arise_logistics_awb_print_response ?? $response;
}
/**
* Miravia物流服务商查询
* User: Sweeper
* Time: 2023/7/7 19:10
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.shipment.provider.query&methodType=GET
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsShipmentProviderQuery(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.shipment.provider.query', $params, 'shipment_provider_request', ['seller_id', 'trade_order_id', 'trade_order_item_id_list', 'channel_type'], 'GET');
return $response->arise_logistics_shipment_provider_query_response->result ?? $response->result ?? $response;
}
/**
* Miravia物流确认妥投状态
* User: Sweeper
* Time: 2023/7/7 19:10
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21395&path=arise.logistics.shipment.confirm&methodType=POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function logisticsShipmentConfirm(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.logistics.shipment.confirm', $params, 'package_confirm_request', ['event_code', 'seller_id', 'package_id_list', 'channel_type']);
return $response->arise_logistics_shipment_confirm_response->result ?? $response->result ?? $response;
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Sweeper\PlatformMiddleware\Services\Miravia;
use Sweeper\PlatformMiddleware\Services\Aliexpress\Base;
/**
* AliExpress - Miravia 订单相关接口
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 16:25
* @Package \Sweeper\PlatformMiddleware\Services\Miravia\Order
*/
class Order extends Base
{
/**
* Miravia订单列表查询
* User: Sweeper
* Time: 2023/7/7 10:58
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21394&path=arise.order.list.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getOrderList(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.order.list.query', $params, 'param0', ['current_page', 'open_channel', 'channel_seller_id']);
return $response->arise_order_list_query_response->result ?? $response->result ?? $response;
}
/**
* Miravia订单详情查询
* User: Sweeper
* Time: 2023/7/7 10:58
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21394&path=arise.order.detail.query&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function getOrderDetail(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.order.detail.query', $params, 'param0', ['trade_order_id', 'open_channel', 'channel_seller_id']);
return $response->arise_order_detail_query_response->result ?? $response->result ?? $response;
}
/**
* Miravia订单设置备注
* User: Sweeper
* Time: 2023/7/7 10:58
* @doc https://open.aliexpress.com/doc/api.htm?spm=a2o9m.11193487.0.0.35096f3dtoF70t#/api?cid=21394&path=arise.order.memo.set&methodType=GET/POST
* @param array $accountInfo
* @param array $params
* @return mixed
*/
public function setMemo(array $accountInfo, array $params = [])
{
$response = static::executeRequest($accountInfo, 'arise.order.memo.set', $params, 'param0', ['trade_order_id', 'open_channel', 'channel_seller_id']);
return $response->arise_order_memo_set_response->result ?? $response->result ?? $response;
}
}