Commit 33ac17d4 authored by 夏彬's avatar 夏彬

Merge remote-tracking branch 'origin/master'

parents f1d74eb7 e38b1e36
{ {
"name": "yunya/wxh-internal-api", "name": "yunya/wxh-internal-api",
"type": "library", "type": "library",
"homepage": "http://gitlab.fingerage.com:999/yangpp/wxh_internal_api", "homepage": "https://git.banshouhui.com/yangpp/wxh_internal_api",
"authors": [ "authors": [
{ {
"name": "xiabin", "name": "xiabin",
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
} }
], ],
"require": { "require": {
"php": ">=5.3.0" "php": ">=7.1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
...@@ -10,6 +10,7 @@ use internalApi\bbs\User; ...@@ -10,6 +10,7 @@ use internalApi\bbs\User;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
\internalApi\bbs\Test::setDebug(true); User::setDebug();
$data = \internalApi\bbs\Test::index('123123'); User::follow(12, 31, true);
print_r($data);
\ No newline at end of file //print_r($data);
\ No newline at end of file
...@@ -10,5 +10,10 @@ use internalApi\ucenter\MemberRedpack; ...@@ -10,5 +10,10 @@ use internalApi\ucenter\MemberRedpack;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
MemberRedpack::setDebug(); MemberRedpack::setDebug();
$info = MemberRedpack::getFirstRedpack(582); //$info = MemberRedpack::createRedpack(18, '12.5', 'test', '测试红包', null, true);
print_r($info); //$info = MemberRedpack::unfreeze([134, 136]);
\ No newline at end of file $info = MemberRedpack::createRedpackBatch([
['uid'=>'12', 'amount'=>1, 'type'=>'test', 'frozen'=>true],
['uid'=>'20', 'amount'=>1, 'type'=>'test', 'entityNo'=>'43gfdg', 'frozen'=>true]
]);
print_r($info);
...@@ -11,8 +11,15 @@ use internalApi\ucenter\Vip; ...@@ -11,8 +11,15 @@ use internalApi\ucenter\Vip;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
Vip::setDebug(); Vip::setDebug();
$ret = Vip::getGrades();
//$ret = Vip::setInviter('844184b4016810002cde5254007c97eb', '0e150e59016910003f4c525400781c54'); try {
print_r($ret); //$ret = Vip::getGrades();
$ret = Vip::getMembersByWxhuids('worker-74635,0e150e59016910003f4c525400781c54');
//$ret = Vip::setInviter('844184b4016810002cde5254007c97eb', '0e150e59016910003f4c525400781c54');
print_r($ret);
} catch (\internalApi\base\ApiException $e) {
echo $e->getMessage();
echo $e->getRemoteTraceString();
}
//Vip::addPending(12, 123, 1); //Vip::addPending(12, 123, 1);
\ No newline at end of file
<?php <?php
use internalApi\xue\CourseList; use internalApi\xue\Course;
require __DIR__.'/_init.php'; require __DIR__.'/_init.php';
//CourseList::setDebug(); Course::setDebug();
//$list = CourseList::getRecommendList(); //$list = CourseList::getRecommendList();
...@@ -12,6 +12,6 @@ require __DIR__.'/_init.php'; ...@@ -12,6 +12,6 @@ require __DIR__.'/_init.php';
//$list = \internalApi\xue\Exam::getExams([4, 5, 6, 7]); //$list = \internalApi\xue\Exam::getExams([4, 5, 6, 7]);
//$list = \internalApi\xue\Course::getCourseInfo(37); //$list = \internalApi\xue\Course::getCourseInfo(37);
$list = \internalApi\xue\Course::getSectionInfo(47); $list = \internalApi\xue\Course::getCourseSectionInfo(151);
print_r($list); print_r($list);
\ No newline at end of file
...@@ -103,11 +103,13 @@ class Client ...@@ -103,11 +103,13 @@ class Client
{ {
$instance = self::getInstance(); $instance = self::getInstance();
$url = $instance->apiUrl.(strpos($instance->apiUrl, '?') !== false ? '&' : '?').'api='.urlencode($api); $requestBody = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : '';
list($sign, $timestamp, $nonce) = $instance->signature($api, $params); list($sign, $timestamp, $nonce) = $instance->signature($api, $requestBody);
$url .= "&client_id={$instance->clientId}&sign={$sign}&timestamp={$timestamp}&nonce={$nonce}"; $url = $instance->apiUrl.(strpos($instance->apiUrl, '?') !== false ? '&' : '?').'api='.urlencode($api)
."&client_id={$instance->clientId}&sign={$sign}&timestamp={$timestamp}&nonce={$nonce}";
list($httpCode, $response) = $instance->request($url, $params); list($httpCode, $response) = $instance->request($url, $requestBody,
$requestBody ? ['Content-Type: application/json'] : []);
if ($httpCode == 200 && $response !== false) { if ($httpCode == 200 && $response !== false) {
$data = @json_decode($response, true); $data = @json_decode($response, true);
...@@ -139,15 +141,14 @@ class Client ...@@ -139,15 +141,14 @@ class Client
* 对请求进程签名 * 对请求进程签名
* *
* @param string $api * @param string $api
* @param array $params * @param string $pstr
* @return array * @return array
*/ */
protected function signature($api, $params) protected function signature($api, $pstr)
{ {
$timestamp = time(); $timestamp = time();
$nonce = uniqid(); $nonce = uniqid();
ksort($params); $str = $api.$pstr.$this->clientId.$this->clientSecret.$timestamp.$nonce;
$str = $api.http_build_query($params).$this->clientId.$this->clientSecret.$timestamp.$nonce;
$sign = md5($str); $sign = md5($str);
return [$sign, $timestamp, $nonce]; return [$sign, $timestamp, $nonce];
......
...@@ -77,6 +77,23 @@ class Server ...@@ -77,6 +77,23 @@ class Server
$paramsList = array_slice($this->apiMap[$group][$name], 1); $paramsList = array_slice($this->apiMap[$group][$name], 1);
$params = []; $params = [];
//确认请求数据
$contentType = $_SERVER['HTTP_CONTENT_TYPE'] ?? '';
switch ($contentType) {
case 'application/x-www-form-urlencoded':
$requestData = $_POST;
break;
case 'application/json':
$json = file_get_contents('php://input');
$requestData = $json !== '' ? json_decode($json, true): [];
break;
default:
$requestData = [];
}
foreach ($paramsList as $k => $v) { foreach ($paramsList as $k => $v) {
if (is_int($k)) { if (is_int($k)) {
$k = $v; $k = $v;
...@@ -85,8 +102,8 @@ class Server ...@@ -85,8 +102,8 @@ class Server
$hasDefault = true; $hasDefault = true;
} }
if (isset($_POST[$k])) { if (isset($requestData[$k])) {
$params[] = $_POST[$k]; $params[] = $requestData[$k];
} elseif ($hasDefault) { } elseif ($hasDefault) {
$params[] = $v; $params[] = $v;
} else { } else {
...@@ -141,21 +158,36 @@ class Server ...@@ -141,21 +158,36 @@ class Server
$timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0; $timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
$nonce = isset($_GET['nonce']) ? $_GET['nonce'] : ''; $nonce = isset($_GET['nonce']) ? $_GET['nonce'] : '';
$servTime = time(); //确认用于签名的请求数据
$params = $_POST; $contentType = $_SERVER['HTTP_CONTENT_TYPE'] ?? '';
ksort($params);
$str = $api.http_build_query($params).$clientId.$this->secret.$timestamp.$nonce; switch ($contentType) {
case 'application/x-www-form-urlencoded':
$parr = $_POST;
ksort($parr);
$pstr = http_build_query($parr);
break;
case 'application/json':
$pstr = file_get_contents('php://input');
break;
default:
$pstr = '';
}
$str = $api.$pstr.$clientId.$this->secret.$timestamp.$nonce;
$servSign = md5($str); $servSign = md5($str);
if ($servSign !== $sign) { if ($servSign !== $sign) {
return false; return false;
} }
if ($servTime - $timestamp > 300) { if (time() - $timestamp > 300) {
return false; return false;
} }
return $api; return $api;
} }
} }
\ No newline at end of file
...@@ -100,4 +100,34 @@ class User extends Client ...@@ -100,4 +100,34 @@ class User extends Client
return self::call('user.inactive', compact('uIds')); return self::call('user.inactive', compact('uIds'));
} }
/**
* 关注一个用户
*
* @param int $uid 当前用户UID
* @param int $followUid 要关注的用户UID
* @param bool $silent 是否静默关注,是则不会发送消息提示,默认否
* @return void
* @throws \internalApi\base\ApiException
* 异常code:1 代表不能关注自己,2 代表不能关注此人,3 代表已经关注了,其它 code 为异常情况
* @throws \internalApi\base\ClientException
*/
public static function follow($uid, $followUid, $silent=false)
{
return self::call('user.follow', compact('uid', 'followUid', 'silent'));
}
/**
* 取消关注一个用户
*
* @param int $uid 当前用户UID
* @param int $unfollowUid 要取消关注的用户UID
* @return void
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function unfollow($uid, $unfollowUid)
{
return self::call('user.unfollow', compact('uid', 'unfollowUid'));
}
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ return [ ...@@ -14,7 +14,6 @@ return [
], ],
'xue' => [ 'xue' => [
'apiUrl' => 'http://xue.yunya.com/api', 'apiUrl' => 'http://xue.yunya.com/api',
'remoteIp' => '127.0.0.1',
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'Z2oKgZYYc8mznesYMf1o' 'clientSecret' => 'Z2oKgZYYc8mznesYMf1o'
], ],
......
...@@ -27,11 +27,6 @@ return [ ...@@ -27,11 +27,6 @@ return [
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => '1WQwnpjcURS0JwSkdiq3r' 'clientSecret' => '1WQwnpjcURS0JwSkdiq3r'
], ],
'portal' => [
'apiUrl' => 'http://s.ibanshou.cn/e/api/internal.php',
'clientId' => 'common',
'clientSecret' => 'TveYDczsq7LTllIUlM5t'
],
'sv' => [ 'sv' => [
'apiUrl' => 'http://sv.ibanshou.cn/api/server', 'apiUrl' => 'http://sv.ibanshou.cn/api/server',
'clientId' => 'common', 'clientId' => 'common',
......
...@@ -27,11 +27,6 @@ return [ ...@@ -27,11 +27,6 @@ return [
'clientId' => 'common', 'clientId' => 'common',
'clientSecret' => 'AJmfi4ORZURS0JwSkdiq3r' 'clientSecret' => 'AJmfi4ORZURS0JwSkdiq3r'
], ],
'portal' => [
'apiUrl' => 'http://s.test.yunyamooc.com/e/api/internal.php',
'clientId' => 'common',
'clientSecret' => 'TveYDczsq7LTllIUlM5t'
],
'shop' => [ 'shop' => [
'apiUrl' => 'http://api-shop.test.yunyamooc.com/internalapi/api', 'apiUrl' => 'http://api-shop.test.yunyamooc.com/internalapi/api',
'clientId' => 'common', 'clientId' => 'common',
......
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2017/8/22
* Time: 18:15
*/
namespace internalApi\portal;
use internalApi\base\Client;
class User extends Client
{
/**
* 同步更新用户基本信息
*
* @param int $uid
* @param array $data
* @return bool
*/
public static function updateSync($uid, $data)
{
return self::call('user.updateSync', compact('uid', 'data'));
}
}
\ No newline at end of file
...@@ -9,6 +9,10 @@ namespace internalApi\ucenter; ...@@ -9,6 +9,10 @@ namespace internalApi\ucenter;
use internalApi\base\Client; use internalApi\base\Client;
/**
* 红包服务
* @package internalApi\ucenter
*/
class MemberRedpack extends Client class MemberRedpack extends Client
{ {
public static function getFirstRedpack($userId) public static function getFirstRedpack($userId)
...@@ -16,4 +20,56 @@ class MemberRedpack extends Client ...@@ -16,4 +20,56 @@ class MemberRedpack extends Client
return self::call('memberRedpack.firstRedpack',compact('userId')); return self::call('memberRedpack.firstRedpack',compact('userId'));
} }
/**
* 给指定用户创建一个可领红包
*
* @param int $uid
* @param float $amount 金额,最大支持99.99
* @param string $customType 红包类型枚举字符串,最大20个字节,
* @param string $desc 红包描述
* @param string $entityNo 实体编号,相同类型,且实体编号相同将不会重复创建,最大16个字节
* @param bool $frozen 红包是否处于冻结状态,冻结状态的红包需使用 unfreeze 解冻后方可提现
* @return array 创建成功后返回数组包含 status 与 id 两个值<br>
* status 为 OK 时代表创建成功,为 ENTITY_EXISTS 代表相同的实体编号重复<br>
* id 为红包的ID<br>
* 正常为情况下不需要要根据返回值进行处理,创建是否成功应该使用 try catch 是否有异常来判断。
* 返回值仅是为了获取红包ID,或区分是否是重复实体编号编号的红包等其它逻辑。
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function createRedpack($uid, $amount, $customType, $desc = '', $entityNo=null, $frozen=false)
{
$p = compact('uid', 'amount', 'customType', 'desc', 'entityNo', 'frozen');
return self::call('memberRedpack.createRedpack', $p);
}
/**
* 批量创建红包
*
* @param array $data 批量创建红包数据,包含多个字段的二维数组,其中 entity_no 与 desc 可选
* uid, amount, type, entityNo, desc, frozen
* 具体参数含义 @see createRedpack
*
* @return array
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function createRedpackBatch(array $data)
{
return self::call('memberRedpack.createRedpackBatch', compact('data'));
}
/**
* 解冻单个或多个红包
*
* @param array|int $redpackIds 单个红包ID或多个红包ID的数组
* @return int 解冻成功的红包数量
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function unfreeze($redpackIds)
{
return self::call('memberRedpack.unfreeze', compact('redpackIds'));
}
} }
\ No newline at end of file
...@@ -81,4 +81,30 @@ class Course extends Client ...@@ -81,4 +81,30 @@ class Course extends Client
return self::call('course.sendCourse', compact('userId','courseId','orderId')); return self::call('course.sendCourse', compact('userId','courseId','orderId'));
} }
/**
* 获取课程章节基本信息
* @param int $sectionId
* @return mixed
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function getCourseSectionInfo($sectionId)
{
return self::call('course.getCourseSectionInfo' , compact('sectionId'));
}
/**
* 获取分类的课程节列表
* @param $categoryId
* @param int $limit
* @param int $offset
* @return mixed
* @throws \internalApi\base\ApiException
* @throws \internalApi\base\ClientException
*/
public static function getCourseSectionLists($categoryId, $limit = 10, $offset = 0)
{
return self::call('course.getCourseSectionLists', compact('categoryId','limit','offset'));
}
} }
\ No newline at end of file
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