asundust/tmall-sdk

该包已被废弃,不再维护。未建议替代包。

天猫店铺SDK

1.0.13 2019-12-27 01:56 UTC

This package is auto-updated.

Last update: 2020-09-23 09:05:02 UTC


README

与天猫商家相关的SDK

安装

composer require asundust/tmall-sdk

接口查找

查询当前SDK中是否包含所需的API搜索接口。请全局搜索,去掉开头的taobao.

例如查询taobao.items.onsale.get,全局搜索关键字items.onsale.get即可。

Api方法上的类注释中都包含了接口文档地址。

PS:部分接口可能在实际使用中不涉及,暂时未删除接口。也请不要问我为什么接口不列出。

使用

$config = [
        'app_key' => '111111',
        'secret' => 'abcdefg12345678',
        'customerId' => '222222222',
    ];
Tmall::qimen($config)->store->query(['storeId' => 12345678]);

通常必传app_keysecret,如customerId属于特殊接口可选传。

接口命名规则:如taobao.qimen.storeinventory.itemupdate,调用方式为单词名的驼峰式,即Tmall::qimen($config)->storeInventory->itemUpdate(['xxx' => 'xxx']);

三段式的接口会多一个index方法,如taobao.refund.get的请求方式为Tmall::refund($config)->get->index(['xxx' => 'xxx']);

超过标准四段式的接口会使用驼峰的方法,如taobao.rdc.aligenius.sendgoods.cancel的请求方式为Tmall::rdc($config)->aliGenius->sendGoodsCancel(['xxx' => 'xxx']);

传参

奇门接口使用XML格式入参,如果入参需要重复参数,由于PHP不支持同键数组,目前的妥协方案为:将键值拼上数字,在转换成XML时自动去掉。关于这个问题,如有更好的建议请提出。例如:入参规则为

<?xml version="1.0" encoding="UTF-8"?>
<request> 
	<userId>淘宝账号ID,long ,必填</userId>
	<operationTime>操作时间,string (19) , YYYY-MM-DD HH:MM:SS,必填</operationTime>
	<stores>
		<store>
			<warehouseType>库存来源的类型,string(50),WAREHOUSE=电商仓,STORE=门店,必填</warehouseType>
			<warehouseId>门店ID(商户中心) 或 电商仓ID,string(50),必填</warehouseId>	
			<storeInventories>
				<storeInventory>
					<billNum>单据流水号,用于幂等操作,string(50) ,必填</billNum>
					<itemId>淘宝前端商品id,long,必填</itemId>
					<outerId>ISV系统中商品SKU外部编码(一定要和itemid,skuid一致,不然会认为是一个新的商品,且保证唯一),string(50) ,必填</outerId>
					<skuId>商品的SKU编码,long,有sku的必填</skuId>
					<inventoryType>库存类型,string(50),CERTAINTY=确定性库存,UNCERTAINTY=不确定性库存,必填</inventoryType>
					<quantity>对应类型的库存数量(正数),int,必填</quantity>
				</storeInventory>
			</storeInventories>
		</store>
	</stores>
</request>

入参数组

[
    'userId' => '000000',
    'stores' => [
        'store0' => [
            'warehouseType' => 'STORE',
            'warehouseId' => '111111',
            'storeInventories' => [
                'storeInventory' => [
                    'itemId' => '222222',
                    'outerId' => '333333',
                    'skuId' => '444444',
                ]
            ],
        ],
        'store1' => [
            'warehouseType' => 'STORE',
            'warehouseId' => '555555',
            'storeInventories' => [
                'storeInventory' => [
                    'itemId' => '666666',
                    'outerId' => '777777',
                    'skuId' => '888888',
                ]
            ],
        ]
    ],
]

上述的store0store1在转换成XML后会自动变回store

Auth用户授权

执行(new \TmallSdk\Auth($config))->auth($redirectUri);

传入回调地址,获取code后执行(new \TmallSdk\Auth($config))->getAccessToken($code);

相关文档 https://open.taobao.com/doc.htm?docId=102635&docType=1

其他

如果遇到错误之处还请各位指出

需要增加接口请告知

许可证

MIT许可证