Coder Social home page Coder Social logo

jd-union-sdk's Introduction

京东联盟SDK

京东联盟SDK,基于新版的

PHP =>7.0

composer require yumufeng/jd-union-sdk

如果是在swoole 扩展下使用,支持协程并发,需要在编译swoole扩展的时候开启,系统会自动判断是否采用swoole

./configure --enable-openssl

由于自己没有高级接口,所以高级权限和基础权限封装是分开成两部分的。

使用示例

$config = [
    'appkey' => '', // AppId (京东联盟的appkey)
    'appSecret' => '', // 密钥 (京东联盟的appSecret)
    'unionId' => '', // 联盟ID (如果使用京东联盟的,填京东联盟的,使用京佣的填京佣的)
    'positionId' => '', // 推广位ID (如果使用京东联盟的,填京东联盟的,使用京佣的填京佣的)
    'siteId' => '', // 网站ID, (如果使用京东联盟的,填京东联盟的,使用京佣的填京佣的)
    'apithId' => '',  // 第三方网站Apith的appid (可选,不使用apith的,可以不用填写)
    'apithKey' => '', // 第三方网站Apith的appSecret (可选,不使用apith的,可以不用填写)
    'jyCode' => '', // 京东京佣的API授权调用code (可选,不使用京佣的,可以不用填写)
    'isCurl' => true // 设置为true的话,强制使用php的curl,为false的话,在swoole cli环境下自动启用 http协程客户端
];
$client = new \JdMediaSdk\JdFatory($config);
$result = $client->apith->querySeckillGoods();
if ($result == false ) {
    var_dump($client->getError());
}

var_dump($result);

说明文档

1.官方版本

以下官方版本传参参考:https://union.jd.com/#/openplatform/api

接口名称 [基础] 对应方法
jd.union.open.order.query (订单查询接口) $client->promotion->order()
jd.union.open.order.row.query (订单行查询接口) $client->promotion->orderRow()
jd.union.open.goods.promotiongoodsinfo.query (获取推广商品信息接口) $client->good->info()
jd.union.open.category.goods.get(商品类目查询) $client->good->category()
jd.union.open.user.pid.get(获取PID) $client->promotion->pid()
jd.union.open.promotion.common.get(获取通用推广链接) $client->link->get()
jd.union.open.goods.jingfen.query (京粉精选商品查询接口) $client->good->jingfen()
根据短链查询出落地页 $client->good->getLinkByShortUrl()
jd.union.open.statistics.giftcoupon.query(活动查询接口) $client->activity->query()
接口名称 [高级] 官方版 对应方法
jd.union.open.coupon.query(优惠券领取情况查询接口【申请】) $client->coupon->query()
jd.union.open.goods.seckill.query(秒杀商品查询接口【申请】) $client->good->seckill()
jd.union.open.goods.query(关键词商品查询接口【申请】) $client->good->query()
jd.union.open.promotion.bysubunionid.get(社交媒体获取推广链接接口【申请】) $client->link->bySubUnionId()
jd.union.open.promotion.byunionid.get(通过unionId获取推广链接【申请】) $client->link->byUnionId()
jd.union.open.coupon.importation(优惠券导入【申请】) $client->coupon->importation()
jd.union.open.position.query(查询推广位【申请】) $client->promotion->queryPosition()
jd.union.open.goods.bigfield.query(大字段商品查询接口(内测版)【申请】) $client->good->bigFieldQuery()
jd.union.open.coupon.gift.get(礼金创建【申请】) $client->gift->get()
jd.union.open.coupon.gift.stop(礼金停止【申请】) $client->gift->stop()
jd.union.open.statistics.giftcoupon.query(礼金停止【申请】) $client->gift->query()

2.京佣版

没有高级权限的,可以点击 加QQ 445328312 辅助获取 京佣 高级权限(由于时间有限 100人/次 服务费用,一次开通,永久使用,不限制调用量)

接口名称 [高级] 京佣版 对应方法
关键词商品查询接口【申请 $client->jingyong->queryGood()
订单查询接口,支持“subid”进行返利跟踪【申请 $client->jingyong->order()
长短转链接口,支持“subid”进行返利跟踪【申请 $client->jingyong->convert()

3.Apith版

没有Apith高级权限的,可以点击 https://apith.cn/invite/4SO80R60 (用github登录即可 ,28元/月,收费的哦)。

接口名称 [高级] Apith版 对应方法
jd.union.open.coupon.query(优惠券领取情况查询接口【申请】) $client->apith->queryCoupon()
jd.union.open.goods.seckill.query(秒杀商品查询接口【申请】) $client->apith->querySeckillGoods()
jd.union.open.goods.query(关键词商品查询接口【申请】) $client->apith->queryGoods()
jd.union.open.promotion.byunionid.get(通过unionId获取推广链接【申请】) $client->apith->getByUnionidPromotion()
jd.union.open.position.query(查询推广位【申请】) $client->apith->queryPosition()
jd.union.open.position.create(创建推广位【申请】) $client->apith->createPosition()
商品主图列表查询【申请 $client->apith->getGoodsImageList()
根据短链查询出落地页【申请 $client->apith->getLinkByShort()
根据短链接查询商品编号【申请 $client->apith->getSkuIdByShort()

License

Apache

jd-union-sdk's People

Contributors

asundust avatar hisway avatar sdhou avatar uhowep avatar vangogogo avatar yumufeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jd-union-sdk's Issues

apith推广位创建siteID

src/Api/Apith.php:100

public function createPosition(array $spaceNameList, string $key, $unionType = 1, $type = 4)
{
$param = [
'unionId' => $this->unionId,
'key' => $key,
'unionType' => $unionType,
'type' => $type,
'spaceNameList' => implode(',', $spaceNameList)
];
if ($type == 1) {
$param = array_merge($param, [
'siteId' => $this->siteId
]);
}
return $this->send('createPosition', $param);
}

站点ID,即网站ID/app ID/snsID ,当type传入4以外的值时,siteId为必填
$type == 1 需要改成 $type !== 4

错误处理需要更新下

vendor/yumufeng/jd-union-sdk/src/Tools/JdGateWay.php Line:211

/**
     * 解析参数
     * @param $result
     * @param bool $raw
     * @return mixed
     */
    private function parseReps($result, $raw = false)
    {
        $decodeObject = json_decode($result, true);
        if (is_string($decodeObject)) {
            return $this->setError($decodeObject);
        }
        if (is_null($decodeObject)) {
            return $this->setError("Api返回结果为空");
        }
        if ($this->is_auth === true) {
            if ($raw == true) {
                return $decodeObject;
            }
            if ($decodeObject['code'] != 1) {
                $this->setError($decodeObject['msg']);
                return false;
            }
            return isset($decodeObject['data']) ? $decodeObject['data'] : [];
        } else {
            $nowLists = current($decodeObject);
            if ($nowLists['code'] != 0) {
                var_dump($nowLists);die;
                return $this->setError(isset($nowLists['msg']) ? $nowLists['msg'] : '错误信息');
            }
            $finally = json_decode($nowLists['result'], true);
            if ($finally['code'] != 200) {
                return $this->setError($finally['message']);
            }
            if ($raw == true) {
                return $finally;
            }
            return isset($finally['data']) ? $finally['data'] : [];
        }
    }

打印结果:
array(3) {
["code"]=>
string(1) "8"
["zh_desc"]=>
string(161) "时间戳参数与服务器时间差异大于设定值timestamp=2019-07-28 09:22:09(解决方案参考:http://open.jd.com/home/home#/doc/common?listId=533)"
["en_desc"]=>
string(89) "Invalid Timestamp(Solution reference:http://open.jd.com/home/home#/doc/common?listId=533)"
}


此种情况下,key为 zh_desc,不是msg

望楼主更新下,否则调试不太方便:)

JdGateWay 构造函数少了siteId的赋值

`/**
* JdGateWay constructor.
* @param array $config
* @param JdFatory $jdFatory
*/
public function __construct(array $config, JdFatory $jdFatory)
{

    $this->appkey = $config['appkey'];
    $this->appSecret = $config['appSecret'];
    $this->apithId = isset($config['apithId']) ? $config['apithId'] : '';
    $this->apithKey = isset($config['apithKey']) ? $config['apithKey'] : '';
    $this->unionId = $config['unionId'];
    $this->positionId = $config['positionId'];
    $this->pid = $config['unionId'] . '_' . $config['siteId'] . '_' . $config['positionId'];
    $this->jdFatory = $jdFatory;
    $this->isCurl = isset($config['isCurl']) && ($config['isCurl'] == true) ? true : false;
    $this->siteId=$config['siteId'];//缺少赋值
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.