MtController.php 1.9 KB

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