MtController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace hd\controllers;
  3. use Yii;
  4. use Abbotton\MeituanTakeaway\Application;
  5. use yii\helpers\Json;
  6. class MtController extends PublicController
  7. {
  8. public $guestAccess = [];
  9. private $config = [
  10. 'app_id' => '119094',
  11. 'app_secret' => 'b7e86d768391180f805621b40ec31e33',
  12. 'request_url' => '', // 默认 `https://waimaiopen.meituan.com/api/v1/`
  13. ];
  14. public function actionApi()
  15. {
  16. echo '开发中...';
  17. }
  18. public function actionNewOrder()
  19. {
  20. Yii::info('本框架输出的中文会不会乱码');
  21. $post = Yii::$app->request->post();
  22. if(!empty($post)) {
  23. Yii::warning('newOrder: ' . urldecode(json_encode($post)));
  24. }
  25. $get = Yii::$app->request->get();
  26. if(!empty($get)) {
  27. Yii::warning('newOrder: ' . json_encode($get));
  28. }
  29. return Json::encode(['data' => 'ok']);
  30. $app = new Application($this->config);
  31. $params = ['order_id' => '27061900338318741', 'is_mt_logistics' => 1];
  32. $orderDetail = $app->order->getOrderDetail($params);
  33. print_r(json_decode($orderDetail, true));
  34. // 商品类、活动类接口支持异步队列
  35. $app->goods->async()->create([]);
  36. }
  37. public function actionCancelOrder()
  38. {
  39. $post = Yii::$app->request->post();
  40. if(!empty($post)) {
  41. Yii::warning('cancelOrder: ' . urldecode(json_encode($post)));
  42. }
  43. $get = Yii::$app->request->get();
  44. if(!empty($get)) {
  45. Yii::warning('cancelOrder: ' . json_encode($get));
  46. }
  47. return Json::encode(['data' => 'ok']);
  48. }
  49. }