Merge pull request 'feature/game_rebate1' (#450) from feature/game_rebate1 into master

Reviewed-on: http://8.136.139.249:3000/wmtx/platform/pulls/450
master
廖金灵 3 years ago
commit a874de5fe6

@ -12,6 +12,7 @@ use Base\Service\TestingResourceService;
use GuzzleHttp\Client;
use think\Db;
use Base\Tool\GameResource;
use Base\Tool\GameResource\SbcqClient;
class GameApiController extends Think {
@ -63,6 +64,23 @@ class GameApiController extends Think {
public function send()
{
$giftItem = [
'id' => 1782,
'num' => 1,
];
$order = [
'user_account' => '13110873520',
'server_id' => '1',
'role_name' => '十六',
];
$client = new SbcqClient();
/* $result = $client->sendEmail($giftItem, $order);
var_dump($result); */
$result = $client->sendGold(25000, $order);
var_dump($result);
return;
// 229
// 231
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => 231])->find();

@ -1,39 +1,32 @@
<?php
namespace Base\Service;
use Base\Tool\GameResource\SbcqClient;
use Base\Tool\GameResource\XyyClient;
use Exception;
use GuzzleHttp\Client;
class GameRebateService
{
const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd';
private function getClient()
{
return new Client([
'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/',
'timeout' => 10.0,
]);
}
public function sendByOrder($order)
{
$gift = M('rebate_gifts', 'tab_')->where(['type' => $order['type'], 'gift_key' => $order['gift_key']])->find();
$gift = M('rebate_gifts', 'tab_')->where(['base_game_id' => $order['base_game_id'], 'type' => $order['type'], 'gift_key' => $order['gift_key']])->find();
$hasError = false;
$sendResult = '';
if ($gift['game_currency'] > 0) {
$result = $this->sendCurrency($order['server_id'], $order['role_id'], $gift['game_currency']);
if ($result['code'] != 1) {
$result = $this->sendGold($order, $gift['game_currency']);
if ($result['status']) {
$hasError = true;
}
$sendResult .= ($result['msg'] ?? '');
$sendResult .= ';';
$sendResult .= ($result['message'] ?? '') . ';';
}
if ($gift['gift_id'] > 0) {
$result = $this->sendGift($order['server_id'], $order['role_id'], $gift['gift_id']);
if ($result['code'] != 1) {
$giftItems = json_decode($gift['gifts'], true);
foreach ($giftItems as $giftItem) {
$result = $this->sendGift($order, $giftItem);
if ($result['status']) {
$hasError = true;
}
$sendResult .= ($result['msg'] ?? '');
$sendResult .= ($result['message'] ?? '') . ';';
}
M('rebate_orders', 'tab_')->where(['id' => $order['id']])->save([
'send_status' => $hasError ? 2 : 1,
@ -42,47 +35,36 @@ class GameRebateService
]);
}
public function sendCurrency($serverId, $roleId, $currency)
private function getClient($baseGameId)
{
$sign = md5($currency.$serverId.$roleId.self::SIGN_KEY);
$params = [
'act' => 'sendgold',
'serverid' => $serverId,
'role_id' => $roleId,
'money' => $currency,
'sign' => $sign
];
return $this->get('', $params);
$client = null;
switch ($baseGameId) {
case 70:
$client = new XyyClient();
break;
case 73:
$client = new SbcqClient();
break;
/* case 9:
$client = new SbcqClient();
break; */
default:
throw new \Exception('客户端未实现');
break;
}
return $client;
}
public function sendGift($serverId, $roleId, $giftId)
public function sendGold($order, $gold)
{
$sign = md5($giftId.$serverId.$roleId.self::SIGN_KEY);
$params = [
'act' => 'send_email',
'serverid' => $serverId,
'role_id' => $roleId,
'prop_id' => $giftId,
'sign' => $sign
];
return $this->get('', $params);
$client = $this->getClient($order['base_game_id']);
return $client->sendGold($gold, $order);
}
protected function get($uri, array $params = [])
public function sendGift($order, $giftItem)
{
try {
$response = $this->getClient()->get($uri, [
'verify' => false,
'query' => $params,
]);
$result = (string)$response->getBody();
return json_decode($result, true);
} catch (\Exception $e) {
return [
'code' => 3,
'msg' => '网络异常:' . $e->getMessage(),
];
}
$client = $this->getClient($order['base_game_id']);
return $client->sendEmail($giftItem, $order);
}
public function review(array $ids, $status)

@ -0,0 +1,165 @@
<?php
namespace Base\Tool\GameResource;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Think\Log;
/**
* 双倍传奇-测试资源接口
*/
class SbcqClient
{
const SIGN_NAME = 'sign';
const SUCCESS = '0000';
const KEY = 'wan';
protected $client;
private $apis = [
'send-gold' => ['uri' => 'sendgold', 'method' => 'post'],
'send-email' => ['uri' => 'sendemail', 'method' => 'post'],
];
public function __construct()
{
$this->client = new Client([
'base_uri' => 'http://api.tlcq.90wqiji.com/wan/game/',
'timeout' => 10.0,
]);
}
public function api($api, array $params = [])
{
$api = $this->apis[$api] ?? 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');
return ['status' => 'error', '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::record('rebate:SBCQ ' . $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::record('rebate:SBCQ ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
return json_decode($result, true);
}
protected function sign($params)
{
return md5($params['account'] . $params['num'] . $params['serverid'] . self::KEY);
}
public function sendEmail($giftItem, $order)
{
$data = [
'account' => $order['user_account'],
'serverid' => $order['server_id'],
'num' => $giftItem['num'],
'name' => $giftItem['id'],
'role' => $order['role_name'],
'content' => '您的福利已到账,请查收',
];
$result = $this->api('send-email', $data);
return $this->getCommonResult($result);
}
public function sendGold($gold, $order)
{
$data = [
'account' => $order['user_account'],
'serverid' => $order['server_id'],
'num' => $gold,
'role' => $order['role_name'],
];
$result = $this->api('send-gold', $data);
return $this->getCommonResult($result);
}
private function getCommonResult($result)
{
if ($result['status'] == 'success') {
return [
'status' => true,
'message' => $result['msg'],
'result' => $result
];
} else {
return [
'status' => false,
'message' => $result['msg'],
'result' => $result
];
}
}
/**
* @todo 暂时没有测试资源
*/
public function apply($order, $role)
{
return $this->sendGold($order['ref_amount'], $role);
}
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],
];
}
}

@ -4,6 +4,7 @@ namespace Base\Tool\GameResource;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Think\Log;
/**
* 逍遥游之仙魔降世-测试资源接口
@ -13,18 +14,20 @@ class XyyClient
const SIGN_NAME = 'sign';
const SUCCESS = '0000';
const KEY = 'Eza65532qaOIAAWasdq962aqweasd';
const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd';
protected $client;
private $apis = [
'provide' => ['uri' => '/', 'method' => 'get'],
'send-gold' => ['uri' => '', 'method' => 'get'],
'send-email' => ['uri' => '', 'method' => 'get'],
'self-apply-foster' => ['uri' => '', 'method' => 'get'],
];
public function __construct()
{
$this->client = new Client([
'base_uri' => 'http://rebate.99you.cn/wdzx_apply.php/23399',
'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/',
'timeout' => 10.0,
]);
}
@ -35,7 +38,7 @@ class XyyClient
if (is_null($api)) {
throw new \Exception('接口不存在');
}
$params[self::SIGN_NAME] = $this->sign($params);
$params[self::SIGN_NAME] = $this->sign($api, $params);
try {
return $this->request($api, $params);
} catch (\Exception $e) {
@ -60,6 +63,7 @@ class XyyClient
'form_params' => $params,
]);
$result = (string)$response->getBody();
Log::record('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
return json_decode($result, true);
}
@ -70,25 +74,49 @@ class XyyClient
'query' => $params,
]);
$result = (string)$response->getBody();
Log::record('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
return json_decode($result, true);
}
protected function sign($params)
protected function sign($api, $params)
{
return md5($params['orderid'] . $params['serverid'] . $params['role_id'] . self::KEY);
if ($api == 'send-email') {
return md5($params['prop_id'].$params['serverid'].$params['role_id'].self::SIGN_KEY);
} elseif ($api == 'send-gold') {
return md5($params['money'].$params['serverid'].$params['role_id'].self::SIGN_KEY);
} else {
return '';
}
}
public function apply($order, $role)
public function sendEmail($giftItem, $order)
{
$data = [
'act' => 'send_email',
'serverid' => $order['server_id'],
'role_id' => $order['role_id'],
'prop_id' => $giftItem['id'],
];
$result = $this->api('send-email', $data);
return $this->getCommonResult($result);
}
public function sendGold($gold, $order)
{
$data = [
'role_id' => $role['role_id'],
'serverid' => $role['server_id'],
'amount' => $order['ref_amount'],
// 'money' => intval($order['ref_amount']) * 10,
'orderid' => $order['order_no'],
'act' => 'sendgold',
'serverid' => $order['server_id'],
'role_id' => $order['role_id'],
'money' => $gold,
];
$result = $this->api('provide', $data);
$result = $this->api('send-gold', $data);
return $this->getCommonResult($result);
}
private function getCommonResult($result)
{
if ($result['code'] == 1) {
return [
'status' => true,
@ -104,6 +132,14 @@ class XyyClient
}
}
/**
* @todo 暂时没有测试资源
*/
public function apply($order, $role)
{
return $this->sendGold($order['ref_amount'], $role);
}
public function getResourceTypes($deviceType)
{
if ($deviceType == 'andriod') {

Loading…
Cancel
Save