Merge pull request '一剑斩仙' (#634) from hotfix/center into master
Reviewed-on: http://8.136.139.249:3000/wmtx/platform/pulls/634master
commit
bbc2c75ed0
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool\GameResource;
|
||||
|
||||
use Base\Tool\Log;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* 一剑斩仙-测试资源接口
|
||||
*/
|
||||
class YjzxClient
|
||||
{
|
||||
const SIGN_NAME = 'sign';
|
||||
const SIGN_KEY = 'nmjf65532qavdfsdq962dddsddfsaffd';
|
||||
|
||||
protected $client;
|
||||
protected $baseUrl = 'http://rebate.99you.cn';
|
||||
|
||||
private $apis = [
|
||||
'send-gold' => ['uri' => '/wmtx_apply.php/23510/', 'method' => 'get', 'with' => [
|
||||
'act' => 'sendgold'
|
||||
]],
|
||||
'send-email' => ['uri' => '/wmtx_apply.php/23510/', 'method' => 'get', 'with' => [
|
||||
'act' => 'send_email'
|
||||
]],
|
||||
];
|
||||
|
||||
public function __construct($game = null)
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => $this->baseUrl,
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function api($api, array $params = [])
|
||||
{
|
||||
$tmpApi = $api;
|
||||
$api = $this->apis[$api] ?? null;
|
||||
if (is_null($api)) {
|
||||
throw new \Exception('接口不存在');
|
||||
}
|
||||
$params[self::SIGN_NAME] = $this->sign($tmpApi, $params);
|
||||
if (is_array($api['with'])) {
|
||||
$params = array_merge($params, $api['with']);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->request($api, $params);
|
||||
} catch (\Exception $e) {
|
||||
$env = C('APP_ENV', null, 'prod');
|
||||
Log::error('Yjzx ' . $e->getMessage());
|
||||
return ['status' => 0, '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('Yjzx ' . 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('Yjzx ' . json_encode($params) . ' ' . $result);
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function sign($name, $params)
|
||||
{
|
||||
if (in_array($name, ['send-gold', 'send-email'])) {
|
||||
return md5(
|
||||
$params['orderid'] .
|
||||
$params['serverid'] .
|
||||
$params['role_id'] .
|
||||
static::SIGN_KEY
|
||||
);
|
||||
} elseif ($name == 'send-testing') {
|
||||
return md5(
|
||||
$params['appId'] .
|
||||
$params['orderNum'] .
|
||||
$params['userId'] .
|
||||
$params['moneyYuan'] .
|
||||
$params['serviceId'] .
|
||||
$params['roleId'] .
|
||||
$params['time'] .
|
||||
static::SIGN_KEY
|
||||
);
|
||||
} elseif ($name == 'send-props') {
|
||||
$signStr = '';
|
||||
ksort($params);
|
||||
foreach ($params as $key => $value) {
|
||||
if ($key == 'prop') {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
$signStr .= $key . '='. trim(urlencode($value)) . '&';
|
||||
}
|
||||
$signStr .= 'key=' . static::SIGN_KEY;
|
||||
$signStr = md5($signStr);
|
||||
return $signStr;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// 测试资源
|
||||
public function apply($order, $role)
|
||||
{
|
||||
$result = $this->api('send-gold', [
|
||||
'role_id' => $role['role_id'],
|
||||
'amount' => $order['ref_amount'],
|
||||
'serverid' => $role['server_id'],
|
||||
'uid' => $role['user_id'],
|
||||
'orderid' => $order['order_no']
|
||||
]);
|
||||
if ($result['code'] == 1) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result ?? []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public function sendGold($order, $role)
|
||||
{
|
||||
$result = $this->api('send-gold', [
|
||||
'role_id' => $role['role_id'],
|
||||
'amount' => $order['ref_amount'],
|
||||
'serverid' => $role['server_id'],
|
||||
'uid' => $role['user_id'],
|
||||
'orderid' => $order['order_no']
|
||||
]);
|
||||
if ($result['code'] == 1) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result ?? []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function sendEmail($giftItem, $order)
|
||||
{
|
||||
$result = $this->api('send-email', [
|
||||
'serverid' => $order['server_id'],
|
||||
'role_id' => $order['role_id'],
|
||||
'uid' => $order['user_id'],
|
||||
'prop_id' => $giftItem['id'],
|
||||
'orderid' => date("YmdHis").$order['id'].$order['user_id'].$giftItem['id'].rand(1000, 9999)
|
||||
]);
|
||||
if ($result['code'] == 1) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $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)
|
||||
{
|
||||
$resources = [];
|
||||
$result = $this->api('get-pay-type', ['action' => 'getItems']);
|
||||
if ($result['status'] == 1) {
|
||||
$items = $result['data'];
|
||||
foreach ($items as $item) {
|
||||
$resources[$item['id']] = [
|
||||
'ref_id' => $item['id'],
|
||||
'name' => $item['name'],
|
||||
'amount' => $item['money'],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $resources;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue