最近项目徐要对接饿了么 http://merchant.openapi.eleme.io/quickstart.html,饿了么居然没给sdk,只好自己写了,不开心
1.首先要拿到两个参数
consumer_key
是对接饿了么开放平台的基本凭证,它代表的是一个品牌或个人实体。该品牌或个人的所有餐厅会关联在此key之下。
consumer_secret
eleme分配给APP的consumer_key
2.制作签名,直接看代码吧——makeSig2()
3.发送http请求——sendHttp2();
4.制作接口——提供了餐厅接口和订单接口的例子
5.调接口——这就不用写出来了吧
商家测试
饿了么提供了以下体验店信息以供接口开发测试:
consumer_key: 0170804777
consumer_secret: 87217cb263701f90316236c4df00d9352fb1da76
restaurant_id: 62028381
restaurant_name: 饿了么开放平台测试
餐厅下单测试地址: http://r.ele.me/openapi-test
注意:如遇到 "测试餐厅必须与测试帐号一起使用" 的错误提示,请清理cookies
/**
饿了吗接口,参考文档 http://merchant.openapi.eleme.io/quickstart.html
Created by sky
User: SD
Date: 2016/7/15
Time: 17:36
*/
class ElemeAPI
{
const BASE_URL = 'http://v2.openapi.ele.me/';
private $consumer_key;
private $consumer_secret;
/**
* 初始化接口类,必须两个参数,consumer_key,consumer_secret
* ElemeAPI constructor.
* @param $sy_param ['consumer_key'=>'','consumer_secret'=>'']
*/
public function __construct($sy_param)
{
$this->consumer_key = $sy_param['consumer_key'];
$this->consumer_secret=$sy_param['consumer_secret'];
}
####################餐厅接口
/**
* 查询所属餐厅
* @return mixed
*/
function getAllRestaurants(){
$api_url='restaurant/own/';
$sy