Skip to content

Commit

Permalink
remove session
Browse files Browse the repository at this point in the history
  • Loading branch information
virbo committed Nov 18, 2021
1 parent c0f65cb commit 577c2d3
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions src/Feeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace virbo\wsfeeder;

use Yii;
use yii\base\Component;
use yii\helpers\ArrayHelper;
use yii\httpclient\client;
use yii\web\BadRequestHttpException;
use yii\helpers\Json;
use yii\web\Response;

/**
* just simple configuration as component
Expand Down Expand Up @@ -110,7 +108,7 @@ public function actFeeder($data = [])
$data = ArrayHelper::merge($data, $token);

$request = $this->_client->createRequest()
->setUrl('/'.$mode)
->setUrl('/' . $mode)
->addHeaders(['content-type' => $this->contentType])
->setContent(Json::encode($data))
->setMethod($this->method)
Expand All @@ -124,7 +122,7 @@ public function actFeeder($data = [])
if ($request->data['error_code'] == 100) {
$this->getToken($renew = true);
} else {
throw new BadRequestHttpException('Error '.$request->data['error_code'].' - '.$request->data['error_desc']);
throw new BadRequestHttpException('Error ' . $request->data['error_code'] . ' - ' . $request->data['error_desc']);
}
}
} else {
Expand All @@ -134,39 +132,29 @@ public function actFeeder($data = [])

protected function getToken($renew = false)
{
$session = Yii::$app->session;

if ($session['token'] === null || $renew) {
$act = Json::encode([
'act' => 'GetToken',
'username' => $this->username,
'password' => $this->password
]);

$mode = $this->mode == 0 ? 'live2.php' : 'sandbox2.php';

$request = $this->_client->createRequest()
->setUrl($mode)
->addHeaders(['content-type' => $this->contentType])
->setContent($act)
->setMethod($this->method)
->send();

if ($request) {
if ($request->data['error_code'] == 0) {
//$this->_token = $request->data['data']['token'];
$session['token'] = $request->data['data']['token'];
} else {
throw new BadRequestHttpException('Error '.$request->data['error_code'].' - '.$request->data['error_desc']);
}
$act = Json::encode([
'act' => 'GetToken',
'username' => $this->username,
'password' => $this->password
]);

$mode = $this->mode == 0 ? 'live2.php' : 'sandbox2.php';

$request = $this->_client->createRequest()
->setUrl($mode)
->addHeaders(['content-type' => $this->contentType])
->setContent($act)
->setMethod($this->method)
->send();

if ($request) {
if ($request->data['error_code'] == 0) {
$this->_token = $request->data['data']['token'];
} else {
throw new BadRequestHttpException();
throw new BadRequestHttpException('Error ' . $request->data['error_code'] . ' - ' . $request->data['error_desc']);
}

$this->_token = $session['token'];
} else {
$this->_token = $session['token'];
throw new BadRequestHttpException();
}
}

}

0 comments on commit 577c2d3

Please sign in to comment.