Commit 30dc80ac authored by 夏彬's avatar 夏彬

Merge remote-tracking branch 'origin/master'

parents d26312b4 cff91438
...@@ -38,5 +38,8 @@ Message::setDebug(); ...@@ -38,5 +38,8 @@ Message::setDebug();
//$info = \internalApi\ucenter\Message::pushMsg(1,0,0,'bbs','theme',0); //$info = \internalApi\ucenter\Message::pushMsg(1,0,0,'bbs','theme',0);
//print_r($info); //print_r($info);
$ret = Message::sendSystemMessage('assistant', 0, 12, Message::TYPE_TEXT, ['msg'=>'新消息测试']); $ret = Message::sendSystemMessageAsync('remind', 0, 12, Message::TYPE_REMIND, [
'title' => '测试的标题',
'text'=>'新消息测试'.uniqid()
]);
print_r($ret); print_r($ret);
...@@ -11,4 +11,4 @@ use internalApi\ucenter\Notice; ...@@ -11,4 +11,4 @@ use internalApi\ucenter\Notice;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
Notice::setDebug(); Notice::setDebug();
Notice::addToast(12, 'test'); Notice::addToastAsync(12, 'test '.date('Y-m-d H:i:s'));
...@@ -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,19 @@ use internalApi\ucenter\Track; ...@@ -10,4 +10,19 @@ use internalApi\ucenter\Track;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
echo Track::track('test'); //echo Track::track('test');
$ret = Track::trackAsync('_view', 12, time(), [
'内容标题' => '这是一个测试你懂的',
'内容ID' => '123',
'内容类型' => '帖子',
'_id' => '123',
'_title' => '这是一个测试你懂的',
'_type' => 'post',
'_author' => 12,
'_visitor' => uniqid(),
'_reflow' => 1
]);
print_r($ret);
echo "\n";
<?php
/**
* beanstalk: A minimalistic PHP beanstalk client.
*
* Copyright (c) 2009-2015 David Persson
*
* Distributed under the terms of the MIT License.
* Redistributions of files must retain the above copyright notice.
*/
namespace internalApi\base;
use RuntimeException;
/**
* An interface to the beanstalk queue service. Implements the beanstalk
* protocol spec 1.9. Where appropriate the documentation from the protocol
* has been added to the docblocks in this class.
*
* @link https://github.com/kr/beanstalkd/blob/master/doc/protocol.txt
*/
class Beanstalk {
/**
* Minimum priority value which can be assigned to a job. The minimum
* priority value is also the _highest priority_ a job can have.
*
* @var integer
*/
const MIN_PRIORITY = 0;
/**
* Maximum priority value which can be assigned to a job. The maximum
* priority value is also the _lowest priority_ a job can have.
*
* @var integer
*/
const MAX_PRIORITY = 4294967295;
/**
* Holds a boolean indicating whether a connection to the server is
* currently established or not.
*
* @var boolean
*/
public $connected = false;
/**
* Holds configuration values.
*
* @var array
*/
protected $_config = [];
/**
* The current connection resource handle (if any).
*
* @var resource
*/
protected $_connection;
/**
* Constructor.
*
* @param array $config An array of configuration values:
* - `'persistent'` Whether to make the connection persistent or
* not, defaults to `true` as the FAQ recommends
* persistent connections.
* - `'host'` The beanstalk server hostname or IP address to
* connect to, defaults to `127.0.0.1`.
* - `'port'` The port of the server to connect to, defaults
* to `11300`.
* - `'timeout'` Timeout in seconds when establishing the
* connection, defaults to `1`.
* - `'logger'` An instance of a PSR-3 compatible logger.
*
* @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* @return void
*/
public function __construct(array $config = []) {
$defaults = [
'persistent' => true,
'host' => '127.0.0.1',
'port' => 11300,
'timeout' => 1,
'logger' => null
];
$this->_config = $config + $defaults;
}
/**
* Destructor, disconnects from the server.
*
* @return void
*/
public function __destruct() {
$this->disconnect();
}
/**
* Initiates a socket connection to the beanstalk server. The resulting
* stream will not have any timeout set on it. Which means it can wait
* an unlimited amount of time until a packet becomes available. This
* is required for doing blocking reads.
*
* @see \internalApi\base\Beanstalk::$_connection
* @see \internalApi\base\Beanstalk::reserve()
* @return boolean `true` if the connection was established, `false` otherwise.
*/
public function connect() {
if (isset($this->_connection)) {
$this->disconnect();
}
$function = $this->_config['persistent'] ? 'pfsockopen' : 'fsockopen';
$params = [$this->_config['host'], $this->_config['port'], &$errNum, &$errStr];
if ($this->_config['timeout']) {
$params[] = $this->_config['timeout'];
}
$this->_connection = @call_user_func_array($function, $params);
if (!empty($errNum) || !empty($errStr)) {
$this->_error("{$errNum}: {$errStr}");
}
$this->connected = is_resource($this->_connection);
if ($this->connected) {
stream_set_timeout($this->_connection, -1);
}
return $this->connected;
}
/**
* Closes the connection to the beanstalk server by first signaling
* that we want to quit then actually closing the socket connection.
*
* @return boolean `true` if diconnecting was successful.
*/
public function disconnect() {
if (!is_resource($this->_connection)) {
$this->connected = false;
} else {
$this->_write('quit');
$this->connected = !fclose($this->_connection);
if (!$this->connected) {
$this->_connection = null;
}
}
return !$this->connected;
}
/**
* Pushes an error message to the logger, when one is configured.
*
* @param string $message The error message.
* @return void
*/
protected function _error($message) {
if ($this->_config['logger']) {
$this->_config['logger']->error($message);
}
}
/**
* Writes a packet to the socket. Prior to writing to the socket will
* check for availability of the connection.
*
* @param string $data
* @return integer|boolean number of written bytes or `false` on error.
*/
protected function _write($data) {
if (!$this->connected) {
$message = 'No connecting found while writing data to socket.';
throw new RuntimeException($message);
}
$data .= "\r\n";
return fwrite($this->_connection, $data, strlen($data));
}
/**
* Reads a packet from the socket. Prior to reading from the socket
* will check for availability of the connection.
*
* @param integer $length Number of bytes to read.
* @return string|boolean Data or `false` on error.
*/
protected function _read($length = null) {
if (!$this->connected) {
$message = 'No connection found while reading data from socket.';
throw new RuntimeException($message);
}
if ($length) {
if (feof($this->_connection)) {
return false;
}
$data = stream_get_contents($this->_connection, $length + 2);
$meta = stream_get_meta_data($this->_connection);
if ($meta['timed_out']) {
$message = 'Connection timed out while reading data from socket.';
throw new RuntimeException($message);
}
$packet = rtrim($data, "\r\n");
} else {
$packet = stream_get_line($this->_connection, 16384, "\r\n");
}
return $packet;
}
/* Producer Commands */
/**
* The `put` command is for any process that wants to insert a job into the queue.
*
* @param integer $pri Jobs with smaller priority values will be scheduled
* before jobs with larger priorities. The most urgent priority is
* 0; the least urgent priority is 4294967295.
* @param integer $delay Seconds to wait before putting the job in the
* ready queue. The job will be in the "delayed" state during this time.
* @param integer $ttr Time to run - Number of seconds to allow a worker to
* run this job. The minimum ttr is 1.
* @param string $data The job body.
* @return integer|boolean `false` on error otherwise an integer indicating
* the job id.
*/
public function put($pri, $delay, $ttr, $data) {
$this->_write(sprintf("put %d %d %d %d\r\n%s", $pri, $delay, $ttr, strlen($data), $data));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'INSERTED':
case 'BURIED':
return (integer) strtok(' '); // job id
case 'EXPECTED_CRLF':
case 'JOB_TOO_BIG':
default:
$this->_error($status);
return false;
}
}
/**
* The `use` command is for producers. Subsequent put commands will put
* jobs into the tube specified by this command. If no use command has
* been issued, jobs will be put into the tube named `default`.
*
* @param string $tube A name at most 200 bytes. It specifies the tube to
* use. If the tube does not exist, it will be created.
* @return string|boolean `false` on error otherwise the name of the tube.
*/
public function useTube($tube) {
$this->_write(sprintf('use %s', $tube));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'USING':
return strtok(' ');
default:
$this->_error($status);
return false;
}
}
/**
* Pause a tube delaying any new job in it being reserved for a given time.
*
* @param string $tube The name of the tube to pause.
* @param integer $delay Number of seconds to wait before reserving any more
* jobs from the queue.
* @return boolean `false` on error otherwise `true`.
*/
public function pauseTube($tube, $delay) {
$this->_write(sprintf('pause-tube %s %d', $tube, $delay));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'PAUSED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/* Worker Commands */
/**
* Reserve a job (with a timeout).
*
* @param integer $timeout If given specifies number of seconds to wait for
* a job. `0` returns immediately.
* @return array|false `false` on error otherwise an array holding job id
* and body.
*/
public function reserve($timeout = null) {
if (isset($timeout)) {
$this->_write(sprintf('reserve-with-timeout %d', $timeout));
} else {
$this->_write('reserve');
}
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'RESERVED':
return [
'id' => (integer) strtok(' '),
'body' => $this->_read((integer) strtok(' '))
];
case 'DEADLINE_SOON':
case 'TIMED_OUT':
default:
$this->_error($status);
return false;
}
}
/**
* Removes a job from the server entirely.
*
* @param integer $id The id of the job.
* @return boolean `false` on error, `true` on success.
*/
public function delete($id) {
$this->_write(sprintf('delete %d', $id));
$status = $this->_read();
switch ($status) {
case 'DELETED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
* Puts a reserved job back into the ready queue.
*
* @param integer $id The id of the job.
* @param integer $pri Priority to assign to the job.
* @param integer $delay Number of seconds to wait before putting the job in the ready queue.
* @return boolean `false` on error, `true` on success.
*/
public function release($id, $pri, $delay) {
$this->_write(sprintf('release %d %d %d', $id, $pri, $delay));
$status = $this->_read();
switch ($status) {
case 'RELEASED':
case 'BURIED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
* Puts a job into the `buried` state Buried jobs are put into a FIFO
* linked list and will not be touched until a client kicks them.
*
* @param integer $id The id of the job.
* @param integer $pri *New* priority to assign to the job.
* @return boolean `false` on error, `true` on success.
*/
public function bury($id, $pri) {
$this->_write(sprintf('bury %d %d', $id, $pri));
$status = $this->_read();
switch ($status) {
case 'BURIED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
* Allows a worker to request more time to work on a job.
*
* @param integer $id The id of the job.
* @return boolean `false` on error, `true` on success.
*/
public function touch($id) {
$this->_write(sprintf('touch %d', $id));
$status = $this->_read();
switch ($status) {
case 'TOUCHED':
return true;
case 'NOT_TOUCHED':
default:
$this->_error($status);
return false;
}
}
/**
* Adds the named tube to the watch list for the current connection.
*
* @param string $tube Name of tube to watch.
* @return integer|boolean `false` on error otherwise number of tubes in watch list.
*/
public function watch($tube) {
$this->_write(sprintf('watch %s', $tube));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'WATCHING':
return (integer) strtok(' ');
default:
$this->_error($status);
return false;
}
}
/**
* Remove the named tube from the watch list.
*
* @param string $tube Name of tube to ignore.
* @return integer|boolean `false` on error otherwise number of tubes in watch list.
*/
public function ignore($tube) {
$this->_write(sprintf('ignore %s', $tube));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'WATCHING':
return (integer) strtok(' ');
case 'NOT_IGNORED':
default:
$this->_error($status);
return false;
}
}
/* Other Commands */
/**
* Inspect a job by its id.
*
* @param integer $id The id of the job.
* @return string|boolean `false` on error otherwise the body of the job.
*/
public function peek($id) {
$this->_write(sprintf('peek %d', $id));
return $this->_peekRead();
}
/**
* Inspect the next ready job.
*
* @return string|boolean `false` on error otherwise the body of the job.
*/
public function peekReady() {
$this->_write('peek-ready');
return $this->_peekRead();
}
/**
* Inspect the job with the shortest delay left.
*
* @return string|boolean `false` on error otherwise the body of the job.
*/
public function peekDelayed() {
$this->_write('peek-delayed');
return $this->_peekRead();
}
/**
* Inspect the next job in the list of buried jobs.
*
* @return string|boolean `false` on error otherwise the body of the job.
*/
public function peekBuried() {
$this->_write('peek-buried');
return $this->_peekRead();
}
/**
* Handles response for all peek methods.
*
* @return string|boolean `false` on error otherwise the body of the job.
*/
protected function _peekRead() {
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'FOUND':
return [
'id' => (integer) strtok(' '),
'body' => $this->_read((integer) strtok(' '))
];
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/**
* Moves jobs into the ready queue (applies to the current tube).
*
* If there are buried jobs those get kicked only otherwise delayed
* jobs get kicked.
*
* @param integer $bound Upper bound on the number of jobs to kick.
* @return integer|boolean False on error otherwise number of jobs kicked.
*/
public function kick($bound) {
$this->_write(sprintf('kick %d', $bound));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'KICKED':
return (integer) strtok(' ');
default:
$this->_error($status);
return false;
}
}
/**
* This is a variant of the kick command that operates with a single
* job identified by its job id. If the given job id exists and is in a
* buried or delayed state, it will be moved to the ready queue of the
* the same tube where it currently belongs.
*
* @param integer $id The job id.
* @return boolean `false` on error `true` otherwise.
*/
public function kickJob($id) {
$this->_write(sprintf('kick-job %d', $id));
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'KICKED':
return true;
case 'NOT_FOUND':
default:
$this->_error($status);
return false;
}
}
/* Stats Commands */
/**
* Gives statistical information about the specified job if it exists.
*
* @param integer $id The job id.
* @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary.
*/
public function statsJob($id) {
$this->_write(sprintf('stats-job %d', $id));
return $this->_statsRead();
}
/**
* Gives statistical information about the specified tube if it exists.
*
* @param string $tube Name of the tube.
* @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary.
*/
public function statsTube($tube) {
$this->_write(sprintf('stats-tube %s', $tube));
return $this->_statsRead();
}
/**
* Gives statistical information about the system as a whole.
*
* @return string|boolean `false` on error otherwise a string with a yaml formatted dictionary.
*/
public function stats() {
$this->_write('stats');
return $this->_statsRead();
}
/**
* Returns a list of all existing tubes.
*
* @return string|boolean `false` on error otherwise a string with a yaml formatted list.
*/
public function listTubes() {
$this->_write('list-tubes');
return $this->_statsRead();
}
/**
* Returns the tube currently being used by the producer.
*
* @return string|boolean `false` on error otherwise a string with the name of the tube.
*/
public function listTubeUsed() {
$this->_write('list-tube-used');
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'USING':
return strtok(' ');
default:
$this->_error($status);
return false;
}
}
/**
* Returns a list of tubes currently being watched by the worker.
*
* @return string|boolean `false` on error otherwise a string with a yaml formatted list.
*/
public function listTubesWatched() {
$this->_write('list-tubes-watched');
return $this->_statsRead();
}
/**
* Handles responses for all stat methods.
*
* @param boolean $decode Whether to decode data before returning it or not. Default is `true`.
* @return array|string|boolean `false` on error otherwise statistical data.
*/
protected function _statsRead($decode = true) {
$status = strtok($this->_read(), ' ');
switch ($status) {
case 'OK':
$data = $this->_read((integer) strtok(' '));
return $decode ? $this->_decode($data) : $data;
default:
$this->_error($status);
return false;
}
}
/**
* Decodes YAML data. This is a super naive decoder which just works on
* a subset of YAML which is commonly returned by beanstalk.
*
* @param string $data The data in YAML format, can be either a list or a dictionary.
* @return array An (associative) array of the converted data.
*/
protected function _decode($data) {
$data = array_slice(explode("\n", $data), 1);
$result = [];
foreach ($data as $key => $value) {
if ($value[0] === '-') {
$value = ltrim($value, '- ');
} elseif (strpos($value, ':') !== false) {
list($key, $value) = explode(':', $value);
$value = ltrim($value, ' ');
}
if (is_numeric($value)) {
$value = (integer) $value == $value ? (integer) $value : (float) $value;
}
$result[$key] = $value;
}
return $result;
}
}
...@@ -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));
}
/** /**
* 对请求进程签名 * 对请求进程签名
* *
......
...@@ -85,6 +85,18 @@ class Thread extends Client ...@@ -85,6 +85,18 @@ class Thread extends Client
return self::call('thread.getThread',compact('fid','page','num')); return self::call('thread.getThread',compact('fid','page','num'));
} }
/**
* 根据帖子标题获取帖子
* @param string $keywords
* @param int $page
* @param int $num
* @return mixed
*/
public static function getThreadByKeywords($keywords = '', $page, $num)
{
return self::call('thread.getThreadByKeywords',compact('keywords','page','num'));
}
/** /**
* 获取板块帖子 * 获取板块帖子
* @param int $bid * @param int $bid
...@@ -104,4 +116,78 @@ class Thread extends Client ...@@ -104,4 +116,78 @@ class Thread extends Client
{ {
return self::call('thread.getDigest',compact('num')); return self::call('thread.getDigest',compact('num'));
} }
/**
* 根据帖子ID串获取用户是否回答
* @param array $threadArr
* @param int $userId
* @return array
*/
public static function IsAnswerByThreadIds($threadArr, $userId)
{
return self::call('thread.IsAnswerByThreadIds', compact('threadArr', 'userId'));
}
/**
* 回复评论帖子
* @param $tid
* @param $message
* @param $uid
* @param $pushTime
* @return mixed
*/
public static function setThreadReply($tid, $message, $uid, $pushTime)
{
return self::call('thread.setThreadReply',compact('tid','message','uid', 'pushTime'));
}
/**
* 发布用户动态
*
* @param $message
* @param $uid
* @param $pushTime
* @param $tags
* @return mixed
*/
public static function setDynamic($message, $uid, $pushTime, $tags)
{
return self::call('thread.setDynamic',compact('message','uid', 'pushTime', 'tags'));
}
/**
* 点赞帖子
*
* @param $tid
* @param $uid
* @return mixed
*/
public static function addThreadRecommend($tid, $uid)
{
return self::call('thread.addThreadRecommend',compact('tid','uid'));
}
/**
* 点赞评论
*
* @param $tid
* @param $uid
* @param $postList
* @return mixed
*/
public static function addPostReview($tid, $uid, $postList)
{
return self::call('thread.addPostReview',compact('tid','uid','postList'));
}
/**
* 获取帖子评论列表
*
* @param $tid
* @return mixed
*/
public static function getThreadCommentList($tid)
{
return self::call('thread.getThreadCommentList',compact('tid'));
}
} }
\ No newline at end of file
...@@ -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,8 +33,13 @@ return [ ...@@ -33,8 +33,13 @@ 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'
],
'_async_server' => [
'host' => '127.0.0.1',
'port' => 11301,
'tube' => 'internal-api'
] ]
]; ];
...@@ -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'
], ],
...@@ -36,5 +36,10 @@ return [ ...@@ -36,5 +36,10 @@ return [
'apiUrl' => 'http://sv.test.yunyamooc.com/api/server', 'apiUrl' => 'http://sv.test.yunyamooc.com/api/server',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => '6A23057D233DA902B5D603A758B0438E' 'clientSecret' => '6A23057D233DA902B5D603A758B0438E'
],
'_async_server' => [
'host' => '127.0.0.1',
'port' => 11300,
'tube' => 'internal-api'
] ]
]; ];
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2019/5/29
* Time: 14:42
*/
namespace internalApi\ucenter;
use internalApi\base\ApiException;
use internalApi\base\Client;
use internalApi\base\ClientException;
class Event extends Client
{
/**
* 用于第三方调用的远程事件发布
*
* @param string $event
* @param int $time
* @param mixed $data
* @throws ApiException|ClientException
*/
public static function publish($event, $time, $data=null)
{
self::call('event.publish', compact('event', 'time', 'data'));
}
}
\ No newline at end of file
...@@ -15,21 +15,105 @@ use internalApi\base\Client; ...@@ -15,21 +15,105 @@ use internalApi\base\Client;
class Label extends Client class Label extends Client
{ {
//类型 1=>认证 2=>品类 3=>品牌 4=>热门事件 5=>现象 6=>故障点 7=>专题
const TYPE_AUTH = 1; // 认证
const TYPE_CATEGORY = 2; // 品类
const TYPE_BRAND = 3; // 品牌
const TYPE_HOT_EVENTS = 4; // 热门事件
const TYPE_PHENOMENON = 5; // 现象
const TYPE_FAULT = 6; // 故障点
const TYPE_SPECIAL_TOPIC = 7; // 专题
//类型 1=>认证 2=>品类 3=>品牌 // 1=>thread 2=>moment 3=>course 4=>section
const TYPE_AUTH = 1; //认证 const FROM_THREAD = 1;
const TYPE_CATEGORY = 2; //品类 const FROM_MOMENT = 2;
const TYPE_BRAND = 3; //品牌 const FROM_COURSE = 3;
const FROM_SECTION = 4;
/** /**
* @param array/int $type 1=>认证 2=>品类 3=>品牌 * @param array/int $type 1=>认证 2=>品类 3=>品牌
*
* @return mixed * @return mixed
* @throws \internalApi\base\ApiException * @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException * @throws \internalApi\base\ClientException
*/ */
public static function getLabels($type = null) public static function getLabels($type = null){
{
return self::call('label.getLabels', compact('type')); return self::call('label.getLabels', compact('type'));
} }
/**
* 标签分类
*
* @param array $labels 标签
* @param array $types //类型 1=>认证 2=>品类 3=>品牌 4=>热门事件 5=>现象 6=>故障点 7=>专题
*
* @return array
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function getListByLabels($labels, $types = [self::TYPE_CATEGORY, self::TYPE_BRAND, self::TYPE_PHENOMENON, self::TYPE_FAULT]){
return self::call('label.getListByLabels', compact('labels', 'types'));
}
/**
* 设置话题置顶
*
* @param int $sid 标记id
* @param array $labelIds 话题id数组
* @param int $endTime 截止时间
* @param string $name 标记名称
* @param int $uid 用户中心uid
* @param int $from 来源
*
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function setTopicRoof($sid, $labelIds, $endTime = 0, $name = '', $uid = 0, $from = self::FROM_THREAD) {
return self::call('label.setTopicRoof', compact('sid', 'labelIds', 'endTime', 'name', 'uid', 'from'));
}
/**
* 设置话题置顶标记名称
*
* @param int $sid 标记id
* @param string $name 标记名称
* @param int $uid 用户中心uid
* @param int $from 来源
*
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function setRoofNameBySid($sid, $name = '', $uid = 0, $from = self::FROM_THREAD)
{
return self::call('label.setRoofNameBySid', compact('sid','name', 'uid', 'from'));
}
/**
* 根据标记id话题置顶数据
*
* @param int $sid 标记id
* @param array $types 标签类型
* @param int $from 来源
*
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function getLabelListBySid($sid, $types = [], $from = self::FROM_THREAD) {
return self::call('label.getLabelListBySid', compact('sid', 'types', 'from'));
}
/**
* 获取我的兴趣标签列表
* @param $uid 用户id
*
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function getMyInterestList($uid) {
return self::call('label.getMyInterestList', compact('uid'));
}
} }
...@@ -26,7 +26,7 @@ class Member extends Client ...@@ -26,7 +26,7 @@ class Member extends Client
* other 其它信息 * other 其它信息
* verify 基本认证信息,例如姓名、地区等 * verify 基本认证信息,例如姓名、地区等
* 如指定 ['basic', 'vip'] 即代表取基本信息与服务星等级信息 * 如指定 ['basic', 'vip'] 即代表取基本信息与服务星等级信息
* 当指定 vip 时,如 vip_grade 字段返回值为 -1 则代表该成员只是准服务星,还需完善资料。 * 当指定 vip 时,返回 vip_complete 表示是否完善资料。
* @return array|null * @return array|null
* @throws \internalApi\base\ApiException * @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException * @throws \internalApi\base\ClientException
......
...@@ -66,6 +66,20 @@ class Message extends Client ...@@ -66,6 +66,20 @@ class Message extends Client
return self::call('message.sendTemplateSms', compact('tel', 'templateId', 'templateParams', 'signature')); return self::call('message.sendTemplateSms', compact('tel', 'templateId', 'templateParams', 'signature'));
} }
/**
* 向指定手机号发送模板短信
*
* @param string|array $tel 单个或多个号码数组
* @param string $templateId 内部短信模板ID
* @param array $templateParams 短信模板变量内容
* @param string $signature 短信签名
* @return int|false
*/
public static function sendTemplateSmsAsync($tel, $templateId, $templateParams=[], $signature=null)
{
return self::emit('message.sendTemplateSms', func_get_args());
}
/** /**
* 向指定用户发送模板短信 * 向指定用户发送模板短信
* *
...@@ -80,87 +94,19 @@ class Message extends Client ...@@ -80,87 +94,19 @@ class Message extends Client
return self::call('message.sendTemplateSmsByUid', compact('uid', 'templateId', 'templateParams', 'signature')); return self::call('message.sendTemplateSmsByUid', compact('uid', 'templateId', 'templateParams', 'signature'));
} }
/***
* @param $userId
* @param $title
* @param $sourceUrl
* @param $from 0:xue 1:bbs 2:s
* @param $type 0:评论 1:帖子
* @param $commentId
* @param $replyUserId
* @param string $replyedComment
* @param string $extra
* @return mixed
* @deprecated
*/
public static function addComment($userId, $title, $sourceUrl, $from, $type, $commentId, $replyUserId, $replyedComment = '', $extra = '')
{}
/**
* @param $userId
* @param $title
* @param $sourceUrl
* @param $from
* @param $type
* @param $sourceId 点赞的评论id
* @param $likeUserId
* @param $likedComment
* @return mixed
* @deprecated
*/
public static function addLike($userId, $title, $sourceUrl, $from, $type, $sourceId, $likeUserId, $likedComment = '')
{}
/**
* @param $userId
* @param $title
* @param $desc
* @param $from
* @param $type
* @param string $content
* @param int $toUser 0系统消息其它为用户id,多个用户id数组
* @return mixed
* @deprecated
*/
public static function add($userId, $title, $desc, $from, $type, $content = '', $toUser = 0)
{}
/**
* 删除评论消息
* @param $userId
* @param $from
* @param $type
* @param $commentId
* @return mixed
* @deprecated
*/
public static function deleteComment($userId, $from, $type, $commentId)
{}
/** /**
* 删除点赞 * 向指定用户发送模板短信
* @param $userId *
* @param $from * @param int $uid
* @param $type * @param string $templateId 内部短信模板ID
* @param $sourceId * @param array $templateParams 短信模板变量内容
* @return mixed * @param string $signature 短信签名
* @deprecated * @return int|false
*/
public static function deleteLiked($userId, $from, $type, $sourceId)
{}
/**
* @param $title 消息标题
* @param $url
* @param $desc 描述
* @param int $userId 用户id 0=>代表全部
* @param string $from 来自
* @param int $type 0 早报 1 求助 2 系统推送
* @return mixed
* @deprecated
*/ */
public static function pushMsg($title, $url, $desc, $userId = 0, $from = 'u', $type = 0) public static function sendTemplateSmsByUidAsync($uid, $templateId, $templateParams=[], $signature=null)
{} {
return self::emit('message.sendTemplateSmsByUid', func_get_args());
}
/** /**
* 以系统会话发送消息 * 以系统会话发送消息
...@@ -172,6 +118,7 @@ class Message extends Client ...@@ -172,6 +118,7 @@ class Message extends Client
* @param array $content 消息内容 * @param array $content 消息内容
* @param array $ext 消息扩展属性 * @param array $ext 消息扩展属性
* @return array * @return array
* @see http://dzzoffice.banshouhui.com/index.php?mod=corpus&op=list&cid=3#fid_1146
* @throws \internalApi\base\ApiException * @throws \internalApi\base\ApiException
*/ */
public static function sendSystemMessage($systemSessionId, $from, $to, $type, $content, $ext=[]) public static function sendSystemMessage($systemSessionId, $from, $to, $type, $content, $ext=[])
...@@ -179,5 +126,22 @@ class Message extends Client ...@@ -179,5 +126,22 @@ class Message extends Client
return self::call('message.sendSystemMessage', compact('systemSessionId', 'from', 'to', 'type', 'content', 'ext')); return self::call('message.sendSystemMessage', compact('systemSessionId', 'from', 'to', 'type', 'content', 'ext'));
} }
/**
* 以系统会话发送消息
*
* @param int|string $systemSessionId 系统会话的ID或别名
* @param int $from 发送用户,系统用户请指定0
* @param int $to 接收用户
* @param int $type 消息类型
* @param array $content 消息内容
* @param array $ext 消息扩展属性
* @return int|false
* @see http://dzzoffice.banshouhui.com/index.php?mod=corpus&op=list&cid=3#fid_1146
*/
public static function sendSystemMessageAsync($systemSessionId, $from, $to, $type, $content, $ext=[])
{
return self::emit('message.sendSystemMessage', func_get_args());
}
} }
...@@ -55,4 +55,46 @@ class Notice extends Client ...@@ -55,4 +55,46 @@ class Notice extends Client
self::call('notice.addToast', compact('uid', 'text', 'timeout')); self::call('notice.addToast', compact('uid', 'text', 'timeout'));
} }
/**
* 添加积分提示
*
* @param int $uid
* @param string $action 动作文字,如“发表帖子”
* @param array $credits 变化积分数字,以积分序号对应数字的形式
* @return int|false
*/
public static function addCreditAsync($uid, $action, $credits)
{
return self::emit('notice.addCredit', func_get_args());
}
/**
* 添加勋章提示
*
* @param int $uid
* @param string $icon
* @param string $name
* @param string $description
* @param $url
* @return int|false
*/
public static function addMedalAsync($uid, $icon, $name, $description, $url)
{
return self::emit('notice.addMedal', func_get_args());
}
/**
* 添加Toast提示
*
* @param int $uid
* @param string $text
* @param null|int $timeout 提示留存时间,毫秒单位,默认为 1500
* @return int|false
*/
public static function addToastAsync($uid, $text, $timeout=null)
{
return self::emit('notice.addToast', func_get_args());
}
} }
\ No newline at end of file
...@@ -31,6 +31,20 @@ class Track extends Client ...@@ -31,6 +31,20 @@ class Track extends Client
return self::call('track.track', compact('event', 'uid', 'time', 'props')); return self::call('track.track', compact('event', 'uid', 'time', 'props'));
} }
/**
* 添加事件
*
* @param string $event 事件、32个字符以内
* @param int $uid 用户UID,0代表访客
* @param int|null $time 时间,默认为当前时间
* @param array $props 属性键值列表 (键32个字符以内,值128字符以内)
* @return int|false
*/
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