一、功能簡(jiǎn)要介紹
1、根據(jù)需求,用戶(hù)在美團(tuán)大眾點(diǎn)評(píng)中所購(gòu)買(mǎi)的門(mén)票在自己的系統(tǒng)上可以核銷(xiāo),同時(shí)把核銷(xiāo)信息存儲(chǔ)到自己的系統(tǒng)里。
2、美團(tuán)點(diǎn)評(píng)API文檔地址:https://open.dianping.com/document/v2?rootDocId=5000
二、開(kāi)發(fā)步驟:
1、用點(diǎn)評(píng)管家賬號(hào)登錄文檔,相應(yīng)文檔說(shuō)明:https://open.dianping.com/document/v2?docId=6000136rootDocId=1000
2 、選好自己相應(yīng)的應(yīng)用型,審核通過(guò)之后,就可以用平臺(tái)系統(tǒng)的測(cè)試的數(shù)據(jù)就行接口調(diào)用
3、在大眾點(diǎn)評(píng)app購(gòu)買(mǎi)相應(yīng)票,根據(jù)驗(yàn)券核銷(xiāo)API文檔(根據(jù)業(yè)務(wù)需求選擇的類(lèi)型是自用型)調(diào)取查詢(xún)?nèi)Ⅱ?yàn)券即核銷(xiāo)券的接口,代碼如下:
//查詢(xún)?nèi)Ⅱ?yàn)券
public function prepare(){
// $arr 為數(shù)組 里面為應(yīng)用參數(shù)
$appKey = "1ef04****e3a8"; //key
$secret = "dd8a291f9f*****4e3fbd9be6ff"; //秘鑰
$timestamp = date('Y-m-d H:i:s');
$format = 'json';
$v = 1;
$sign_method = 'MD5';
$qr_code = '257***4228';
$open_shop_uuid = '34d5902420ca****48e941a38d773';
$session = 'bbf7059256aaf3f1****3b4d9c0816cf819b7';
$data = [
'app_key' => $appKey,
'timestamp' => $timestamp,
'sign_method' => $sign_method,
'format' => $format,
'v' => $v,
'session' => $session,
];
$arr = [
'requestid'=>'123',
'receipt_code' => $qr_code,
//'qr_code'=>$qr_code,
'open_shop_uuid' => $open_shop_uuid,
//'count'=>1,
//'app_shop_account' =>'test',
// 'app_shop_accountname' =>'test1',
];
$data = array_merge($data, $arr);
ksort($data);
$sign = $this->cal_sign($secret, $data);//獲取簽名
$data['sign'] = $sign;
// $data['count'] = $sign;
// $data['app_shop_account'] = $sign;
// $data['app_shop_accountname'] = $sign;
$data = array_merge($data, $arr);
$postdata = http_build_query($data);
$url = 'https://openapi.dianping.com/router/tuangou/receipt/prepare';//輸碼查詢(xún)?nèi)?
//$url = 'https://openapi.dianping.com/router/tuangou/receipt/scanprepare';//掃碼查詢(xún)?nèi)?
//$url = 'https://openapi.dianping.com/router/tuangou/receipt/consume';//驗(yàn)券
$tmpInfo=$this->curl_post($url,$postdata);
var_dump($tmpInfo);
}
/**
* 計(jì)算簽名
*
* @param $app_secret 三方app_secret
* @param $req_param 請(qǐng)求參數(shù)集合,包括公共參數(shù)和業(yè)務(wù)參數(shù)
* @return string md5簽名
*/
function cal_sign($app_secret, $req_param)
{
// 排序所有請(qǐng)求參數(shù)
ksort($req_param);
$src_value = "";
// 按照key1value1key2value2...keynvaluen拼接
foreach ($req_param as $key => $value) {
$src_value .= ($key . $value);
}
//計(jì)算md5
return md5($app_secret . $src_value . $app_secret);
}
//post請(qǐng)求
private function curl_post($url,$postdata){
$curl = curl_init(); // 啟動(dòng)一個(gè)CURL會(huì)話(huà)
curl_setopt($curl, CURLOPT_URL, $url); // 要訪(fǎng)問(wèn)的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對(duì)認(rèn)證證書(shū)來(lái)源的檢測(cè)
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Expect:'
)); // 解決數(shù)據(jù)包大不能提交
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動(dòng)跳轉(zhuǎn)
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動(dòng)設(shè)置Referer
curl_setopt($curl, CURLOPT_POST, 1); // 發(fā)送一個(gè)常規(guī)的Post請(qǐng)求
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); // Post提交的數(shù)據(jù)包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 設(shè)置超時(shí)限制防止死循
curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區(qū)域內(nèi)容
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳過(guò)證書(shū)檢查
$tmpInfo = curl_exec($curl); // 執(zhí)行操作
if (curl_errno($curl)) {
echo 'Errno' . curl_error($curl);
}
curl_close($curl); // 關(guān)鍵CURL會(huì)話(huà)
$tmpInfo=json_decode($tmpInfo,true);
return $tmpInfo;
}
//get請(qǐng)求
private function curl_get($url) {
//初使化curl
$curl = curl_init();
//請(qǐng)求的url,由形參傳入
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對(duì)認(rèn)證證書(shū)來(lái)源的檢測(cè)
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Expect:'
)); // 解決數(shù)據(jù)包大不能提交
//將得到的數(shù)據(jù)返回
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//不處理頭信息
curl_setopt($curl, CURLOPT_HEADER, 0);
//連接超過(guò)10秒超時(shí)
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動(dòng)跳轉(zhuǎn)
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動(dòng)設(shè)置Referer
curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區(qū)域內(nèi)容
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回
//執(zhí)行curl
$output = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Errno' . curl_error($curl);
}
//關(guān)閉資源
curl_close($curl);
//返回內(nèi)容
$tmpInfo=json_decode($output,true);
return $tmpInfo;
}
運(yùn)用平臺(tái)提供的相應(yīng)參數(shù),流程能順利走通。
4、當(dāng)放到線(xiàn)上的時(shí)候,選擇相應(yīng)的進(jìn)行上線(xiàn),首先要去平臺(tái)“我的應(yīng)用”設(shè)置回調(diào)地址,然后再授權(quán)地址上加上回調(diào)地址,還要進(jìn)行授權(quán)去獲取session,然后通過(guò)session去獲取店鋪的id
回調(diào)地址:
授權(quán)地址:
5、授權(quán)地址:
https://e.dianping.com/dz-open/merchant/auth?app_key=1ef0*****e3a8redirect_url=https://*****/admin/Dian/get_authstate=teststatescope=[%22tuangou%22]
授權(quán)地址可以獲取auth_code,根據(jù)這個(gè)值去換取session,換取session后可以去換取店鋪id
//獲取auth_code
public function get_auth(){
$auth_code = input('auth_code');
if(!isset($auth_code)) {
$app_key='1ef*****3a8';
$state='teststate';
$redirect_url='https://****/admin/Dian/get_auth';
$scope='tuangou';
$url='https://e.dianping.com/dz-open/merchant/auth?';
$data=[
'app_key' =>$app_key,
'state' => $state,
'redirect_url' =>$redirect_url,
'scope' =>$scope,
];
$postdata = http_build_query($data);
Header("Location: $url$postdata");
} else {
var_dump($auth_code);die();
}
}
//獲取session
public function get_session(){
$app_key='1ef0*****e3a8';
$app_secret='dd8a291******bd9be6ff';
$auth_code='4e027519e******a6a9d1ee5f2';
$grant_type='authorization_code';
$redirect_url='https://*****/admin/Dian/get_auth';
$data=[
'app_key' =>$app_key,
'app_secret' => $app_secret,
'redirect_url' =>$redirect_url,
'auth_code' =>$auth_code,
'grant_type' =>$grant_type
];
$postdata = http_build_query($data);
$url='https://openapi.dianping.com/router/oauth/token';
$tmpInfo=$this->curl_post($url,$postdata);
var_dump($tmpInfo);
}
//獲取所有店鋪的id
public function get_shopid(){
$app_key='1ef04*****e3a8';
$secret = "dd8a29*****fbd9be6ff"; //秘鑰
$sign_method='MD5';
$timestamp = date('Y-m-d H:i:s');
$format = 'json';
$v = 1;
//$session = 'f44d594ab895c******85b70bade02c';
$session = 'bbf7059256aaf3*******0816cf819b7';
$bid='5da1aab********5ad457a2c';//和session一起返回的
$offset =0;
$limit = 20;
$url='https://openapi.dianping.com/router/oauth/session/scope?';
$data=[
'app_key' =>$app_key,
'sign_method' => $sign_method,
'timestamp' =>$timestamp,
'format' =>$format,
'v' =>$v,
'session' =>$session,
'bid' =>$bid,
'offset' =>$offset,
'limit' =>$limit,
];
ksort($data);
$sign = $this->cal_sign($secret, $data);
$data['sign'] = $sign;
$postdata = http_build_query($data);
$tmpInfo=$this->curl_get($url.$postdata);
var_dump($tmpInfo);
}
到此這篇關(guān)于PHP 對(duì)接美團(tuán)大眾點(diǎn)評(píng)團(tuán)購(gòu)券(門(mén)票)的開(kāi)發(fā)步驟的文章就介紹到這了,更多相關(guān)PHP美團(tuán)大眾點(diǎn)評(píng)團(tuán)購(gòu)券內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- PHP與以太坊交互詳解
- php實(shí)現(xiàn)單筆轉(zhuǎn)賬到支付寶功能
- php實(shí)現(xiàn)微信企業(yè)轉(zhuǎn)賬功能
- 微信企業(yè)轉(zhuǎn)賬之入口類(lèi)分裝php代碼
- php實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能
- php7中停止php-fpm服務(wù)的方法詳解
- PHP小程序后臺(tái)部署運(yùn)行 LNMP+WNMP的方法
- 為PHP模塊添加SQL SERVER2012數(shù)據(jù)庫(kù)的步驟詳解
- php微信小程序解包過(guò)程實(shí)例詳解
- 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算
- PHP實(shí)現(xiàn)創(chuàng)建以太坊錢(qián)包轉(zhuǎn)賬等功能