<?php
namespace app\shared\controller;
//美团
use Meituan\Dianping;
class Meituan
{
	//获取auth_code
   private $api_url="https://openapi.dianping.com/router";
   private $appkey="370926cf832f39e3";
   private $secret="a10badba03f3cb7a4c00ba28a5c160e3dfaaa137";
   public function get_auth(){
		  $auth_code = input('auth_code');
		  if(!isset($auth_code)) {
			   $app_key=$this->appkey;
			   $state='teststate';
			   $redirect_url=request()->domain().request()->url();
			   $scope=["tuangou"];
			   $url='https://e.dianping.com/dz-open/merchant/auth?';
			   $data=[
			    'app_key' =>$this->appkey,
			    'state' => $state,
			    'redirect_url' =>urlencode($redirect_url),
			    'scope' =>$scope,
			   ];
			   $postdata = http_build_query($data);
			   // p("$url$postdata");
			   // die;
			   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);
	 }

}