'https://openapi.alipay.com/gateway.do?charset=utf-8', Pay::MODE_SANDBOX => 'https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8', Pay::MODE_SERVICE => 'https://openapi.alipay.com/gateway.do?charset=utf-8', ]; /** * @return null|array|Collection|MessageInterface * * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function __call(string $shortcut, array $params) { $plugin = '\\Yansongda\\Pay\\Plugin\\Alipay\\Shortcut\\'. Str::studly($shortcut).'Shortcut'; return $this->call($plugin, ...$params); } /** * @param array|string $order * * @return array|Collection * * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function find($order) { $order = is_array($order) ? $order : ['out_trade_no' => $order]; Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('query', [$order]); } /** * @param array|string $order * * @return array|Collection * * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function cancel($order) { $order = is_array($order) ? $order : ['out_trade_no' => $order]; Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('cancel', [$order]); } /** * @param array|string $order * * @return array|Collection * * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function close($order) { $order = is_array($order) ? $order : ['out_trade_no' => $order]; Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('close', [$order]); } /** * @return array|Collection * * @throws ContainerException * @throws InvalidParamsException * @throws ServiceNotFoundException */ public function refund(array $order) { Event::dispatch(new Event\MethodCalled('alipay', __METHOD__, $order, null)); return $this->__call('refund', [$order]); } /** * @param null|array|ServerRequestInterface $contents * * @throws ContainerException * @throws InvalidParamsException */ public function callback($contents = null, ?array $params = null): Collection { $request = $this->getCallbackParams($contents); Event::dispatch(new Event\CallbackReceived('alipay', $request->all(), $params, null)); return $this->pay( [CallbackPlugin::class], $request->merge($params)->all() ); } public function success(): ResponseInterface { return new Response(200, [], 'success'); } public function mergeCommonPlugins(array $plugins): array { return array_merge( [PreparePlugin::class], $plugins, [RadarSignPlugin::class], [LaunchPlugin::class, ParserPlugin::class], ); } /** * @param null|array|ServerRequestInterface $contents */ protected function getCallbackParams($contents = null): Collection { if (is_array($contents)) { return Collection::wrap($contents); } if ($contents instanceof ServerRequestInterface) { return Collection::wrap('GET' === $contents->getMethod() ? $contents->getQueryParams() : $contents->getParsedBody()); } $request = ServerRequest::fromGlobals(); return Collection::wrap( array_merge($request->getQueryParams(), $request->getParsedBody()) ); } }