PHP Thinkphp5.0对接美团API接口 实现卡卷核销功能

好久没有更新文章了。不知道关注我的小伙伴们是不是已经不在关注我了。最近在忙着一些推广运营的事情,所以没有更新,
这几天接到一个项目,需要对接美团API接口,实现核销功能。现在就来给大家展示具体代码,

/* @FunctionDesc:美团卡卷 查询、验券(核销),撤销验券
   * @Params:  qr_code 卡券券码
   *           open_shop_uuid 店铺id (根据session值 获取得到)
   *           deal_id 套餐id 查询接口获得
   *           type 功能类型 值为 save 验券(核销)、值为 cancel 验券(核销)、其他值时为查询
   * */
  public function tuangou_hexiao(){
   
   
    //
    $qr_cpde = $_GET['qr_code'];
    $open_shop_uuid = $_GET['open_shop_uuid'];
 
    // $arr 为数组 里面为应用参数
    $appKey = "111111111";
    $secret = "11111111111111111"; //秘钥
    $timestamp = date('Y-m-d H:i:s');
    $format = 'json';
    $v = 1;
    $sign_method = 'MD5';
    //因为功能要实现在小程序,所以获取的必要信息要存在文件中,有必要时拿出来
    //不是必要行为,
    $file = $this->readFile();
 
    $data = [
      'app_key' => $appKey,
      'timestamp' => $timestamp,
      'sign_method' => $sign_method,
      'format' => $format,
      'v' => $v,
      //此处的session值,我原本是存在文件中的,
      //如果你不需要存文件,那你就当做参数传递过来
      'session' => $file['session'],
    ];
    //根据不同的操作类型配置不同的参数
    //具体参数含义见 https://open.dianping.com/document/v2?docId=6000176&rootDocId=5000
    if($_GET['type']=='save'){
   
   
      $arr = [
        'requestid' => '123',
        'count'=>1,
        'receipt_code' => $qr_cpde,
        'open_shop_uuid' => $open_shop_uuid,
        'app_shop_account' => '账号',
        'app_shop_accountname' => '账号名称',
      ];
      $url = 'https://openapi.dianping.com/router/tuangou/receipt/consume';//验券(核销)
    }elseif ($_GET['type']=='cancel'){
   
   
       $arr = [
          'app_deal_id' => $_GET['deal_id'],
          'receipt_code' => $qr_cpde,
          'open_shop_uuid' => $open_shop_uuid,
          'app_shop_account' => '账号',
          'app_shop_accountname' => '账号名称',
        ];
      $url = 'https://openapi.dianping.com/router/tuangou/receipt/reverseconsume';//撤销
    }else{
   
   
      $arr = [
        'receipt_code' => $qr_cpde,
        'open_shop_uuid' => 
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

于先生吖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值