>, * source_rows:int, * cursor:int, * has_next:bool * } */ public function getPage( Carbon $start, Carbon $endExclusive, string $timeType, int $cursor = 0, ?int $pageSize = null, ): array { if ($start->gte($endExclusive)) { throw new RuntimeException('jushuitan_shop_promotion_fee_invalid_date_range'); } if (! in_array($timeType, ['fee_time', 'modified'], true)) { throw new RuntimeException('jushuitan_shop_promotion_fee_invalid_time_type'); } $size = min(max( $pageSize ?? (int) config('services.jushuitan.shop_promotion_fee_page_size', 100), 1, ), 100); $payload = $this->request([ 'cursor' => max($cursor, 0), 'start_time' => $start->format('Y-m-d'), 'time_type' => $timeType, 'end_time' => $endExclusive->format('Y-m-d'), 'page_size' => $size, ]); $data = is_array($payload['data'] ?? null) ? $payload['data'] : []; $records = is_array($data['data'] ?? null) ? $data['data'] : []; return [ 'records' => array_values(array_filter($records, 'is_array')), 'source_rows' => count($records), 'cursor' => max((int) ($data['cursor'] ?? $cursor), 0), 'has_next' => (bool) ($data['has_next'] ?? false), ]; } /** @param array $biz @return array */ private function request(array $biz): array { $appKey = trim((string) config('services.jushuitan.app_key')); $appSecret = trim((string) config('services.jushuitan.app_secret')); $accessToken = trim((string) config('services.jushuitan.access_token')); if ($appKey === '' || $appSecret === '' || $accessToken === '') { throw new RuntimeException('jushuitan_open_api_credentials_missing'); } $params = [ 'app_key' => $appKey, 'access_token' => $accessToken, 'timestamp' => (string) now()->timestamp, 'charset' => 'utf-8', 'version' => '2', 'biz' => json_encode( $biz, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR, ), ]; ksort($params); $signingValue = $appSecret; foreach ($params as $key => $value) { $signingValue .= $key . $value; } $params['sign'] = md5($signingValue); $baseUrl = rtrim((string) config( 'services.jushuitan.open_api_base_url', 'https://openapi.jushuitan.com', ), '/'); $path = (string) config( 'services.jushuitan.shop_promotion_fee_path', '/open/webapi/pfopen/pfopenalifee/getopenalipaypromotionfee', ); /** @var PendingRequest $request */ $request = Http::withHeaders([ 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8', ])->asForm() ->acceptJson() ->timeout(max((int) config('services.jushuitan.timeout', 20), 1)); $response = $request->post($baseUrl . '/' . ltrim($path, '/'), $params); if (! $response->successful()) { throw new RuntimeException('jushuitan_open_api_http_' . $response->status()); } $payload = $response->json(); if (! is_array($payload)) { throw new RuntimeException('jushuitan_open_api_invalid_json'); } $code = (int) ($payload['code'] ?? -1); if ($code !== 0) { $message = mb_strtolower(trim((string) ($payload['msg'] ?? $payload['message'] ?? ''))); if ($code === 140 && str_contains($message, 'app_key')) { throw new RuntimeException('jushuitan_open_api_app_key_invalid'); } throw new RuntimeException('jushuitan_open_api_code_' . $code); } return $payload; } }