1 Star 0 Fork 6

skymysky / ElemeSDK

forked from hillpy / ElemeSDK 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

饿了么蜂鸟配送php开发包(开发中)

issue star fork license

功能介绍

本项目为蜂鸟配送开放平台api封装库,使用php语言实现,封装为composer包。

安装方法

  1. 下载发行版

  2. 使用composer安装(推荐)

  • 请在项目根目录执行以下命令(请使用版本较新的composer,并设置好镜像源)
composer require hillpy/eleme-sdk

使用方法

  • 以下为示例代码
/**
 * 使用案例
 * 注意:实际项目若使用composer安装的库,请先引入自动加载脚本(require __DIR__ . '/vender/autoload.php';)。另外需安装redis扩展并开启redis服务
 */
use hillpy\ElemeSDK\Eleme;

// 设置中国时区(个别接口涉及时间数据)
date_default_timezone_set('PRC');

// 设置变量
$appId = '';
$secretKey = '';

// 设置实例化参数
$paramArr = array(
    'appId'=>$appId,
    'secretKey'=>$secretKey,
    'debug'=>true,
    'accessToken'=>''
);

$debug = $paramArr['debug'] ? 'true' : 'false';

// 从redis获取accessToken;
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$accessToken = $redis->get('eleme_access_token_appid_' . $appId . '_debug_' . $debug);

// 若存在accessToken,加入paramArr数组中
$accessToken && $paramArr['accessToken'] = $accessToken;

// 实例化Eleme
$eleme = new Eleme($paramArr);

//若缓存中不存在accessToken,从新实例化对象中获取并写入redis
if (!$accessToken) {
     isset($eleme->accessTokenData['access_token']) && $accessToken = $eleme->accessTokenData['access_token'];

    if ($accessToken) {
        // 获取的expire_time为毫秒时间戳,转秒时间戳并减去10秒(过期时间适当提前避免accessToken实际已失效)
        if (isset($eleme->accessTokenData['expire_time'])) {
            $expireTime = intval(($eleme->accessTokenData['expire_time'] / 1000)) - 10;
            $cacheTime = $expireTime - time();
        } else {
            $cacheTime = 0;
        }
        $redis->setex('eleme_access_token_appid_' . $appId . '_debug_' . $debug, $cacheTime, $accessToken);
    }
}

// 输出accessToken
if ($accessToken == '') {
    echo 'accessToken获取失败<br>';
} else {
    echo 'accessToken:' . $accessToken . '<br>';
}

// 以添加添加门店接口为例,以下为门店接口请求数据及结果 
$extendParamArr['data'] = array(
    'chain_store_code' => '',
    'chain_store_name' => '',
    'contact_phone' => '',
    'address' => '',
    'position_source' => 3,
    'longitude' => '',
    'latitude' => '',
    'service_code' => 1
);

$res = $eleme->addChainStore($extendParamArr);

var_dump('<pre>');
var_dump($res);

仓库地址

Coding
Gitee
Github

协议

MIT

MIT License Copyright (c) 2018 shinn lancelot Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

饿了么蜂鸟配送php开发包 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/skymysky/ElemeSDK.git
git@gitee.com:skymysky/ElemeSDK.git
skymysky
ElemeSDK
ElemeSDK
master

搜索帮助