對接美團外賣開放平台


 

話不多說 直接上代碼

# 再此之前 你需要在美團的外賣開放平台配置回調地址 及 推送地址。
# 注意 美團推送的時候會有get請求,如果你的項目訪問地址必帶有"?" 在配置美團的時候 需要修改你的地址,apache下 修改項目根目錄中的“.htaccess”文件;
# 例:http://xxx.com.cn/?md=mt&cl=mt&at=mt 這是你項目訪問地址,需要修改為 http://xxx.com.cn/md=mt/mt/mt.自己網上找下怎么樣配置的




 <?php

 class MTController extends commonController {

######################################################### 必接接口 訂單推送API START ########################################################
    const SANDBOX_APP_ID = '';
    const SANDBOX_APP_SECRET = '';
    const SANDBOX_URL = 'https://waimaiopen.meituan.com/api/v1/';
    const SANDBOX_STORE_ID = '';

    const APP_ID = '';
    const APP_SECRET = '';
    const URL = '';
    const STORE_ID = '';
    /**
     * 推送已確認訂單 這里你可以操作獲取訂單信息存儲數據庫等 ;該信息由美團直接POST 推送到這個配置接口地址
*/ public function MTConfirmOrderAction() { $log = new Logging(); $log->lfile('MTConfirmOrder'); if($_POST && $_POST['sig'] && count((array)$_POST) > 0){ $url_detail = urldecode($_POST['detail']); $detail = json_decode($url_detail,true); $field['order_no'] = $_POST['order_id']; $field['shop_no'] = $_POST['app_poi_code']; $field['lat'] = $_POST['latitude']; $field['lng'] = $_POST['longitude']; $field['source'] = '美團'; $field['buyer'] = urldecode($_POST['recipient_name']); $field['receiver'] = urldecode($_POST['recipient_name']); $field['receiver_tel'] = $_POST['recipient_phone']; $field['receiver_address'] = urldecode($_POST['recipient_address']); $field['customre_memo'] = urldecode($_POST['caution']); $field['actual_pay'] = $_POST['total']; $field['order_time'] = $_POST['ctime']; $field['delivery_time'] = $_POST['delivery_time']; $field['consignment_sync'] = 'Y'; $field['status'] = 0; $field['shop_name'] = $_POST['wm_poi_name']; $field['ph_no'] = 'MT'.$_POST['order_id']; $field['pos_fee'] = $_POST['shipping_fee']; $field['createdt'] = 'now()'; $OID = $this->model->addItem($field, 'orders'); $field = []; foreach ($detail as $v){ $field['orders_id'] = $OID; $field['product_no'] = $v['app_food_code']; $field['product_name'] = $v['food_name']; $field['qty'] = $v['quantity']; $field['unit_price'] = $v['price']; $field['ph_no'] = 'MT'.$_POST['order_id']; $field['createdt'] = 'now()'; $this->model->addItem($field, 'orders_product'); } } $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($_POST,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } /** * 已完成訂單推送回調 */ public function MTFinishStatusAction() { $log = new Logging(); $log->lfile('MTFinishStatus'); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($this->params,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } /** * 訂單配送狀態回調 */ public function MTOrderStatusAction() { $log = new Logging(); $log->lfile('MTOrderStatus'); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($_POST,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } /** * 推送已支付訂單 */ public function MTPushPaidOrdersAction() { $log = new Logging(); $log->lfile('MTPushPaidOrders'); $this->MTConfirmAction($_POST['order_id']); # 直接確認訂單 // $this->MTCancelAction($_POST['order_id']); # 直接取消訂單 $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($_POST,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } /** * 推送催單消息 */ public function MTReminderAction() { $log = new Logging(); $log->lfile('MTReminder'); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($_POST,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } ######################################################### 訂單推送API END ######################################################## ######################################################### 取消訂單推送API START ######################################################## /** * 推送取消訂單消息 推送用戶或客服取消訂單 */ public function MTPushCancelOrderAction() { $log = new Logging(); $log->lfile('MTPushCancelOrder'); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($this->params,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } ######################################################### 取消訂單推送API END ######################################################## ######################################################### 必接接口 訂單類API START ######################################################## /** * 商家確認訂單 */ public function MTConfirmAction($order_id) { $Config = Config::getInstance(); $webSite = $Config->getWebSiteConfig(); $APP_ID = (($webSite['debug']) ? self::SANDBOX_APP_ID : self::APP_ID); $URL = (($webSite['debug']) ? self::SANDBOX_URL : self::URL).'order/confirm'; $parameter['order_id'] = $order_id; $parameter['timestamp'] = time(); $parameter['app_id'] = $APP_ID; $log = new Logging(); $log->lfile('MTConfirm'); $sign = $this->_sign($parameter,$URL); $Result = $this->getCurl($sign); $Data = json_decode($Result, true); $log->lwrite('reception:' . json_encode($Data,JSON_UNESCAPED_UNICODE).'response:'.json_encode($parameter,JSON_UNESCAPED_UNICODE)); } /** * 推送訂單結算信息 */ public function MTOrderCloseAction() { $log = new Logging(); $log->lfile('MTOrderClose'); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($_POST,JSON_UNESCAPED_UNICODE).'response:'.json_encode($r)); echo json_encode($r); } /** * 駁回訂單退款申請 */ public function MTRejectAction($order_id,$reason) { $log = new Logging(); $log->lfile('MTReject'); $Config = Config::getInstance(); $webSite = $Config->getWebSiteConfig(); $APP_ID = (($webSite['debug']) ? self::SANDBOX_APP_ID : self::APP_ID); $URL = (($webSite['debug']) ? self::SANDBOX_URL : self::URL).'order/refund/reject'; $parameter['order_id'] = $order_id; $parameter['reason'] = $reason; $parameter['timestamp'] = time(); $parameter['app_id'] = $APP_ID; $sign = $this->_sign($parameter,$URL); $Result = $this->getCurl($sign); $Data = json_decode($Result, true); $r = ['data'=>'ok']; $log->lwrite('reception:' . json_encode($Data,JSON_UNESCAPED_UNICODE).'response:'.json_encode($parameter,JSON_UNESCAPED_UNICODE)); echo json_encode($r); } /** * 訂單確認退款請求 */ public function MTAgreeAction($order_id,$reason) { $log = new Logging(); $log->lfile('MTAgree'); $Config = Config::getInstance(); $webSite = $Config->getWebSiteConfig(); $APP_ID = (($webSite['debug']) ? self::SANDBOX_APP_ID : self::APP_ID); $URL = (($webSite['debug']) ? self::SANDBOX_URL : self::URL).'order/refund/agree'; $parameter['order_id'] = $order_id; $parameter['reason'] = $reason; $parameter['timestamp'] = time(); $parameter['app_id'] = $APP_ID; $sign = $this->_sign($parameter,$URL); $Result = $this->getCurl($sign); $Data = json_decode($Result, true); $log->lwrite('reception:' . json_encode($Data,JSON_UNESCAPED_UNICODE).'response:'.json_encode($parameter,JSON_UNESCAPED_UNICODE)); } /** * 訂單配送中 改狀態 */ public function MTAeliveringAction() { $Config = Config::getInstance(); $webSite = $Config->getWebSiteConfig(); $log = new Logging(); $log->lfile('MTAelivering'); $APP_ID = (($webSite['debug']) ? self::SANDBOX_APP_ID : self::APP_ID); $URL = (($webSite['debug']) ? self::SANDBOX_URL : self::URL).'order/delivering'; $parameter['order_id'] = '27009292362162587'; $parameter['timestamp'] = time(); $parameter['courier_name'] = '是我'; $parameter['courier_phone'] = 17321295203; $parameter['app_id'] = $APP_ID; $sign = $this->_sign($parameter,$URL); $Result = $this->getCurl($sign); $Data = json_decode($Result, true); $log->lwrite('reception:' . json_encode($Data,JSON_UNESCAPED_UNICODE).'response:'.json_encode($parameter)); } /** * 修改狀態送達 */ public function MTArrivedAction() { $Config = Config::getInstance(); $webSite = $Config->getWebSiteConfig(); $log = new Logging(); $log->lfile('MTArrived'); $APP_ID = (($webSite['debug']) ? self::SANDBOX_APP_ID : self::APP_ID); $URL = (($webSite['debug']) ? self::SANDBOX_URL : self::URL).'order/arrived'; $parameter['order_id'] = '27009292362162587'; $parameter['timestamp'] = time(); $parameter['app_id'] = $APP_ID; $sign = $this->_sign($parameter,$URL); $Result = $this->getCurl($sign); $Data = json_decode($Result, true); $log->lwrite('reception:' . json_encode($Data,JSON_UNESCAPED_UNICODE).'response:'.json_encode($parameter)); } ######################################################### 訂單類API END ######################################################## }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM