generateMerchantAuthUrl($this->mainId, $redirectUrl); // 重定向用户 header('Location: ' . $authUrl); } // 获取多个平台报价 public function actionAllPlatformPrice() { $ds = new DispatchService(); $orderData = [ 'city_name' => '北京市', 'sender' => [ 'from_address' => '东升科技国际园', 'from_address_detail' => '2层202', 'from_sender_name' => '小闪', 'from_mobile' => '13800000000', 'from_latitude' => '40.047858', 'from_longitude' => '116.378424', ], 'receiver_list' => [ [ 'order_no' => 'C1119A000013053981', 'to_address' => '永泰庄地铁站', 'to_address_detail' => '1楼', 'to_receiver_name' => '小送', 'to_mobile' => '13800000001', 'to_latitude' => '40.043612', 'to_longitude' => '116.361199', 'good_type' => 5, // 物品类型 'weight' => 2, // 物品重量(kg,整数) 'remarks' => '', // 备注 ] ], 'appoint_type' => 0, // 0: 立即单,1: 预约单 'appointment_date' => '', // 预约时间 yyyy-MM-dd HH:mm 'store_id' => 393549, // 店铺ID 'travel_way' => 0, // 指定交通工具,0: 不限交通方式 'delivery_type' => 1, // 1: 帮我送,2: 帮我取 'expect_start_time' => null, // 期望送达时间起始(毫秒级时间戳) 'expect_end_time' => null, // 期望送达时间终止(毫秒级时间戳) ]; $re = $ds->getBestPlatformByPrice($orderData); return $re; } // 创建订单(发单) // 查询订单(查单) // 第三方回调入口 /** * 回调接口 */ public function actionCallback() { $callbackData = Yii::$app->request->post(); if (empty($callbackData)) { $postStr = file_get_contents('php://input'); $callbackData = json_decode($postStr, true); if (empty($callbackData)) { util::fail('回调请求的数据为空'); } } // 从配置中获取安全token // $token = Yii::$app->params['wx_intracity_token'] ?? 'your_token_here'; // $result = IntraCityExpress::handleOrderCallback($callbackData, $token); // 记录回调日志 Yii::info('聚合配送回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'delivery'); $code = $callbackData['code']; $state = $callbackData['state']; $shopId = $callbackData['shopId']; $isAllStoreAuth = $callbackData['isAllStoreAuth']; $thirdStoreId = $callbackData['thirdStoreId']; $storeId = $callbackData['storeId']; // 验证state参数(防止CSRF) //if ($state != $yourUserId) { //throw new \yii\web\BadRequestHttpException('Invalid state parameter'); //} // 获取AccessToken $auth = new \common\components\delivery\platform\shanSong\Auth(); $result = $auth->getAccessToken($code); if (!$result['success']) { throw new \yii\web\HttpException(500, '获取授权失败:' . $result['error']); } // 保存授权信息到数据库 $data['user_id'] = $state; $data['shop_id'] = $shopId; $data['access_token'] = $result['access_token']; $data['refresh_token'] = $result['refresh_token']; $data['expires_at'] = time() + $result['expires_in']; $data['auth_type'] = $isAllStoreAuth ? 'all_store' : 'single_store'; if (!$isAllStoreAuth) { $data['third_store_id'] = $thirdStoreId; $data['shans_store_id'] = $storeId; } ShansAuthTokenClass::add($data); if (false) { throw new \yii\web\HttpException(500, '保存授权信息失败'); } //return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']); return $this->redirect(['success']); } }