MtController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\meituan\classes\MtOrderClass;
  4. use Yii;
  5. use Abbotton\MeituanTakeaway\Application;
  6. use yii\helpers\Json;
  7. class MtController extends PublicController
  8. {
  9. public $guestAccess = [];
  10. private $config = [
  11. 'app_id' => '119094',
  12. 'app_secret' => 'b7e86d768391180f805621b40ec31e33',
  13. 'request_url' => '', // 默认 `https://waimaiopen.meituan.com/api/v1/`
  14. ];
  15. public function actionApi()
  16. {
  17. echo '开发中...';
  18. }
  19. public function actionNewOrder()
  20. {
  21. $post = Yii::$app->request->post();
  22. if(empty($post)) { // 无数据过来时,是美团对接口进行存活试探
  23. return Json::encode(['data' => 'ok']);
  24. }
  25. $mtOrder = MtOrderClass::add($post);
  26. return Json::encode(['data' => 'ok']);
  27. $app = new Application($this->config);
  28. $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
  29. $orderDetail = $app->order->getOrderDetail($params);
  30. print_r(json_decode($orderDetail, true));
  31. // 商品类、活动类接口支持异步队列
  32. $app->goods->async()->create([]);
  33. }
  34. public function actionCancelOrder()
  35. {
  36. $post = Yii::$app->request->post();
  37. if(!empty($post)) {
  38. Yii::warning('cancelOrder: ' . urldecode(json_encode($post)));
  39. }
  40. $get = Yii::$app->request->get();
  41. if(!empty($get)) {
  42. Yii::warning('cancelOrder: ' . json_encode($get));
  43. }
  44. return Json::encode(['data' => 'ok']);
  45. }
  46. }