方维购物分享系统默认会采集商品的一张主图,为了更好的展示,我需要采集商品的多张图片;
修改/core/services/goods.service.php->collectGoods()
设置要采集的字段,加上item_img;
//设置采集的字段
$req = new ItemsListGetRequest; $req->setFields("num_iid,detail_url,cid,delist_time,desc,item_img");
处理返回的多图数据,插入数据表
//add by wangtongphp QQ:1006440989 将多张图片写入表 $item ['item_imgs'] = ( array ) $item ['item_imgs']; $taobao_goods_pic = array (); if ($item ['item_imgs'] ['@attributes'] ['list']) { $item_img = ( array ) $item ['item_imgs'] ['item_img']; //如果是一维数组 if ($item_img ['url']) { $taobao_goods_pic ['keyid'] = $goods ['keyid']; $taobao_goods_pic ['url'] = addslashes ( $item_img ['url'] ); $taobao_goods_pic ['position'] = ( int ) $item_img ['position']; FDB::insert ( 'taobao_goods_pic', $taobao_goods_pic, false, true ); } //如果是二维数组 else { foreach ( $item_img as $k => $v ) { $v = ( array ) $v; $taobao_goods_pic ['keyid'] = $goods ['keyid']; $taobao_goods_pic ['url'] = addslashes ( $v ['url'] ); $taobao_goods_pic ['position'] = ( int ) $v ['position']; FDB::insert ( 'taobao_goods_pic', $taobao_goods_pic, false, true ); } } }
用taobao.items.list.get接口输出的多张图片数据测试
//var_dump($item['item_imgs'])的结果 array(2) { ["@attributes"]=> array(1) { ["list"]=> string(4) "true" } ["item_img"]=> object(SimpleXMLElement)#12 (3) { ["id"]=> string(1) "0" ["position"]=> string(1) "0" ["url"]=> string(96) "http://img02.taobaocdn.com/bao/uploaded/i2/17682019848077558/T1T80tXwRfXXXXXXXX_!!0-item_pic.jpg" } } array(2) { ["@attributes"]=> array(1) { ["list"]=> string(4) "true" } ["item_img"]=> array(3) { [0]=> object(SimpleXMLElement)#16 (3) { ["id"]=> string(1) "0" ["position"]=> string(1) "0" ["url"]=> string(72) "http://img03.taobaocdn.com/bao/uploaded/i3/T19FK.XcddXXafSdQ._111702.jpg" } [1]=> object(SimpleXMLElement)#17 (3) { ["id"]=> string(10) "5538138250" ["position"]=> string(1) "1" ["url"]=> string(87) "http://img04.taobaocdn.com/bao/uploaded/i4/387027922/T2xmnAXf0aXXXXXXXX_!!387027922.jpg" } [2]=> object(SimpleXMLElement)#18 (3) { ["id"]=> string(10) "5548397863" ["position"]=> string(1) "2" ["url"]=> string(87) "http://img04.taobaocdn.com/bao/uploaded/i4/387027922/T2YIPuXl0aXXXXXXXX_!!387027922.jpg" } } }