Commit 070e5090 by 王召彬
parents 9ff2be0f d1295115
......@@ -12,6 +12,8 @@ class AuthError
const TOKEN_ERROR = ["msg" => "token写入失败", "code" => 500, "errorCode" => 25100];
const WX_ERROR = ["msg" => "获取信息失败", "code" => 500, "errorCode" => 25101];
const CONFIG_ERROR = ["msg" => "配置不正确", "code" => 500, "errorCode" => 25102];
const GET_TOKEN_ERROR = ["msg" => "获取token失败", "code" => 500, "errorCode" => 25103];
const NOT_FOUND_USER = ["msg" => "获取用户信息失败", "code" => 404, "errorCode" => 25104];
public static function atranslate($message,$param)
......@@ -23,4 +25,9 @@ class AuthError
return sprintf(...$param);
}
public static function getError($code) {
$reflect = new \ReflectionClass(StoreError::class);
return $reflect->getConstant('E'.$code);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/27
* Time: 14:47
*/
namespace Hdll\Services\Auth\Exception;
use Hdll\Services\Common\Exception\CommonException;
class AuthException extends CommonException
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/5
* Time: 15:47
*/
namespace Hdll\Services\Auth\Lib;
use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferUpdateInfo($token, $info)
* Interface BuyerInterface
* @package App\Lib
*/
interface AuthInterface
{
/**
* 要更新redis中的实体信息
*
* @param $token
* @param $info
* @return bool
*/
public function updateInfo($token, $info);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/20
* Time: 11:13
*/
namespace Hdll\Services\Buyer\Enum;
class BuyerError
{
const PARAMETER_ERR = ["msg" => "参数错误", "code" => 400, "errorCode" => 24001];
const REGISTERED = ["msg" => "用户已存在,无需创建", "code" => 400, "errorCode" => 24101];
const DB_ERROR = ["msg" => "数据库操作错误", "code" => 500, "errorCode" => 24102];
public static function atranslate($message,$param)
{
if ( empty($param) ) {
return $message;
}
array_unshift($param,$message);
return sprintf(...$param);
}
public static function getError($code) {
$reflect = new \ReflectionClass(BuyerError::class);
return $reflect->getConstant('E'.$code);
}
}
\ No newline at end of file
......@@ -10,7 +10,12 @@
namespace Hdll\Services\Common\Entity;
use Hdll\Services\Auth\Enum\AuthError;
use Hdll\Services\Auth\Exception\AuthException;
use Swoft\App;
use Swoft\Bean\Annotation\Bean;
use Swoft\Cache\Cache;
use Swoft\Redis\Redis;
/**
* 用户实体
......@@ -34,17 +39,20 @@ class User
private $token;
private $cmId;
private $sessionKey;
private $scope;
private $referId;
private $unionid;
private $openId;
public function __construct($token='')
{
$this->setHeadImg("test");
$this->setId(1);
$this->setNickName("zhangsan");
$this->setStoreId("2");
$this->setToken($token);
}
public function getId()
......@@ -92,9 +100,54 @@ class User
return $this->headImg = $value;
}
public function setSessionKey($value)
{
$this->sessionKey = $value;
}
public function setOpenId($value)
{
$this->openId = $value;
}
public function setUnionid($value)
{
$this->unionid = $value;
}
public function setReferId($value)
{
$this->referId = $value;
}
public function setScope($value)
{
$this->scope = $value;
}
public function setToken($value)
{
return $this->token = $value;
if ( empty($value) ) {
return [false,AuthError::GET_TOKEN_ERROR];
}
/**
* @var Redis $redis
*/
$redis = App::getBean(Redis::class);
$info = $redis->get('AUTH:'.$value);
if ( empty($info) ) {
return [false,AuthError::NOT_FOUND_USER];
}
$info = json_decode($info, true);
$this->fill($info);
$this->token = $value;
return true;
}
public function setCmId($value)
......@@ -106,5 +159,46 @@ class User
{
return $this->cmId;
}
public function fill($arr)
{
foreach ($arr as $name => $value) {
$methodName = sprintf('set%s', ucfirst($name));
if (method_exists($this, $methodName)) {
$this->$methodName($value);
}
}
}
public function getSessionKey()
{
return $this->sessionKey;
}
public function getOpenId()
{
return $this->openId;
}
public function getUnionid()
{
return $this->unionid;
}
public function getReferId()
{
return $this->referId;
}
public function getScope()
{
return $this->scope;
}
}
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Hdll\Services\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class SellerPoolConfig extends PoolProperties
{
protected $name = 'seller';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
* @var array
*/
protected $uri = [
'192.168.3.100:8101',
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -43,6 +43,12 @@ class OrderError
const DB_ERROR = ["msg" => "数据库操作错误", "code" => 500, "errorCode" => 22118];
public static function atranslate($message,$param)
{
if ( empty($param) ) {
......
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/17
* Time: 14:19
*/
namespace Hdll\Services\Order\Enum;
class SellerDistributionEnum
{
const E101 = ['101', '金额不能小于0'];
const E102 = [102, '该数据不属于您', 403];
const E103 = [103, '请勿重复创建', 403];
const E104 = [104, '该用户不存在或属于您的团队', 403];
public function getError($code)
{
$reflect = new \ReflectionClass(self::class);
$arr = $reflect->getConstant('E' . substr($code, -3));
if (!is_array($arr)) {
return false;
}
return [
'code' => $arr[0],
'msg' => $arr[1],
'errorCode' => $arr[2],
];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/27
* Time: 16:28
*/
namespace Hdll\Services\Store\Lib;
use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferSave($referId, $unionId, $openId, $nickName, $headImgUrl, $realName, $phoneNumber)
* @method ResultInterface deferGet($id)
* Interface SellerInterface
* @package App\Lib
*/
interface SellerInterface
{
/**
* @param $referId
* @param $unionId
* @param $openId
* @param $nickName
* @param $headImgUrl
* @param string $realName
* @param string $phoneNumber
* @return mixed
* @author Administrator
*/
public function save($referId, $unionId, $openId, $nickName, $headImgUrl, $realName = '', $phoneNumber = '');
/**
* @param $id
* @return mixed
* @author Administrator
*/
public function get($id);
}
\ 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