request->isAjax()) { $data = ExpressConfig::getInstance()->all(); $defaults = [ 'express_enable' => '1', 'express_provider' => 'aliyun', 'aliyun_appcode' => '', 'aliyun_api_url' => '', 'aliyun_api_mode' => 'auto', 'aliyun_http_method' => 'auto', 'expressbird_appcode' => '', 'cache_ttl' => '300', ]; return $this->success('操作成功', null, array_merge($defaults, $data)); } return $this->view->fetch(); } public function save() { $params = $this->request->post('row/a'); if (!$params) { $this->error('参数错误'); } $allowed = [ 'express_enable', 'express_provider', 'aliyun_appcode', 'aliyun_api_url', 'aliyun_api_mode', 'aliyun_http_method', 'expressbird_appcode', 'cache_ttl', ]; foreach ($allowed as $name) { if (!array_key_exists($name, $params)) { continue; } $exists = Db::name('shopro_aliyun_express_config')->where('name', $name)->find(); if ($exists) { Db::name('shopro_aliyun_express_config')->where('name', $name)->update(['value' => $params[$name]]); } else { Db::name('shopro_aliyun_express_config')->insert(['name' => $name, 'value' => $params[$name]]); } } ExpressConfig::reload(); $this->success('保存成功'); } public function test() { $waybillNo = trim($this->request->post('waybill_number', '')); $phone = trim($this->request->post('phone', '')); $expressCode = trim($this->request->post('express_code', '')); $provider = trim($this->request->post('express_provider', '')); if ($waybillNo === '') { $this->error('请填写快递单号'); } try { $service = new ExpressQueryService(); $normalized = $service->queryTrack($waybillNo, $phone, $expressCode, $provider ?: null, false); if (empty($normalized['success'])) { $raw = !empty($normalized['raw']) ? json_encode($normalized['raw'], JSON_UNESCAPED_UNICODE) : ''; $this->error('测试查询失败:未获取到有效轨迹' . ($raw ? ':' . mb_substr($raw, 0, 300) : '')); } $this->success('测试查询成功', null, $normalized); } catch (\think\exception\HttpResponseException $e) { throw $e; } catch (\Throwable $e) { $msg = trim($e->getMessage()); $this->error('测试查询失败:' . ($msg !== '' ? $msg : get_class($e))); } } }