You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
5.1 KiB
PHP
163 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace Base\Tool\GameResource;
|
|
|
|
use Base\Tool\Log;
|
|
use GuzzleHttp\Client;
|
|
|
|
/**
|
|
* 逍遥游-测试资源接口
|
|
*/
|
|
class XyyClient
|
|
{
|
|
const SIGN_NAME = 'sign';
|
|
const SUCCESS = '0000';
|
|
|
|
const SIGN_KEY = '51a447dc409b785af03e41a2d5014879';
|
|
|
|
protected $client;
|
|
private $platformId = 600;
|
|
|
|
private $apis = [
|
|
'provide' => ['uri' => '/Api/Statis/sendgold', 'method' => 'post'],
|
|
];
|
|
|
|
public function __construct($game = null)
|
|
{
|
|
if ($game && ($game['id'] == 293 || $game['id'] == 294)) {
|
|
$this->platformId = 602;
|
|
} else {
|
|
$this->platformId = 600;
|
|
}
|
|
$this->client = new Client([
|
|
'base_uri' => 'http://x3wm.dgcgame.com:82',
|
|
'timeout' => 10.0,
|
|
]);
|
|
}
|
|
|
|
public function api($name, array $params = [])
|
|
{
|
|
$api = $this->apis[$name] ?? null;
|
|
if (is_null($api)) {
|
|
throw new \Exception('接口不存在');
|
|
}
|
|
$params[self::SIGN_NAME] = $this->sign($params);
|
|
try {
|
|
return $this->request($api, $params);
|
|
} catch (\Exception $e) {
|
|
$env = C('APP_ENV', null, 'prod');
|
|
Log::error('ts:XYY ' . $e->getMessage());
|
|
return ['code' => 3, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
|
|
}
|
|
}
|
|
|
|
public function request($api, $params)
|
|
{
|
|
if ($api['method'] == 'get') {
|
|
return $this->get($api['uri'], $params);
|
|
} else {
|
|
return $this->post($api['uri'], $params);
|
|
}
|
|
}
|
|
|
|
protected function post($uri, array $params = [])
|
|
{
|
|
$response = $this->client->post($uri, [
|
|
'verify' => false,
|
|
'form_params' => $params,
|
|
]);
|
|
$result = (string)$response->getBody();
|
|
Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
|
|
return json_decode($result, true);
|
|
}
|
|
|
|
protected function get($uri, array $params = [])
|
|
{
|
|
$response = $this->client->get($uri, [
|
|
'verify' => false,
|
|
'query' => $params,
|
|
]);
|
|
$result = (string)$response->getBody();
|
|
Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
|
|
return json_decode($result, true);
|
|
}
|
|
|
|
protected function sign($params)
|
|
{
|
|
$signStr =
|
|
$params['actors'] .
|
|
$params['pfrom_id'] .
|
|
$params['server_id'] .
|
|
$params['sendnum_yb'] .
|
|
$params['sendnum_by'] .
|
|
urlencode($params['email_title']) .
|
|
urlencode($params['email_content']) .
|
|
self::SIGN_KEY .
|
|
$params['time'].
|
|
$params['type'];
|
|
return md5($signStr);
|
|
}
|
|
|
|
private function getCommonResult($result)
|
|
{
|
|
if ($result['code'] == 0) {
|
|
return [
|
|
'status' => true,
|
|
'message' => $result['msg'],
|
|
'result' => $result
|
|
];
|
|
} else {
|
|
return [
|
|
'status' => false,
|
|
'message' => $result['msg'],
|
|
'result' => $result
|
|
];
|
|
}
|
|
}
|
|
|
|
public function apply($order, $role)
|
|
{
|
|
$data = [
|
|
'pfrom_id' => $this->platformId,
|
|
'server_id' => $role['server_id'],
|
|
'actors' => $role['role_id'],
|
|
'sendnum_yb' => intval($order['ref_amount']) * 10,
|
|
'sendnum_by' => 0,
|
|
'email_title' => '扶持元宝',
|
|
'email_content' => '请查收',
|
|
'time' => time(),
|
|
'type' => 0,
|
|
// 'rebate' => 2,
|
|
];
|
|
$result = $this->api('provide', $data);
|
|
return $this->getCommonResult($result);
|
|
}
|
|
|
|
public function getResourceTypes($deviceType)
|
|
{
|
|
if ($deviceType == 'andriod') {
|
|
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
|
|
} elseif ($deviceType == 'ios') {
|
|
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
|
|
}
|
|
}
|
|
|
|
public function getResources($typeId, $deviceType)
|
|
{
|
|
return [
|
|
1 => ['ref_id' => 1, 'name' => '60元宝', 'amount' => 6],
|
|
2 => ['ref_id' => 2, 'name' => '300元宝', 'amount' => 30],
|
|
3 => ['ref_id' => 3, 'name' => '980元宝', 'amount' => 98],
|
|
4 => ['ref_id' => 4, 'name' => '1280元宝', 'amount' => 128],
|
|
5 => ['ref_id' => 5, 'name' => '1980元宝', 'amount' => 198],
|
|
6 => ['ref_id' => 6, 'name' => '3280元宝', 'amount' => 328],
|
|
7 => ['ref_id' => 7, 'name' => '6480元宝', 'amount' => 648],
|
|
8 => ['ref_id' => 8, 'name' => '10000元宝', 'amount' => 1000],
|
|
9 => ['ref_id' => 9, 'name' => '20000元宝', 'amount' => 2000],
|
|
10 => ['ref_id' => 10, 'name' => '30000元宝', 'amount' => 3000],
|
|
11 => ['ref_id' => 11, 'name' => '50000元宝', 'amount' => 5000],
|
|
12 => ['ref_id' => 12, 'name' => '100000元宝', 'amount' => 10000],
|
|
13 => ['ref_id' => 13, 'name' => '200000元宝', 'amount' => 20000],
|
|
];
|
|
}
|
|
} |