之前看到有人在网络求教《淘宝api的吗?求问如何直接上传网络图片》,为了让新人少走弯路,以下是小编写整理相关解决方法。
代码经过测试(可以看后面的返回结果)
比如:https://www.onebound.cn/daigou/logo/0-702x180.jpg
/**
使用淘宝open api直接上传网络图片的方法
*/
//调用SDK代码如下:
$appkey=’’;
$secret=’’;
$c = new TopClient;
$c->appkey = $appkey;
$c->secretKey = $secret;
$c->format = ‘json’;
$req = new ItemAddRequest;
$req->setLocationState(“浙江”);
$req->setLocationCity(“杭州”);
$req->setNum(“30”);
$req->setPrice(“200.07”);
$req->setType(“fixed”);
$req->setStuffStatus(“new”);
$req->setTitle(“Nokia N97全新行货”);
$req->setDesc(“这是一个商品”);
$req->setApproveStatus(“onsale”);
$req->setCid(“50026519”);
//1、远程图片的方式
p i c u r l = ‘ h t t p s : / / w w w . o n e b o u n d . c n / d a i g o u / l o g o / 0 − 702 x 180. j p g ’ ; d a t a = f i l e g e t c o n t e n t s ( d a t a = f i l e g e t c o n t e n t s ( d a t a = f i l e g e t c o n t e n t s ( p i c u r l ) ; f i l e L o c a t i o n = ′ / t m p / ′ . t i m e ( ) . r a n d ( 1000 , 99999 ) . f i l e L o c a t i o n = ′ / t m p / ′ . t i m e ( ) . r a n d ( 1000 , 99999 ) . f i l e L o c a t i o n = ′ / t m p / ′ . t i m e ( ) . r a n d ( 1000 , 99999 ) . F I L E S [ pic_url=‘https://www.onebound.cn/daigou/logo/0-702x180.jpg’; data=filegetcontents( data = file_get_contents(data=file g et c ontents(pic_url); fileLocation=′/tmp/′.time().rand(1000,99999). fileLocation = '/tmp/' .time().rand(1000,99999).fileLocation= ′ /tmp/ ′ .time().rand(1000,99999)._FILES[ picurl=‘https://www.onebound.cn/daigou/logo/0−