顺丰开放平台Api PHP SDK demo
引用
对接前期工作注册
提交接入申请
接口初始化配置,获得 app_id 和app_secret
完成测试环境测试
进入生产使用
接入注意事项申请令牌 (/security/access_token/ 接口)
access_token 有效期为 1 小时,过期需使用 refresh_token 刷新令牌(/security/refresh_token/ 接口)
refresh_token 有效期为当天 24 点,过期需重新申请(/security/access_token/ 接口)
接口均为 https ,数据传输格式为 json
Demo
SDK Demo<?php
/**
* 顺丰 api 接口使用
* Date: 2017/10/19
* Time: 9:36
* @author zlh
*/
class SfApi {
/**
* @var string
*/
protected $app_id;
/**
* @var string
*/
protected $app_key;
/**
* @var string
*/
public $access_token;
/**
* @var string
*/
public $refresh_token;
/**
* @var string
*/
private $uri;
/**
* SfApi constructor.
* @param string $app_id
* @param string $app_key
* @param bool $online
* @return void
*/
public function __construct ($app_id, $app_key, $online = false) {
$this->app_id = $app_id;
$this->app_key = $app_key;
$this->url = $online ? 'https://open-prod.sf-express.com/' : 'https://open-sbox.sf-express.com/';
}
/**
* 快速创建订单
* @param array $req_body
* @return bool|string
*/
public function order ($req_body) {
$req_body = array(
'orderId' => $req_body['orderId'],
'expressType' => $req_body['expressType'],
'payMethod' => $req_body['payMethod'],
'custId' => $req_body['custId'],
'payArea' => isset($req_body['payArea']) ? $req_body['payArea'] : 'SFCM10008035754399',
//'remark' => $req_body['remark'],
'consigneeInfo' => array(
'company' => isset($req_body['consigneeInfo']['company']) ? $req_body['consigneeInfo']['company'] : '个人',
'contact' => $req_body['consigneeInfo']['contact'],
'tel' => $req_body['consigneeInfo']['tel'],
'province' => $req_body['consigneeInfo']['province'],
'city' => $req_body['consigneeInfo']['city'],
'county' => $req_body['consigneeInfo']['county'],
'address' => $req_body['consigneeInfo']['address'],
'mobile' => $req_body['consigneeInfo']['mobile'],
),
'cargoInfo' => array(
'cargo' => $req_body['cargoI