| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?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 的,执行下解密
- foreach($post as $k => $val) {
- $post[$k] = urldecode($val);
- }
- $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']);
- }
- }
|