官方链接:open.dianping.com/document/v2…
根据下方图中流程可以找到官方提供的测试账号:


登录上测试账号进入我的应用,选择你要开发的应用模块

点击对应应用模块,进入下面图中,可以拿到对应店铺的session和open_shop_uuid和refresh_session
- session 此参数在调用api请求参数时,有详细说明
- open_shop_uuid 美团点评店铺id (官方建议调用api使用此参数)
- app_shop_id 第三方的店铺id (官方 不 建议使用api使用此参数)
- app_shop_id 和 open_shop_uuid 会在调用api时有详细说明
- 图中有个小二维码可以用大众点评app扫码进入此店铺,购买券,进行测试
- 我已买了两个测试券码【4357249135(已核销),6950654050(未核销)】

下面图中可以拿到Appkey和Secret

以上都是为了下面调用api时所准备需要的基本参数,下面请直接查看代码。
<?php
namespace Meituan;
/*美团点评北极星券*/
class Volume
{
protected $app_key='13009a02d1389c40';
protected $secret = 'c36a0fd6480c221bd432fa0ee7870a7b5ae40de4';
/*
* 官方文档 http://open.dianping.com/document/v2?docId=6000173&rootDocId=5000
* 注:
* 测试session 【 https://open.dianping.com/application/console/applytest?appkey=13009a02d1389c40 】
*
* receipt_code 券码,我已买了两个测试券【4357249135(已核销),6950654050(未核销)】
* */
/*公共请求参数*/
public function packagedata(){
$para['app_key'] = $this->app_key;
$para['format'] = 'json';
$para['v'] = 1;
$para['sign_method'] = 'MD5';
$para['session'] = '31eecf960a7f136a874f2d69b06fae9a441ed678';//可通过刷新缓存和获取缓存获得
$para['timestamp'] = date('Y-m-d H:m:s',time());
return $para;
}
/*
* https://open.dianping.com/document/v2?docId=6000177&rootDocId=5000【官方文档】
* 验券接口--核销卷提交*/
public function consume(){
$url = 'https://openapi.dianping.com/router/tuangou/receipt/consume';
$para = $this->packagedata();//公共请求参数
$para['open_shop_uuid'] = '8970011729ef26eb30bfc10a12ae5f46';
$para['requestid'] = '123';
$para['receipt_code'] = '4357249135';
$para['count'] = 1;
$para['app_shop_account'] = 'opensdktest';
$para['app_shop_accountname'] = 'opensdktest';
$sign = $this->setsign($para);
$para['sign'] = $sign;
$res = $this->send_post($url,$para);
$result = json_decode($res,true);
return sendMessage($result);
}
/*
* https://open.dianping.com/document/v2?docId=6000176&rootDocId=5000 【官方文档】
* 输码验券校验接口--获取券的信息*/
public function prepare(){
$url = 'https://openapi.dianping.com/router/tuangou/receipt/prepare';
$para = $this->packagedata();//公共请求参数
$para['receipt_code'] = '6950654050';
$para['open_shop_uuid'] = '8970011729ef26eb30bfc10a12ae5f46';
$sign = $this->setsign($para);
$para['sign'] = $sign;
$res = $this->send_post($url,$para);
$result = json_decode($res,true);
return sendMessage($result);
}
/*
* https://open.dianping.com/document/v2?docId=6000164&rootDocId=5000【官方文档】
* 商家授权UI组件*/
public function merchantauth(){
$redirect_url = 'http://www.ym.com/applet.php/Show/gettoken';//回调地址(第三方平台会通过此回调地址将授权码传递过来)
$url = 'https://e.dianping.com/dz-open/merchant/auth?app_key='.$this->app_key.'&state=11&redirect_url='.$redirect_url;
echo $url;
}
/*系统授权session获取接口----此方法未成功--原因不知道为啥老是提示我授权码过期*/
public function gettoken(){
$auth_code = input('get.auth_code');//此处是通过回调地址获取的授权码
$url = 'https://openapi.dianping.com/router/oauth/token';
$para['app_key'] = $this->app_key;
$para['app_secret'] = $this->secret;
$para['auth_code'] = $auth_code;
$para['grant_type'] = 'authorize_platform';
$para['redirect_url'] = 'http://www.ym.com/applet.php/Show/gettoken';//以目前个人理解,此回调地址与商家授权回调地址一致【具体请看官方 https://open.dianping.com/document/v2?docId=6000341&rootDocId=5000】
$res = $this->send_post($url,$para);
$result = json_decode($res,true);
return sendMessage($result);
}
/*
* https://open.dianping.com/document/v2?docId=6000342&rootDocId=5000【官方文档】
* 缓存时间为30天,缓存到期时间也会返回
* session刷新接口--通过 refresh_token缓存值 获取最新 session值,返回最新 refresh_token缓存值 和 session值*/
public function refreshtoken(){
$url = 'https://openapi.dianping.com/router/oauth/token';
$para['app_key'] = $this->app_key;
$para['app_secret'] = $this->secret;
$para['grant_type'] = 'refresh_token';
$para['refresh_token'] = 'be2f77b9409b7d013e5dd8ee5165549d267feee5';//refresh_token缓存值
$res = $this->send_post($url,$para);
$result = json_decode($res,true);
return sendMessage($result);
}
/*发送post请求*/
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
/*签名组装*/
public function setsign($para){
ksort($para);
$str = '';
foreach ($para as $key=>$value){
if(!empty($value)){
$str = $str.$key.$value;
}
}
$str = $this->secret.$str.$this->secret;
$str = MD5($str);
$str = strtolower($str);
return $str;
}
//拼接url
public function createLinkstringUrlencode($para){
$arg = "";
while (list ($key, $val) = each($para)) {
$arg .= $key . "=" . $val . "&";
}
$arg = substr($arg, 0, count($arg) - 2);
if (get_magic_quotes_gpc()) {
$arg = stripslashes($arg);
}
return $arg;
}
}