request->post('currency', ''); $base_currency = Yii::$app->request->post('base_currency', ''); $exchange = Yii::$app->request->post("exchange", 'Zhaobi'); if (false == $currency || false == $base_currency) { $msg = 'invalid symbol'; $code = -1; goto doEnd; } $builder = ExchangeBuilderFactory::create('Zhaobi'); $result = $builder->getDetail(strtoupper($currency), strtoupper($base_currency)); if (-1 == $result['code']) { $msg = 'invalid symbol'; $code = -1; goto doEnd; } $code = 0; $msg = 'ok'; $ticker = $result['ticker']; doEnd : return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; } public function actionIndex() { $currency = Yii::$app->request->post('currency', ''); $base_currency = Yii::$app->request->post('base_currency', ''); $exchange = Yii::$app->request->post("exchange", 'Zhaobi'); $base_exchange = Yii::$app->request->post("base_exchange", 'Zhaobi'); if (false == $currency || false == $base_currency) { $msg = 'invalid symbol'; $code = -1; goto doEnd; } $exchange = ExchangeFactory::createExchange($exchange); $quotation = $exchange->getTicker($currency); $quotation = [ 'low' => (float)sprintf("%0.4f", $quotation['low'] / 100), 'high' => (float)sprintf("%0.4f", $quotation['high'] / 100), 'last' => (float)sprintf("%0.4f", $quotation['last'] / 100), 'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100), ]; echo json_encode($quotation);exit; $base_exchange = ExchangeFactory::createExchange($base_exchange); $base_quotation = $base_exchange->getTicker($base_currency); $base_quotation = [ 'low' => (float)sprintf("%0.4f", $base_quotation['low'] / 100), 'high' => (float)sprintf("%0.4f", $base_quotation['high'] / 100), 'last' => (float)sprintf("%0.4f", $base_quotation['last'] / 100), 'rmb' => (float)sprintf("%0.2f", $base_quotation['last'] / 100), ]; $builder = ExchangeBuilderFactory::create('Zhaobi'); $result = $builder->getDetail(strtoupper($currency), strtoupper($base_currency)); if (-1 == $result['code']) { $msg = 'invalid symbol'; $code = -1; goto doEnd; } $code = 0; $msg = 'ok'; $ticker = $result['ticker']; doEnd : return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; } }