|
|
|
@ -6,30 +6,28 @@ use Base\Tool\PlatformLog;
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
use Think\Log;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 天之禁2-测试资源接口
|
|
|
|
|
*/
|
|
|
|
|
class TzjClient
|
|
|
|
|
abstract class JhBaseClient
|
|
|
|
|
{
|
|
|
|
|
const SIGN_NAME = 'sign';
|
|
|
|
|
const SUCCESS = 1;
|
|
|
|
|
|
|
|
|
|
protected $baseUri;
|
|
|
|
|
protected $key;
|
|
|
|
|
protected $brAppId;
|
|
|
|
|
protected $brPCode;
|
|
|
|
|
|
|
|
|
|
protected $client;
|
|
|
|
|
|
|
|
|
|
private $apis = [
|
|
|
|
|
protected $apis = [
|
|
|
|
|
'mail' => ['url' => '/wf/m/mail/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'],
|
|
|
|
|
'prop' => ['url' => '/wf/m/prop/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'],
|
|
|
|
|
'pay' => ['url' => '/wf/m/pay/brRom/1/brPCode/{brPCode}/brAppId/{brAppId}', 'method' => 'post'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function __construct($game = null)
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->client = new Client([
|
|
|
|
|
'base_uri' => 'http://club.game.267zf.com',
|
|
|
|
|
'base_uri' => $this->baseUri,
|
|
|
|
|
'timeout' => 10.0,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
@ -112,25 +110,70 @@ class TzjClient
|
|
|
|
|
|
|
|
|
|
public function apply($order, $role)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'userId' => $role['user_id'],
|
|
|
|
|
'roleId' => $role['role_id'],
|
|
|
|
|
'serverId' => $role['server_id'],
|
|
|
|
|
'orderNum' => $order['order_no'],
|
|
|
|
|
'orderNum' => $this->generateOrderNumber($order),
|
|
|
|
|
'moneyFen' => $order['amount'],
|
|
|
|
|
'time' => time(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$refId = $order['ref_id'];
|
|
|
|
|
$api = '';
|
|
|
|
|
if ($api == 'mail') {
|
|
|
|
|
$data['mailData'] = $refId;
|
|
|
|
|
} elseif ($api == 'prop') {
|
|
|
|
|
$data['propData'] = $refId;
|
|
|
|
|
} elseif ($api == 'pay') {
|
|
|
|
|
$data['moneyFen'] = intval($order['ref_amount'] * 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function sendProps($order)
|
|
|
|
|
{
|
|
|
|
|
$props = [];
|
|
|
|
|
$order['props'] = json_decode($order['props'], true);
|
|
|
|
|
foreach ($order['props'] as $prop) {
|
|
|
|
|
$props[] = [
|
|
|
|
|
'propId' => $prop['ref_id'],
|
|
|
|
|
'count' => $prop['num'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$data = [
|
|
|
|
|
'userId' => $order['user_id'],
|
|
|
|
|
'roleId' => $order['role_id'],
|
|
|
|
|
'serverId' => $order['server_id'],
|
|
|
|
|
'orderNum' => $this->generateOrderNumber($order),
|
|
|
|
|
'propData' => $props,
|
|
|
|
|
'time' => time(),
|
|
|
|
|
];
|
|
|
|
|
$result = $this->api('prop', $data);
|
|
|
|
|
return $this->getCommonResult($result, 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $this->api($api, $data);
|
|
|
|
|
public function sendGold($gold, $order)
|
|
|
|
|
{
|
|
|
|
|
$data = [
|
|
|
|
|
'userId' => $order['user_id'],
|
|
|
|
|
'roleId' => $order['role_id'],
|
|
|
|
|
'serverId' => $order['server_id'],
|
|
|
|
|
'orderNum' => $this->generateOrderNumber($order),
|
|
|
|
|
'moneyFen' => $gold,
|
|
|
|
|
'time' => time(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$result = $this->api('pay', $data);
|
|
|
|
|
return $this->getCommonResult($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function sendEmail($giftItem, $order)
|
|
|
|
|
{
|
|
|
|
|
$data = [
|
|
|
|
|
'userId' => $order['user_id'],
|
|
|
|
|
'roleId' => $order['role_id'],
|
|
|
|
|
'serverId' => $order['server_id'],
|
|
|
|
|
'orderNum' => $this->generateOrderNumber($order, $giftItem['index']),
|
|
|
|
|
'mailData' => [$giftItem['id']],
|
|
|
|
|
'time' => time(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$result = $this->api('mail', $data);
|
|
|
|
|
return $this->getCommonResult($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getCommonResult($result) {
|
|
|
|
|
if ($result == self::SUCCESS) {
|
|
|
|
|
return [
|
|
|
|
|
'status' => true,
|
|
|
|
@ -146,47 +189,24 @@ class TzjClient
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function generateOrderNumber($order, $index = 0)
|
|
|
|
|
{
|
|
|
|
|
$length = 8 - strlen(strval($order['id']));
|
|
|
|
|
$indexLength = 3 - strlen(strval($index));
|
|
|
|
|
return date('Ymd') . str_repeat('0', $length) . $order['id'] . str_repeat('0', $indexLength) . $index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getResourceTypes($deviceType)
|
|
|
|
|
{
|
|
|
|
|
if ($deviceType == 'andriod') {
|
|
|
|
|
return [
|
|
|
|
|
['id' => 1, 'name' => '邮件', 'device_type' => 'andriod'],
|
|
|
|
|
['id' => 2, 'name' => '道具', 'device_type' => 'andriod'],
|
|
|
|
|
['id' => 3, 'name' => '元宝', 'device_type' => 'andriod'],
|
|
|
|
|
];
|
|
|
|
|
} elseif ($deviceType == 'ios') {
|
|
|
|
|
return [
|
|
|
|
|
['id' => 1, 'name' => '邮件', 'device_type' => 'andriod'],
|
|
|
|
|
['id' => 2, 'name' => '道具', 'device_type' => 'andriod'],
|
|
|
|
|
['id' => 3, 'name' => '元宝', 'device_type' => 'andriod'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getResources($typeId, $deviceType)
|
|
|
|
|
{
|
|
|
|
|
if ($typeId == 3) {
|
|
|
|
|
return [
|
|
|
|
|
1 => ['ref_id' => 1, 'name' => '6元宝', 'amount' => 6],
|
|
|
|
|
2 => ['ref_id' => 2, 'name' => '30元宝', 'amount' => 30],
|
|
|
|
|
3 => ['ref_id' => 3, 'name' => '98元宝', 'amount' => 98],
|
|
|
|
|
// 4 => ['ref_id' => 4, 'name' => '128元宝', 'amount' => 128],
|
|
|
|
|
5 => ['ref_id' => 5, 'name' => '198元宝', 'amount' => 198],
|
|
|
|
|
6 => ['ref_id' => 6, 'name' => '328元宝', 'amount' => 328],
|
|
|
|
|
7 => ['ref_id' => 7, 'name' => '648元宝', 'amount' => 648],
|
|
|
|
|
8 => ['ref_id' => 8, 'name' => '1000元宝', 'amount' => 1000],
|
|
|
|
|
9 => ['ref_id' => 9, 'name' => '2000元宝', 'amount' => 2000],
|
|
|
|
|
// 10 => ['ref_id' => 10, 'name' => '3000元宝', 'amount' => 3000],
|
|
|
|
|
11 => ['ref_id' => 11, 'name' => '5000元宝', 'amount' => 5000],
|
|
|
|
|
// 12 => ['ref_id' => 12, 'name' => '10000元宝', 'amount' => 10000],
|
|
|
|
|
// 13 => ['ref_id' => 13, 'name' => '20000元宝', 'amount' => 20000],
|
|
|
|
|
];
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function log($message, $level = Log::INFO) {
|
|
|
|
|
PlatformLog::write($message, 'game_api/tzj', $level);
|
|
|
|
|
protected function log($message, $level = Log::INFO) {
|
|
|
|
|
PlatformLog::write($message, 'game_api/jh_base', $level);
|
|
|
|
|
}
|
|
|
|
|
}
|