PHP 对接美团大众点评团购券(门票)的开发步骤

吾爱主题 阅读:119 2021-11-09 15:23:00 评论:0

一、功能简要介绍

    1、根据需求,用户在美团大众点评中所购买的门票在自己的系统上可以核销,同时把核销信息存储到自己的系统里。

   2、美团点评api文档地址:https://open.dianping.com/document/v2?rootdocid=5000

二、开发步骤:

   1、用点评管家账号登录文档,相应文档说明:https://open.dianping.com/document/v2?docid=6000136&rootdocid=1000

  2 、选好自己相应的应用型,审核通过之后,就可以用平台系统的测试的数据就行接口调用

3、在大众点评app购买相应票,根据验券核销api文档(根据业务需求选择的类型是自用型)调取查询券、验券即核销券的接口,代码如下:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 //查询券、验券   public function prepare(){    // $arr 为数组 里面为应用参数    $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' ;//输码查询券    //$url = 'https://openapi.dianping.com/router/tuangou/receipt/scanprepare';//扫码查询券    //$url = 'https://openapi.dianping.com/router/tuangou/receipt/consume';//验券    $tmpinfo = $this ->curl_post( $url , $postdata );    var_dump( $tmpinfo );   }       /**    * 计算签名    *    * @param $app_secret 三方app_secret    * @param $req_param 请求参数集合,包括公共参数和业务参数    * @return string md5签名    */   function cal_sign( $app_secret , $req_param )   {    // 排序所有请求参数    ksort( $req_param );    $src_value = "" ;    // 按照key1value1key2value2...keynvaluen拼接    foreach ( $req_param as $key => $value ) {     $src_value .= ( $key . $value );    }    //计算md5    return md5( $app_secret . $src_value . $app_secret );   }     //post请求    private function curl_post( $url , $postdata ){    $curl = curl_init(); // 启动一个curl会话    curl_setopt( $curl , curlopt_url, $url ); // 要访问的地址    curl_setopt( $curl , curlopt_ssl_verifypeer, 0); // 对认证证书来源的检测    curl_setopt( $curl , curlopt_httpheader, array (     'expect:'    )); // 解决数据包大不能提交    curl_setopt( $curl , curlopt_followlocation, 1); // 使用自动跳转    curl_setopt( $curl , curlopt_autoreferer, 1); // 自动设置referer    curl_setopt( $curl , curlopt_post, 1); // 发送一个常规的post请求    curl_setopt( $curl , curlopt_postfields, $postdata ); // post提交的数据包    curl_setopt( $curl , curlopt_timeout, 30); // 设置超时限制防止死循    curl_setopt( $curl , curlopt_header, 0); // 显示返回的header区域内容    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); // 跳过证书检查    $tmpinfo = curl_exec( $curl ); // 执行操作    if (curl_errno( $curl )) {     echo 'errno' . curl_error( $curl );    }    curl_close( $curl ); // 关键curl会话    $tmpinfo =json_decode( $tmpinfo ,true);    return $tmpinfo ;   }     //get请求   private function curl_get( $url ) {    //初使化curl    $curl = curl_init();    //请求的url,由形参传入    curl_setopt( $curl , curlopt_url, $url );    curl_setopt( $curl , curlopt_ssl_verifypeer, 0); // 对认证证书来源的检测    curl_setopt( $curl , curlopt_httpheader, array (     'expect:'    )); // 解决数据包大不能提交    //将得到的数据返回    curl_setopt( $curl , curlopt_returntransfer, 1);    //不处理头信息    curl_setopt( $curl , curlopt_header, 0);    //连接超过10秒超时    curl_setopt( $curl , curlopt_timeout, 30);    curl_setopt( $curl , curlopt_http_version, curl_http_version_1_0);    curl_setopt( $curl , curlopt_followlocation, 1); // 使用自动跳转    curl_setopt( $curl , curlopt_autoreferer, 1); // 自动设置referer    curl_setopt( $curl , curlopt_header, 0); // 显示返回的header区域内容    curl_setopt( $curl , curlopt_httpheader, array ( 'content-type: application/x-www-form-urlencoded' ));    curl_setopt( $curl , curlopt_returntransfer, 1); // 获取的信息以文件流的形式返回    //执行curl    $output = curl_exec( $curl );    if (curl_errno( $curl )) {     echo 'errno' . curl_error( $curl );    }    //关闭资源    curl_close( $curl );    //返回内容    $tmpinfo =json_decode( $output ,true);    return $tmpinfo ;   }

运用平台提供的相应参数,流程能顺利走通。

4、当放到线上的时候,选择相应的进行上线,首先要去平台“我的应用”设置回调地址,然后再授权地址上加上回调地址,还要进行授权去获取session,然后通过session去获取店铺的id

回调地址:

授权地址:

5、授权地址:

https://e.dianping.com/dz-open/merchant/auth?app_key=1ef0*****e3a8&redirect_url=https://*****/admin/dian/get_auth&state=teststate&scope=[%22tuangou%22]

授权地址可以获取auth_code,根据这个值去换取session,换取session后可以去换取店铺id

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 //获取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 );   }

到此这篇关于php 对接美团大众点评团购券(门票)的开发步骤的文章就介绍到这了,更多相关php美团大众点评团购券内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/m0_37739005/article/details/115303212

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容