This commit is contained in:
parent
a4f0d7e5a6
commit
f58a5b4b67
|
|
@ -12,11 +12,11 @@ return [
|
|||
// 数据库名
|
||||
'database' => 'customerservice',
|
||||
// 用户名
|
||||
'username' => 'customerservice',
|
||||
'username' => 'root',
|
||||
// 密码
|
||||
'password' => 'ExXLFhBBpFx5M4XA',
|
||||
'password' => 'root',
|
||||
// 端口
|
||||
'hostport' => '3306',
|
||||
'hostport' => '3307',
|
||||
// 连接dsn
|
||||
'dsn' => '',
|
||||
// 数据库连接参数
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: zjz
|
||||
* Date: 2018/7/26
|
||||
* Time: 11:40
|
||||
*/
|
||||
|
||||
namespace game;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use think\Log;
|
||||
|
||||
class GameSrvApi
|
||||
{
|
||||
protected $host = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->host =config('game_host');
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求
|
||||
* @param $action
|
||||
* @param $params
|
||||
* @param bool $json_decode
|
||||
* @return string|\stdClass
|
||||
*/
|
||||
public function doPost($action, $params, $json_decode = true)
|
||||
{
|
||||
$client = new Client([
|
||||
'timeout' => 30
|
||||
]);
|
||||
|
||||
$json = json_encode($params);
|
||||
|
||||
list($microsecond, $time) = explode(' ', microtime()); //' '中间是一个空格
|
||||
$ts = floor((floatval($microsecond) + floatval($time)) * 1000);
|
||||
$sign = md5(implode(';', ['5a7553560c9cf51c105678f3', '/' . $action, $json, $ts]));
|
||||
$query = sprintf("ts=%s&sign=%s", $ts, $sign);
|
||||
$fullUrl = $this->host . '/' . $action . '?' . $query;
|
||||
Log::record('fullUrl:' . $fullUrl);
|
||||
Log::record('json:' . $json);
|
||||
$resBody = null;
|
||||
try {
|
||||
$res = $client->post($fullUrl, ['body' => $json]);
|
||||
if ($res) {
|
||||
if ($res->getStatusCode() == 200) {
|
||||
$resBody = $res->getBody()->getContents();
|
||||
if ($json_decode) {
|
||||
return json_decode($resBody, true);
|
||||
}
|
||||
} else {
|
||||
Log::record('response status code = ' . $res->getStatusCode());
|
||||
//exception('游服status不通',404);
|
||||
}
|
||||
} else {
|
||||
Log::record('client request null');
|
||||
//exception('游服client不通',404);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::record('游服'.$e->getMessage());
|
||||
//exception('游服不通',404);
|
||||
}
|
||||
return $resBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
* """Param"": {
|
||||
* ""ID"":323, //用户id
|
||||
* }"
|
||||
*
|
||||
*
|
||||
* "{
|
||||
* ""State"": 1,
|
||||
* ""ErrMes"":"""",
|
||||
* ""Data"": {
|
||||
* }
|
||||
* }"
|
||||
*
|
||||
* @param $params
|
||||
* @return \stdClass|string
|
||||
*/
|
||||
public static function PlayerData($params)
|
||||
{
|
||||
return (new self)->doPost('api/Player/PlayerData', ['Param' => $params]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue