Commit 4b890404 authored by 杨培's avatar 杨培

支付消息队列异步调用指定接口,增加跟踪事件异步接口

parent c4738f3e
...@@ -6,13 +6,10 @@ ...@@ -6,13 +6,10 @@
* Time: 11:54 AM * Time: 11:54 AM
*/ */
use internalApi\ucenter\Event;
use internalApi\ucenter\Member; use internalApi\ucenter\Member;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
Member::setDebug(true); Event::setDebug();
Event::publish('commission_settlement', time());
$data = Member::getVipByWxhuid('dccc5b52016510003f78525400781c54'); \ No newline at end of file
//$data = User::canAddGoldCoin(13739230723);
print_r($data);
\ No newline at end of file
...@@ -10,4 +10,10 @@ use internalApi\ucenter\Track; ...@@ -10,4 +10,10 @@ use internalApi\ucenter\Track;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
echo Track::track('test'); //echo Track::track('test');
$ret = Track::trackAsync('test', 12, time(), [
'测试属性' => '属性值',
'_protectedProperty' => 'propertyValue'
]);
print_r($ret);
...@@ -137,6 +137,70 @@ class Client ...@@ -137,6 +137,70 @@ class Client
} }
} }
/**
* 向消息队列添加一个异步调用请求
*
* @param string $api
* @param array $params 参数列表,注意此参数列表与 call() 中的参数列表完全不同,此参数列表为纯数组形式(数字键名),
* 且参数顺序须与被调用服务顺序完全一致
* @see call
* @return int|boolean 入队列成功则返回消息ID,失败返回false
*/
protected static function emit($api, $params=[])
{
static $client = null;
if ($client === null) {
$config = self::$config['_async_server'];
$client = new Beanstalk([
'host' => $config['host'],
'port' => $config['port']
]);
$client->connect();
$client->useTube($config['tube']);
}
$msg = [
'target' => self::name(),
'api' => $api,
'params' => $params,
'time' => time(),
'nonce' => uniqid(),
'ver' => 0
];
$ext = [];
//添加客户端信息以辨服务端识别和调试
$userAgent = 'PHP/'.PHP_VERSION.' ('.PHP_OS.') Client/beanstalk';
if (isset($_SERVER['HTTP_HOST'])) {
$userAgent .= ' ('.$_SERVER['HTTP_HOST'].')';
}
$ext['ua'] = $userAgent;
//IP 透传
if (isset($_SERVER['REMOTE_ADDR'])) {
$clientIp = !empty($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : $_SERVER['REMOTE_ADDR'];
$ext['ip'] = $clientIp;
$forwardedFor = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] :
($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '');
if ($forwardedFor && $forwardedFor != $clientIp) {
$forwardedFor .= ','.$_SERVER['SERVER_ADDR'];
$ext['fw'] = $forwardedFor;
}
}
$ext && $msg['ext'] = $ext;
return $client->put(1024, 0, 60, json_encode($msg, JSON_UNESCAPED_UNICODE));
}
/** /**
* 对请求进程签名 * 对请求进程签名
* *
......
...@@ -41,5 +41,10 @@ return [ ...@@ -41,5 +41,10 @@ return [
'apiUrl' => 'http://appapi.fecshoptest.com/v1/internalapi', 'apiUrl' => 'http://appapi.fecshoptest.com/v1/internalapi',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA' 'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA'
] ],
'_async_server' => [
'host' => '172.16.0.181',
'port' => 11300,
'tube' => 'internal-api'
]
]; ];
...@@ -33,7 +33,7 @@ return [ ...@@ -33,7 +33,7 @@ return [
'clientSecret' => '6A23057D233DA902B5D603A758B0438E' 'clientSecret' => '6A23057D233DA902B5D603A758B0438E'
], ],
'shop' => [ 'shop' => [
'apiUrl' => 'http://api-shop.banshouhui.com/internalapi/api', 'apiUrl' => 'http://api-shop.banshouhui.com/v1/internalapi',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA' 'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA'
] ]
......
...@@ -28,7 +28,7 @@ return [ ...@@ -28,7 +28,7 @@ return [
'clientSecret' => 'AJmfi4ORZURS0JwSkdiq3r' 'clientSecret' => 'AJmfi4ORZURS0JwSkdiq3r'
], ],
'shop' => [ 'shop' => [
'apiUrl' => 'http://api-shop.test.yunyamooc.com/internalapi/api', 'apiUrl' => 'http://api-shop.test.yunyamooc.com/v1/internalapi',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA' 'clientSecret' => 'qlOCFMUfxWjOhK2bdL88e3w2DjdhUDIA'
], ],
......
...@@ -31,6 +31,11 @@ class Track extends Client ...@@ -31,6 +31,11 @@ class Track extends Client
return self::call('track.track', compact('event', 'uid', 'time', 'props')); return self::call('track.track', compact('event', 'uid', 'time', 'props'));
} }
public static function trackAsync($event, $uid=0, $time=null, $props=[])
{
return self::emit('track.track', func_get_args());
}
/** /**
* 更新事件 * 更新事件
* *
......
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