Commit bcae8583 authored by shajiaiming's avatar shajiaiming

请求托管时增加校验

parent 674ffd86
......@@ -8,10 +8,15 @@ use common\helpers\Curl;
class TrusteeShipService
{
private $node_params;
private $header;
public function __construct($parameter = [])
public function __construct($parameter = [], $header = [])
{
$platform_id = Yii::$app->request->getPlatformId();
if (!empty($header)) {
$this->header = $header;
}
if (empty($parameter)) {
$this->node_params = Yii::$app->params['trusteeship']['node_' . $platform_id]['url'];
} else {
......@@ -25,16 +30,17 @@ class TrusteeShipService
}
public function send($method = 'GET', $uri, $params = [], $headers = [])
public function send($method = 'GET', $uri, $params = [])
{
$ch = new Curl();
if(!empty($headers)){
$ch->setHeaders($headers);
if (!empty($this->header)) {
$ch->setHeaders($this->header);
}
if (!empty($params)) {
$ch->setGetParams($params);
}
$result = $ch->$method($this->urlBuild($uri), false);
if (!$result) {
return ['code' => -1, 'msg' => $ch->errorText];
......@@ -57,21 +63,7 @@ class TrusteeShipService
{
$uri = 'backend/account/wallet-balance';
$time = time();
$platform_id = Yii::$app->request->getPlatformId();
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id];
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
return $this->send("GET", $uri, $params, $headers);
return $this->send("GET", $uri, $params);
}
public function getUserAsset($params = [])
......@@ -81,12 +73,5 @@ class TrusteeShipService
return $this->send("GET", $uri, $params);
}
protected function getSign($params, $appkey, $appSecret, $time)
{
ksort($params);
$string = http_build_query($params);
$result = md5($appkey . $string . $appSecret . $time);
$sign = strtoupper($result);
return $sign;
}
}
......@@ -322,4 +322,14 @@ class BaseController extends Controller
}
return $params;
}
protected function getSign($params, $appkey, $appSecret, $time)
{
ksort($params);
$string = http_build_query($params);
$result = md5($appkey . $string . $appSecret . $time);
$sign = strtoupper($result);
return $sign;
}
}
\ No newline at end of file
......@@ -155,7 +155,19 @@ class UserController extends BaseController
'end_time' => $end_time
];
$service = new TrusteeShipService($node_params);
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getUserList($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
......
......@@ -53,7 +53,19 @@ class WalletController extends BaseController
'size' => $size,
'currency' => $currency
];
$service = new TrusteeShipService($node_params);
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getWalletBalance($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
......@@ -69,11 +81,24 @@ class WalletController extends BaseController
$params = [
'uid' => $uid
];
$service = new TrusteeShipService($node_params);
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getUserAsset($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
}
return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success'];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment