阿里巴巴開放平臺 sdk -PHP

liaosp發表於2019-12-08

.

Installing

$ composer require liaosp/ali_open -vvv

Usage

在這裡插入圖片描述
場景: 拉取阿里巴巴商家的採購資料,同步到erp上,採用的是多使用者模式,即不需要獲取token,直接到open.1688.com 獲取持久access_token ,故沒有把獲取token 的方式分裝到裡面,大家可以參考這篇文章:https://liaosp.blog.csdn.net/article/detai...
說明:本例子是因為官方sdk看得太累了,所以自己封裝一下簽名,供大家參考!

        $obj = new \Liaosp\AliOpen\AliOpen(['page'=>1]);
        $obj->setAppkey('你的appkey');
        $obj->setAppsecret('你的祕鑰');
        $obj->setAccessToken('自己想辦法去獲取token,如果設定的是多使用者單使用者的直接複製,應用管理中的token');//參考:https://liaosp.blog.csdn.net/article/details/103440299
        $res =$obj->order->setApi('com.alibaba.trade:alibaba.trade.getBuyerOrderList-1')->get(); //api 就是阿里巴巴文件中的
        var_dump($res);

專案中可以繼承他:

<?php

namespace App\Services\AliOpen;

class AliOpen extends \Liaosp\AliOpen\AliOpen
{
    public function __construct($params = array())
    {
        $this->setAppkey('39376**');
        $this->setAppsecret('0RsvFZYV**');
        $this->access_token = '06410386-242c-41f6-8a20-5e7e0d2b6229';
        parent::__construct($params);
    }
}

獲取訂單列表的例子

        $get_data =( new AliOpen([     //這邊的AliOpen ,是你設定appkey的物件
            'page'=>1,
            'pageSize'=>100,
        ]))
            ->order
            ->setApi('com.alibaba.trade:alibaba.trade.getBuyerOrderList-1')
            ->get();

獲取訂單詳情的例子

        $get_data = (new AliOpen([
            'webSite'=>1688,
            'orderId'=>$this->app->order_id,
        ]))
            ->order
            ->setApi('com.alibaba.trade:alibaba.trade.get.buyerView-1')
            ->get();

你的星星是我持續更新的動力
https://github.com/liaoshengping/ali_open

和我做朋友?

https://www.cnblogs.com/liaosp/p/11075260....

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章