Skip to content

Commit

Permalink
Merge pull request #4 from hVenus/develop
Browse files Browse the repository at this point in the history
添加子帐号接口。添加两个interface.添加token刷新方法。
  • Loading branch information
hVenus authored Feb 18, 2018
2 parents 401c4c1 + 4a0ad85 commit eb7157a
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 6 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ composer require hvenus/Jingdong-api

## 使用

示例

```php

Expand Down Expand Up @@ -69,6 +70,7 @@ $jd->ExpressGetWaybillCode([

## 已完成接口

* ACCOUNT 子账号API
* ADDRESS 京东地址库API
* ECLP ECLP仓海API
* EXPRESS 京东快递API
Expand All @@ -81,6 +83,38 @@ $jd->ExpressGetWaybillCode([

PHP函数不允许以数字开头,所以所有数字开头的前面都多加个“jd_”前缀以示区别.

## 刷新授权Token

京东的授权Token正式环境下是一年的有效期,可以写个定时任务每天去检查下token的过期时间,根据需要来自动刷新。

示例
```php
// 先取出已经获得到授权数据
$auth_time = $config['jd:auth:time']; // token发放时间,单位毫秒
$auth_expires_in = $config['jd:auth:expires_in']; // 有效期时长, 单位秒
$auth_refresh_token = $config['jd:auth:refresh_token']; // refresh_token
$expires_time = $auth_time + $auth_expires_in * 1000; // 计算过期时间,单位毫秒。 token发放时间(毫秒) + 有效期时长(秒) * 1000
$diff = $expires_time/1000 - time(); // 取差值,表示还剩多少秒过期。
$deadline = 60*60*24; // 一天
if ($diff <= $deadline) { // 一天内过期
// 刷新
$param = [
'client_id' => $config['AppKey'],
'client_secret' => $config['AppSecret'],
'refresh_token' => $config['refresh_token'],
'state' => $Something, // 此参数内容原样返回
];
$result = $jd->RefreshToken($param);
if (false !== $result) {
// 重新设置新token
$config['jd:auth:access_token'] = $result['access_token']; // 新access_token
$config['jd:auth:expires_in'] = $result['expires_in'];
$config['jd:auth:refresh_token'] = $result['refresh_token']; // 京东文档说refresh_token是不变的。
$config['jd:auth:time'] = $result['time'];
}
}
```

## License

MIT
137 changes: 137 additions & 0 deletions src/API/ACCOUNT.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* 子账号API.
*/

namespace hVenus\JingdongAPI\API;


trait ACCOUNT
{
/**
* 普通 基础 jingdong.vender.childAccount.query 1. 查询员工信息
* @param $params
* @return mixed
*/
public function VenderChildAccountQuery($params) {
return $this->call_jd_function('jingdong.vender.childAccount.query', $params);
}

/**
* 普通 基础 jingdong.vender.childaccount.role.query 2. 查询员工角色信息
* @param $params
* @return mixed
*/
public function VenderChildAccountRoleQuery($params) {
return $this->call_jd_function('jingdong.vender.childaccount.role.query', $params);
}

/**
* 普通 基础 jingdong.vender.childaccount.dept.query 3. 查询员工所在部门信息
* @param $params
* @return mixed
*/
public function VenderChildAccountDeptQuery($params) {
return $this->call_jd_function('jingdong.vender.childaccount.dept.query', $params);
}

/**
* 普通 基础 jingdong.vender.childaccount.privilege.query 4. 查询员工的权限
* @param $params
* @return mixed
*/
public function VenderChildAccountPrivilegeQuery($params) {
return $this->call_jd_function('jingdong.vender.childaccount.privilege.query', $params);
}

/**
* 普通 基础 jingdong.vender.privilege.query 5. 查询商家的权限信息
* @param $params
* @return mixed
*/
public function VenderPrivilegeQuery($params) {
return $this->call_jd_function('jingdong.vender.privilege.query', $params);
}

/**
* 普通 基础 jingdong.vender.dept.list 6. 查询部门列表
* @param $params
* @return mixed
*/
public function VenderDeptList($params) {
return $this->call_jd_function('jingdong.vender.dept.list', $params);
}

/**
* 普通 基础 jingdong.vender.dept.get 7. 获取单个部门信息
* @param $params
* @return mixed
*/
public function VenderDeptGet($params) {
return $this->call_jd_function('jingdong.vender.dept.get', $params);
}

/**
* 普通 基础 jingdong.vender.dept.add 8. 新增部门
* @param $params
* @return mixed
*/
public function VenderDeptAdd($params) {
return $this->call_jd_function('jingdong.vender.dept.add', $params);
}

/**
* 普通 基础 jingdong.vender.dept.delete 9. 删除部门
* @param $params
* @return mixed
*/
public function VenderDeptDelete($params) {
return $this->call_jd_function('jingdong.vender.dept.delete', $params);
}

/**
* 普通 基础 jingdong.vender.dept.modify 10. 修改部门名称
* @param $params
* @return mixed
*/
public function VenderDeptModify($params) {
return $this->call_jd_function('jingdong.vender.dept.modify', $params);
}

/**
* 普通 基础 jingdong.vender.role.list 11. 查询角色列表
* @param $params
* @return mixed
*/
public function VenderRoleList($params) {
return $this->call_jd_function('jingdong.vender.role.list', $params);
}

/**
* 普通 基础 jingdong.vender.role.get 12. 获取单个角色信息
* @param $params
* @return mixed
*/
public function VenderRoleGet($params) {
return $this->call_jd_function('jingdong.vender.role.get', $params);
}

/**
* 普通 基础 jingdong.vender.role.modify 14. 修改角色名称
* @param $params
* @return mixed
*/
public function VenderRoleModify($params) {
return $this->call_jd_function('jingdong.vender.role.modify', $params);
}

/**
* 普通 基础 jingdong.vender.announcement.list 15. 公告列表查询
* @param $params
* @return mixed
*/
public function VenderAnnouncementList($params) {
return $this->call_jd_function('jingdong.vender.announcement.list', $params);
}

}
15 changes: 10 additions & 5 deletions src/API/ADDRESS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,44 @@
trait ADDRESS
{
/**
* 普通 基础 jingdong.areas.province.get 获取省级地址列表——新省级地址接口
* 普通 基础 jingdong.areas.province.get 获取省级地址列表——新省级地址接口
* @param $params
* @return mixed
*/
public function AddressGetProvince($params) {
return $this->call_jd_function('jingdong.areas.province.get', $params);
}

/**
* 普通 基础 jingdong.areas.city.get 获取市级信息列表——新市级地址接口
* 普通 基础 jingdong.areas.city.get 获取市级信息列表——新市级地址接口
* @param $params
* @return mixed
*/
public function AddressGetCity($params) {
return $this->call_jd_function('jingdong.areas.city.get', $params);
}

/**
* 普通 基础 jingdong.areas.county.get 获取区县级信息列表——新区县级地址接口
* 普通 基础 jingdong.areas.county.get 获取区县级信息列表——新区县级地址接口
* @param $params
* @return mixed
*/
public function AddressGetCounty($params) {
return $this->call_jd_function('jingdong.areas.county.get', $params);
}

/**
* 普通 基础 jingdong.areas.town.get 获取乡镇级信息列表——新乡镇级地址接口
* 普通 基础 jingdong.areas.town.get 获取乡镇级信息列表——新乡镇级地址接口
* @param $params
* @return mixed
*/
public function AddressGetTown($params) {
return $this->call_jd_function('jingdong.areas.town.get', $params);
}

/**
* 普通 基础 jingdong.zxj.cod.get 中小件COD
* 普通 基础 jingdong.zxj.cod.get 中小件COD
* @param $params
* @return mixed
*/
public function AddressGetCOD($params) {
Expand Down
26 changes: 25 additions & 1 deletion src/JD.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace hVenus\JingdongAPI;

use hVenus\JingdongAPI\API\ACCOUNT;
use hVenus\JingdongAPI\API\ADDRESS;
use hVenus\JingdongAPI\API\CATEGORY;
use hVenus\JingdongAPI\API\DSP;
Expand All @@ -17,7 +18,7 @@

class JD extends BaseClass
{
use Helper, ECLP, EXPRESS, ADDRESS, CATEGORY, DSP, SHOP, ORDER;
use Helper, ECLP, EXPRESS, ADDRESS, CATEGORY, DSP, SHOP, ORDER, ACCOUNT;

/**
* 获取各接口的具体地址
Expand Down Expand Up @@ -86,4 +87,27 @@ public function Call($method, $param) {
return $this->call_jd_function($method, $param);
}

/**
* 刷新京东的授权Token
* @param $param
* @return bool|mixed
*/
public function RefreshToken($param) {
$config = [
'client_id' => $param['AppKey'],
'client_secret' => $param['AppSecret'],
'grant_type' => 'refresh_token',
'refresh_token' => $param['refresh_token'],
'state' => $param['state'],
'scope' => 'read',
];
$result = $this->HttpPost('https://oauth.jd.com', 'oauth/token', $config);

if ($result != '') {
$data = json_decode($result);
return $data;
}
return false;
}

}
38 changes: 38 additions & 0 deletions src/JingDongExpressInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* JingDong Express Interface.
*/

namespace hVenus\JingdongAPI;


interface JingDongExpressInterface
{
/**
* 下京东快递单
* @param $params
* @return mixed
*/
public function AddExpressOrder($params);

/**
* 取消运单
* @param $params
* @return mixed
*/
public function CancelExpressOrder($params);

/**
* 获取运单详情
* @param $params
* @return mixed
*/
public function GetExpressOrder($params);

/**
* 获取运单路由信息
* @param $mail_no
* @return mixed
*/
public function GetExpressOrderRoute($mail_no);
}
45 changes: 45 additions & 0 deletions src/JingDongWarehouseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* JingDong Warehouse Interface.
*/

namespace hVenus\JingdongAPI;


interface JingDongWarehouseInterface
{
/**
* 采购入库单
* @param $erp_order_id
* @return mixed
*/
public function AddEntryWarehouseOrder($erp_order_id);

/**
* 取消采购入库单
* @param $entry_warehouse_order_id
* @return mixed
*/
public function CancelEntryWarehouseOrder($entry_warehouse_order_id);

/**
* 仓库销售出库单
* @param $params
* @return mixed
*/
public function AddWarehouseSalesOrder($params);

/**
* 取消销售出库订单
* @param $salses_order
* @return mixed
*/
public function CancelWarehouseSalesOrder($salses_order);

/**
* 添加商品信息
* @param $goods_id
* @return mixed
*/
public function AddGoodsInfoToWarehouse($goods_id);
}

0 comments on commit eb7157a

Please sign in to comment.