send($model); if (!empty($resp->getError())) throw new \Exception($resp->getError()); // 如果code不为0 if ((!empty($model) && $validResp) && !empty($resp->respError())) throw new \Exception($resp->respError()); return $resp; } catch (\Exception $e) { \Yii::error(FormatHelper::exception($e, __METHOD__)); $msg = explode(" rid: ", $e->getMessage()); throw new \Exception($msg[0] ?? '未知错误'); } } /** * @param RequestInterface $request * @param ModelInterface|null $model * @param bool $validResp * @return array * @throws \Exception */ public static function toArray(RequestInterface $request, ModelInterface $model = null, bool $validResp = true) { return self::execute($request, $model, $validResp)->toArray(); } /** * @param RequestInterface $request * @param ModelInterface|null $model * @param bool $validResp * @return array * @throws \Exception */ public static function accessTokenAndToArray(RequestInterface $request, ModelInterface $model = null, bool $validResp = true) { return self::execute($request->accessToken(), $model, $validResp)->toArray(); } /** * @param RequestInterface $request * @param ModelInterface|null $model * @param bool $validResp * @return mixed * @throws \Exception */ public static function accessTokenRawContent(RequestInterface $request, ModelInterface $model = null, bool $validResp = true) { return self::execute($request->accessToken(), $model, $validResp)->getRawContent(); } }