Home > Backend Development > PHP Tutorial > taobao.item.add上传图片的有关问题

taobao.item.add上传图片的有关问题

WBOY
Release: 2016-06-13 13:26:37
Original
913 people have browsed it

求助taobao.item.add上传图片的问题
商品会传,但是图片不知道怎么上传

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php header("Content-Type: multipart/form-data; charset=utf-8");
require_once "include\Snoopy.class.php";
$appSecret = 'XXX'; //填写自己申请的$appSecret
$app_key='XXX';
$url = 'http://gw.api.taobao.com/router/rest?';  //正式环境提交URL,一般情况下不要改
        $paramArr = array(
            'method' => 'taobao.item.add',   //API名称
            'session' => 'XXX',   //sessionkey
            'timestamp' => date('Y-m-d H:i:s'),
            'format' => 'xml',  //返回格式,本demo仅支持xml
            'app_key' => 'XXX',  //Appkey
            'v' => '2.0',   //API版本号
            'sign_method'=> 'md5', //签名方式
             'num'=> '200', //商品数量
             'price'=> '20', //商品价格
             'type'=> 'fixed', //发布类型
             'stuff_status'=> 'new', //新旧程度
             'approveStatus'=>'instock',
             'title'=> '油画入门', //标题
             //'image'=> '@3.jpg', //商品价格
             'desc'=> 'imageimageimageimage', //商品描述
             'location.state'=> '上海', //省
             'location.city'=> '上海', //市
             'cid'=> '50005701', //淘宝类目
             'seller_cids'=> '244664972', //店铺类目
             'freight_payer'=> 'buyer', //邮费模板
             'postage_id'=> '2790119', //邮费模板
             'props'=> '1636953:2147483647;', //商品属性
             'input_pids'=> '1636953', //商家编码
             'input_str'=> '9787508347394', //商品属性
                     );
        //生成签名
        $paramArr['sign']= createSign($paramArr,$appSecret);
        //组织参数
        $strParam .= 'sign='.$sign;
        //构造Url
        $reqHttp = new Snoopy();
        $reqHttp->submit($url,$paramArr);
         //$paramArr['image']= array('image'=>'@3.jpg'); //商品价格
        $r=getXmlData($reqHttp->results);
        print_r($r);

//以下为SKD内容
    //签名函数
    function createSign ($paramArr) {
        global $appSecret;
        $sign = $appSecret;
        ksort($paramArr);
        foreach ($paramArr as $key => $val) {
           if ($key !='' && $val !='') {
               $sign .= $key.$val;
           }
        }
        $sign = strtoupper(md5($sign.$appSecret));
        return $sign;
    }

    //组参函数
    function createStrParam ($paramArr) {
        $strParam = '';
        foreach ($paramArr as $key => $val) {
           if ($key != '' && $val !='') {
               $strParam .= $key.'='.urlencode($val).'&';
           }
        }
        return $strParam;
    }

    //解析xml函数
    function getXmlData ($strXml) {
        $pos = strpos($strXml, 'xml');
        if ($pos) {
            $xmlCode=simplexml_load_string($strXml,'SimpleXMLElement', LIBXML_NOCDATA);
            $arrayCode=get_object_vars_final($xmlCode);
            return $arrayCode ;
        } else {
            return '';
        }
    }

    function get_object_vars_final($obj){
        if(is_object($obj)){
            $obj=get_object_vars($obj);
        }
        if(is_array($obj)){
            foreach ($obj as $key=>$value){
                $obj[$key]=get_object_vars_final($value);
            }
        }
        return $obj;
    }

?>
Copy after login


------解决方案--------------------
到taobao open平台去询问要更多人知道些.
我忘记了,我记得好像也是有SDK什么可以直接调用的.
------解决方案--------------------
应该直接给封好库了,底层肯定是curl之类往上post的multipart/form-data。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template