master
elf 1 year ago
parent 7144c3219c
commit 0927cfd3bb

@ -2,6 +2,7 @@
namespace Base\Service; namespace Base\Service;
use Base\Tool\GameResource\JmxyClient; use Base\Tool\GameResource\JmxyClient;
use Base\Tool\GameResource\YjlyClient;
use Base\Tool\GameResource\ZzylClient; use Base\Tool\GameResource\ZzylClient;
use Think\Model; use Think\Model;
@ -50,7 +51,7 @@ class GameRebateService
'L' => 'roleLevel', 'L' => 'roleLevel',
]; ];
public $rebateBaseGameIds = [11, 17]; public $rebateBaseGameIds = [11, 17, 21];
public function isGiftItemSend($order, $item) public function isGiftItemSend($order, $item)
{ {
@ -123,6 +124,9 @@ class GameRebateService
case 17: case 17:
$client = new JmxyClient(); $client = new JmxyClient();
break; break;
case 21:
$client = new YjlyClient();
break;
default: default:
throw new \Exception('客户端未实现'); throw new \Exception('客户端未实现');
break; break;

@ -0,0 +1,220 @@
<?php
namespace Base\Tool\GameResource;
use Base\Tool\Log;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/**
* 御剑灵域-测试资源接口
*/
class YjlyClient
{
const APP_ID = '';
const SIGN_NAME = 'sign';
const SIGN_KEY = 'nmjf65532qavdfsdq962dddsddfsaffd';
protected $client;
protected $baseUrl = 'https://x2centerapi.xiaoxixinxi.com';
private $apis = [
'send-email' => ['uri' => '/9vjh/player_mail', '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['appId'] = self::APP_ID;
$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)
{
$signString = '';
$signString .= $params['appId'];
$signString .= $params['serverId'];
$signString .= $params['roleId'];
$signString .= $params['userId'];
if ($name == 'send-gold') {
$signString .= $params['moneyFen'];
} elseif ($name == 'send-email') {
$signString .= $params['mailData'];
} elseif ($name == 'send-props') {
$signString .= $params['propData'];
}
$signString .= $params['orderNum'];
$signString .= $params['time'];
$signString .= self::SIGN_KEY;
return md5($signString);
}
// 测试资源
public function apply($order, $role)
{
throw new Exception('没有接口');
}
//
public function sendGold($order, $role)
{
$result = $this->api('send-gold', [
'roleId' => $role['role_id'],
'moneyFen' => intval($order['ref_amount'] * 100), // TODO
'serverId' => $role['server_id'],
'userId' => $role['user_id'],
'orderNum' => $order['order_no']
]);
if (intval($result['code']) == 0) {
return [
'status' => true,
'message' => $result['msg'],
'result' => $result
];
} else {
return [
'status' => false,
'message' => $result['msg'],
'result' => $result ?? []
];
}
}
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'],
];
}
$result = $this->api('send-prop', [
'roleId' => $order['role_id'],
'propData' => json_encode($props),
'serverId' => $order['server_id'],
'userId' => $order['user_id'],
'orderNum' => $this->generateOrderNumber($order),
'time' => time(),
]);
if (intval($result['code']) == 0) {
return [
'status' => true,
'message' => $result['msg'],
'result' => $result
];
} else {
return [
'status' => false,
'message' => $result['msg'],
'result' => $result ?? []
];
}
}
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 sendEmail($giftItem, $order)
{
$result = $this->api('send-email', [
'serverId' => $order['server_id'],
'roleId' => $order['role_id'],
'userId' => $order['user_id'],
'mailData' => json_encode([['mailId' => $giftItem['id']]]),
'orderNum' => date("YmdHis").$order['id'].$order['user_id'].$giftItem['id'].rand(1000, 9999),
'time' => time(),
]);
if (intval($result['code']) === 0) {
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)
{
return [];
}
}

@ -0,0 +1,43 @@
<?php
send();
function send() {
$url = 'http://cl3-uc01gh.huanyuantech.com/acf/send_gift.php';
$data = [
'appId' => 'chengfeng',
'userId' => 5141, // ljl654321
'orderNum' => time() . rand(1000, 9999),
'title' => '测试邮件',
'content' => '测试礼包发送',
'packages' => json_encode([
[
'packageId' => '29044',
'count' => 10,
],
]),
'serverId' => 1,
'roleId' => 65740,
'time' => time(),
];
$data['sign'] = sign($data);
var_dump($data);
$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec ($ch);
curl_close($ch);
var_dump($response);
}
function sign($params) {
unset($params['sign']);
ksort($params);
$signString = '';
foreach ($params as $key => $value) {
$signString .= $value;
}
return md5($signString . 'a3f579b5add2342a7ac07017b7650c45');
}
Loading…
Cancel
Save