Commit b692e548 by banice

添加super_agent_id

parent 17dad6f8
......@@ -29,14 +29,16 @@ class Events
}
/**
* @param $clientId
* @param $message
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws Exception
*/
public static function onMessage($clientId, $message)
{
$request = json_decode($message, true);
if (isset($request['command']) === false) {
......@@ -45,6 +47,9 @@ class Events
}
\Lib\Log::debug($message);
$command = $request['command'];
......@@ -89,15 +94,56 @@ class Events
if ($command == '02') {
$agentId = $request['agent_id'];
if (isset($request['super_agent_id'])) {
if (isset($request['super_agent_id'][0])) {
$superAgentId = $request['super_agent_id'][0];
Gateway::bindUid($superAgentId, $agentId);
$redis = new \Redis();
$redis->connect('redis.test.senthink.com');
$redis->select(4);
$redis->multi(2);
foreach ($request['super_agent_id'] as $id) {
$redis->hSet('cdz:super_agent_id:hash', $id, $id);
}
$redis->exec();
$redis->close();
}
Gateway::bindUid($clientId, $agentId);
Gateway::sendToCurrentClient(json_encode(['code' => 200]));
return;
}
if ($command == '03') {
$token = $request['token'];
$client = new Client([
'base_uri' => 'https://hdg-user-api.test.senthink.com',
]);
$response = $client->request('POST', 'api/wx/token/confirm', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
]
]);
if ($response->getStatusCode() === 200) {
$body = json_decode($response->getBody(), true);
Gateway::setSession($clientId, $body);
$userId = $body['id'];
Gateway::bindUid($clientId, 'hdg' . $userId);
Gateway::sendToCurrentClient(json_encode(['return_code' => 200, 'result_code' => "SUCCESS"]));
return;
} else {
Gateway::sendToCurrentClient(json_encode(['return_code' => 200, 'result_code' => 'FAIL']));
return;
}
}
......
......@@ -18,7 +18,7 @@ use Monolog\Logger;
* @method static warn($info, $context = [])
* @method static alert($info, $context = [])
* @method static error($info, $context = [])
*
* @method static debug($info, $context = [])
* Class Log
* @package Lib
*/
......@@ -65,7 +65,7 @@ class Log
public static function __callStatic($name, $arguments)
{
return call_user_func_array([static::$log,$name],$arguments);
return call_user_func_array([static::$log, $name], $arguments);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment