| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace hd\controllers;
- use bizHd\meituan\classes\MtOrderClass;
- use common\components\arrayUtil;
- use Yii;
- use Abbotton\MeituanTakeaway\Application;
- use yii\helpers\Json;
- class MtController extends PublicController
- {
- public $guestAccess = [];
- private $config = [
- 'app_id' => '119094',
- 'app_secret' => 'b7e86d768391180f805621b40ec31e33',
- 'request_url' => '', // 默认 `https://waimaiopen.meituan.com/api/v1/`
- ];
- public function actionApi()
- {
- echo '开发中...';
- }
- public function actionNewOrder()
- {
- $post = Yii::$app->request->post();
- if(empty($post)) { // 无数据过来时,是美团对接口进行存活试探,请保留此段代码,好让请求在此被中断返回
- return Json::encode(['data' => 'ok']);
- }
- // 美团传入的订单数据,中文是 URL_encode 的,执行下解密
- $post = urldecode(json_encode($post));
- $post = json_decode($post, true);
- $data = arrayUtil::humpUnderlineConversion($post, 1);
- $mtOrder = MtOrderClass::add($data);
- return Json::encode(['data' => 'ok']);
- $app = new Application($this->config);
- $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
- $orderDetail = $app->order->getOrderDetail($params);
- print_r(json_decode($orderDetail, true));
- // 商品类、活动类接口支持异步队列
- $app->goods->async()->create([]);
- }
- public function actionCancelOrder()
- {
- $post = Yii::$app->request->post();
- if(!empty($post)) {
- Yii::warning('cancelOrder: ' . urldecode(json_encode($post)));
- }
- $get = Yii::$app->request->get();
- if(!empty($get)) {
- Yii::warning('cancelOrder: ' . json_encode($get));
- }
- return Json::encode(['data' => 'ok']);
- }
- }
|