api上传网络图片的方法
使用淘宝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 ge t co 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[pic
u
rl=‘https://www.onebound.cn/daigou/logo/0−702x180.jpg’;data=filegetcontents(data=file
g
et
c
ontents(data=filegetcontents(pic
u
rl);fileLocation=′/tmp/′.time().rand(1000,99999).fileLocation=
′
/tmp/
′
.time().rand(1000,99999).fileLocation=′/tmp/′.time().rand(1000,99999).
F
ILES[imgname][‘name’];
req−>setImage(′@′.req->setImage(’@’.req−>setImage(
′
@
′
.fileLocation);
//2、上传图片的方法
/*
$tmpname = $_FILES[‘img’][‘name’];
$tmpfile = $_FILES[‘img’][‘tmp_name’];
$type = $_FILES[‘img’][‘type’];
okfile=′/tmp/′.time().rand(1000,99999).ok_file = ‘/tmp/’.time().rand(1000,99999).ok
f
ile=
′
/tmp/
′
.time().rand(1000,99999)._FILES[‘img’][‘name’];
move_uploaded_file(tmpfile,tmpfile,tmpfile,ok_file);
req−>setImage(′@′.req->setImage(’@’.req−>setImage(
′
@
′
.fileLocation);
*/
//3、setPicPath是淘宝图片空间的相对地址,并不是可以直接传的网络图片地址
//$req->setPicPath(“i7/T1rfxpXcVhXXXH9QcZ_033150.jpg”);
$resp = c−>execute(c->execute(c−>execute(req, $sessionKey);
返回结果:
{
“item_add_response”: {
“item”: {
“created”: “2020-02-29 10:11:09”,
“iid”: “613055906493”,
“num_iid”: 613055906493
},
“request_id”: “nfe27adkvygx”
}