交友模块
This commit is contained in:
1
application/friendapi/common.php
Normal file
1
application/friendapi/common.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
6
application/friendapi/config.php
Normal file
6
application/friendapi/config.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
//配置文件
|
||||
return [
|
||||
'exception_handle' => '\\app\\friendapi\\library\\ExceptionHandle',
|
||||
];
|
||||
379
application/friendapi/controller/Login.php
Normal file
379
application/friendapi/controller/Login.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\common\controller\NumberAuth;
|
||||
use app\api\controller\Sms;
|
||||
use http\Client;
|
||||
use think\Controller;
|
||||
use think\Loader;
|
||||
use Firebase\JWT\JWT;
|
||||
use think\Log;
|
||||
|
||||
|
||||
class Login extends Controller
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
//允许跨域
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号密码登录接口。
|
||||
*
|
||||
* @ string $user_login 用户名或手机号
|
||||
* @ string $password 密码
|
||||
* @ int $system 登录系统类型(如 iOS, Android)
|
||||
* @ json 返回登录结果信息
|
||||
*/
|
||||
public function user_login()
|
||||
{
|
||||
$user_name = input('user_login', '');
|
||||
$password = input('password', '');
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
$reslut = model('Login')->user_login($user_name, $password, $system,$login_device);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码登录接口。
|
||||
*
|
||||
* @param string $user_login 手机号
|
||||
* @param int $system 登录系统类型
|
||||
* @param string $sms_code 短信验证码
|
||||
* @ json 返回登录结果信息
|
||||
*/
|
||||
public function phone_code(){
|
||||
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
$user_name = input('user_login');
|
||||
$sms_code = input('sms_code', ''); //短信验证码
|
||||
// $sms = new Sms;
|
||||
// $ret = $sms->check($user_name, $sms_code);//$event = default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现
|
||||
$ret = model('sms')->verification_code('default',$user_name, $sms_code);
|
||||
if ($ret['code'] == 0) {
|
||||
return V($ret['code'], $ret['msg'], null);
|
||||
}
|
||||
|
||||
$reslut = model('Login')->phone_verification_code_log($user_name, $system,$login_device);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $login_token
|
||||
* @param string $last_login_device 最后一次登录设备标识
|
||||
* @param int $system 登录系统类型
|
||||
* @ json 返回一键登录结果
|
||||
*/
|
||||
public function one_click_login()
|
||||
{
|
||||
$loginToken = input('login_token', '');
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
if (empty($loginToken)) {
|
||||
return V(0, '验证码错误' );
|
||||
}
|
||||
|
||||
// 1. 通过Token获取手机号
|
||||
$mobile = NumberAuth::getMobileByToken($loginToken);
|
||||
|
||||
if (!$mobile) {
|
||||
return V(0, '登录失败, 请更换登录方式!' );
|
||||
}
|
||||
|
||||
if(ctype_digit($mobile)){
|
||||
$reslut = model('Login')->phone_verification_code_log($mobile,$system,$login_device);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}else{
|
||||
return V(0, '登录失败' );
|
||||
}
|
||||
}
|
||||
|
||||
//多账号选号登录
|
||||
public function multi_account_login()
|
||||
{
|
||||
$user_name = input('user_login');
|
||||
$system = input('system','');
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
|
||||
$reslut = model('Login')->multi_account_login($user_name, $system,$login_device);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
public function wechatLogin()
|
||||
{
|
||||
$code = input('code');
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
if (empty($code)) {
|
||||
return V(0, 'code不能为空' );
|
||||
}
|
||||
|
||||
$config = get_system_config();
|
||||
$appid = $config['wx_app_id'];
|
||||
$app_secret = $config['wx_app_secret'];
|
||||
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$app_secret}&code={$code}&grant_type=authorization_code";
|
||||
|
||||
$result = myCurl($url);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if (isset($data['errcode'])) {
|
||||
return V(0, $data['errmsg']);
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
$userInfo = $this->getWechatUserInfo($data['access_token'], $data['openid']);
|
||||
|
||||
// 处理用户登录/注册逻辑
|
||||
$reslut = model('Login')->wechat_ali_Login('wx',$userInfo,$system,$login_device);
|
||||
if ($reslut['code'] == 1) {
|
||||
return V(1, $reslut['msg'], $reslut['data'] );
|
||||
}
|
||||
return V(0, '登录失败' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信用户信息
|
||||
*/
|
||||
private function getWechatUserInfo($accessToken, $openid)
|
||||
{
|
||||
$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$accessToken}&openid={$openid}";
|
||||
$result = myCurl($url);
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
//给支付宝登录拼接参数
|
||||
public function AlipayUserInfo()
|
||||
{
|
||||
$configs = get_system_config();
|
||||
$app_id = $configs['alipay_app_id'];
|
||||
$pid = $configs['alipay_pid'];
|
||||
$data = [
|
||||
'app_id' => $app_id,
|
||||
'pid' => $pid,
|
||||
'sign_type' => 'RSA2',
|
||||
'apiname'=>'com.alipay.account.auth',
|
||||
'method'=>'alipay.open.auth.sdk.code.get',
|
||||
'app_name'=>'mc',
|
||||
'biz_type'=>'openservice',
|
||||
'product_id'=>'APP_FAST_LOGIN',
|
||||
'scope'=>'kuaijie',
|
||||
'target_id'=>generateRandom(12),
|
||||
'auth_type'=>'AUTHACCOUNT',
|
||||
];
|
||||
$dd = $this->getCheckSignContent($data);
|
||||
$sign = $this->aliPaySign($dd, $configs['alipay_private_key']);
|
||||
//把签名放在最后
|
||||
$dd = $dd . '&sign=' . urlencode($sign);
|
||||
|
||||
return V(1, '获取成功', $dd );
|
||||
}
|
||||
|
||||
//生成签名前数据排序后拼接
|
||||
|
||||
/**
|
||||
* 获取支付宝签名
|
||||
* @param $params
|
||||
* @param $rsaPrivateKey
|
||||
* @return string
|
||||
*/
|
||||
function getCheckSignContent($params)
|
||||
{
|
||||
ksort($params);
|
||||
$stringToBeSigned = '';
|
||||
foreach ($params as $k => $v) {
|
||||
if ($v && substr($v, 0, 1) != '@') {
|
||||
$stringToBeSigned .= "$k=$v&";
|
||||
}
|
||||
}
|
||||
$stringToBeSigned = rtrim($stringToBeSigned, '&');
|
||||
return $stringToBeSigned;
|
||||
}
|
||||
/**
|
||||
* 支付宝登录
|
||||
* 支付宝开放平台创建应用 获取应用私钥 和应用公钥 然后修改AliPay.php文件里面login方法的配置值
|
||||
*/
|
||||
public function aliLogin()
|
||||
{
|
||||
$authCode = input('auth_code');
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
if (empty($authCode)) {
|
||||
return V(0, 'auth_code不能为空' );
|
||||
}
|
||||
|
||||
//引用支付宝sdk
|
||||
Loader::import('AliPayV2.AliPay', EXTEND_PATH, '.php');
|
||||
$ali = new \AliPay();
|
||||
// 使用auth_code获取access_token
|
||||
$userInfo = $ali->login($authCode);
|
||||
|
||||
if ($userInfo['code'] != 1) {
|
||||
return V($userInfo['code'], $userInfo['msg'],$userInfo['data']);
|
||||
}
|
||||
//对象转数组
|
||||
$userinfo = json_decode(json_encode($userInfo['data']), true);
|
||||
// 处理用户登录/注册逻辑
|
||||
$reslut = model('Login')->wechat_ali_Login('ali',$userinfo,$system,$login_device);
|
||||
if ($reslut['code'] == 1) {
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
return V(0, '登录失败' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支付宝签名
|
||||
*/
|
||||
private function aliPaySign($stringToBeSigned, $privateKey)
|
||||
{
|
||||
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
|
||||
wordwrap($privateKey, 64, "\n", true) .
|
||||
"\n-----END RSA PRIVATE KEY-----";
|
||||
|
||||
openssl_sign($stringToBeSigned, $sign, $res, OPENSSL_ALGO_SHA256);
|
||||
|
||||
return base64_encode($sign);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ios 登录
|
||||
*/
|
||||
public function iosLogin()
|
||||
{
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
$login_device = input('deviceId','');
|
||||
if(empty($login_device)){
|
||||
$login_device = request()->header('deviceId');
|
||||
}
|
||||
|
||||
$identityToken = input('ios_token');
|
||||
$appleId = input('apple_id');
|
||||
// $isValid = $this->verifyIdentityToken($identityToken);
|
||||
//
|
||||
// if (!$isValid) {
|
||||
// return V(0, '无效的token' );
|
||||
// }
|
||||
|
||||
// $decodedToken = JWT::decode( $identityToken, new \Firebase\JWT\Key(config('jwt_secret_key'), 'HS256'));
|
||||
// $userIdentity = (array) $decodedToken;
|
||||
//
|
||||
// $appleId = $userIdentity['sub'];
|
||||
// Log::record("ios登录信息".json_encode($userIdentity),"info");
|
||||
// 处理用户登录/注册逻辑
|
||||
$reslut = model('Login')->wechat_ali_Login('ios',$appleId,$system,$login_device);
|
||||
if ($reslut['code'] == 1) {
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
return V(0, '登录失败' );
|
||||
}
|
||||
|
||||
// private function verifyIdentityToken($identityToken)
|
||||
// {
|
||||
// $client = new Client();
|
||||
//
|
||||
// try {
|
||||
// $response = $client->request('POST', 'https://appleid.apple.com/auth/keys');
|
||||
//
|
||||
// if ( $response->getStatusCode() == 200) {
|
||||
// $publicKeys = json_decode( $response->getBody(), true)['keys'];
|
||||
//
|
||||
// foreach ( $publicKeys as $key) {
|
||||
// $pem = $this->convertPublicKeyToPEM( $key);
|
||||
// $decodedToken = JWT::decode( $identityToken, new \Firebase\JWT\Key( $pem, 'RS256'));
|
||||
//
|
||||
// if ( $decodedToken) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// echo 'Error verifying token: ' . $e->getMessage();
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
//退出登录
|
||||
public function logout()
|
||||
{
|
||||
$token = input('token');
|
||||
$reslut = model('Login')->logout($token);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//注销
|
||||
public function cancel()
|
||||
{
|
||||
$token = input('token');
|
||||
$reslut = model('Login')->cancel($token);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//忘记密码
|
||||
public function forgot_password()
|
||||
{
|
||||
$user_name = input('mobile');
|
||||
$password = input('new_password');
|
||||
$sms_code = input('sms_code', ''); //短信验证码
|
||||
//default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现
|
||||
$reslut = model('sms')->verification_code(3,$user_name, $sms_code);
|
||||
if ($reslut['code'] == 0) {
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
$reslut = model('Login')->forgot_password($user_name, $password);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
409
application/friendapi/controller/Room.php
Normal file
409
application/friendapi/controller/Room.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Db;
|
||||
|
||||
class Room extends BaseCom
|
||||
{
|
||||
//创建房间
|
||||
public function create_room()
|
||||
{
|
||||
$room_name = input('room_name', '');
|
||||
$room_cover = input('room_cover', '');
|
||||
$room_intro = input('room_intro', '');
|
||||
$key_name = "api:room:user_create_room:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$reslut = model('Room')->user_create_room($this->uid, $room_name, $room_cover, $room_intro);
|
||||
redis_unlock($key_name);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//编辑房间
|
||||
public function edit_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$room_name = input('room_name', '');
|
||||
$room_cover = input('room_cover', '');
|
||||
$room_intro = input('room_intro', '');
|
||||
$room_background_id = input('room_background', '');
|
||||
|
||||
$reslut = model('Room')->user_edit_room($this->uid, $room_id, $room_name, $room_cover, $room_intro,$room_background_id);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//关注的用户现在所在房间(废弃)
|
||||
public function user_follow_in_room_list()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
|
||||
$reslut = model('Room')->user_follow_in_room_list($this->uid, $page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间随机名称
|
||||
public function room_random_name()
|
||||
{
|
||||
return V(1, '获取成功', generateRandomRoomName());
|
||||
}
|
||||
|
||||
// 房间历史足迹
|
||||
public function user_room_history_list()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
$reslut = model('UserData')->user_room_history_list($this->uid, $page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//删除历史足迹
|
||||
public function delete_room_history()
|
||||
{
|
||||
$reslut = model('UserData')->delete_room_history($this->uid);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//我创建/主持/管理/关注的房间
|
||||
public function my_associated_room()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
$type = input('type', 0);//0-我创建的 1-我主持的 2-我管理的 3-我关注的
|
||||
$reslut = model('Room')->my_associated_room($this->uid, $type, $page, $page_limit);
|
||||
return V(1, '获取成功', $reslut);
|
||||
}
|
||||
|
||||
|
||||
//我的Cp房
|
||||
public function my_cp_room()
|
||||
{
|
||||
$reslut = model('Room')->my_cp_room($this->uid);
|
||||
return V(1, '获取成功', $reslut);
|
||||
}
|
||||
|
||||
//房间补贴
|
||||
public function room_ubsidy()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->room_ubsidy($room_id);
|
||||
return V(1, '获取成功', $reslut);
|
||||
}
|
||||
|
||||
//房间历史补贴记录
|
||||
public function room_subsidy_history()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
$reslut = model('Room')->room_subsidy_history($room_id, $page, $page_limit);
|
||||
return V(1, '获取成功', $reslut);
|
||||
}
|
||||
|
||||
//房间流水明细
|
||||
public function room_turnover_detail()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$start_time = input('start_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
$reslut = model('Room')->room_turnover_detail($room_id, $start_time, $end_time, $page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 进入房间
|
||||
*/
|
||||
public function join_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$password = input('password', '');
|
||||
$reslut = model('Room')->join_room($this->uid, $room_id, $password);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//退出房间
|
||||
public function quit_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->quit_room($this->uid, $room_id,$user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//踢出房间
|
||||
public function kick_out_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->quit_room($this->uid, $room_id,$user_id,1);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//直播间送礼
|
||||
public function room_give_gift()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$gift_id = input('gift_id', 0);
|
||||
$gift_num = input('gift_num', 0);
|
||||
$to_uid = input('to_uid', 0);//收礼人ID,逗号隔开的字符串
|
||||
$type = input('type', 1);//1金币购买 2送背包礼物
|
||||
$pit_number = input('pit_number', 0);
|
||||
|
||||
$reslut = model('Room')->room_gift($this->uid, $to_uid, $gift_id, $gift_num, $type, $room_id, $pit_number);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间榜单
|
||||
public function room_rank()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 1);//1财富榜,2魅力榜
|
||||
$timeType = input('time_type', 1);//1小时榜,2天榜,3周榜,
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 30);
|
||||
$reslut = model('Room')->room_rank($room_id, $type, $timeType, $page, $limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间在线列表
|
||||
public function room_online_list()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 50);
|
||||
$reslut = model('Room')->room_online_list($room_id, $page, $limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间内用户主页(房间内点头像)
|
||||
public function room_user_home()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->room_user_home($this->uid,$room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//设置开播提醒
|
||||
public function set_live_reminder()
|
||||
{
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->set_live_reminder($this->uid, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//当前发(抢)头条需要的数据
|
||||
public function current_headline()
|
||||
{
|
||||
$reslut = model('HeadLine')->current_headline();
|
||||
return V(1, '成功', $reslut);
|
||||
}
|
||||
//发(抢)头条
|
||||
public function send_headline()
|
||||
{
|
||||
$content = input('content', '');
|
||||
$money = input('money', 0);
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('HeadLine')->send_headline($this->uid,$money,$content,$room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//设置主持
|
||||
public function set_host()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$type = input('type', 1);//1-主持,2管理
|
||||
$is_add = input('is_add', 1);//1-添加,2-删除
|
||||
$reslut = model('Room')->set_host($this->uid, $room_id, $user_id,$type,$is_add);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//主持人,管理员列表
|
||||
public function host_list()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 0);
|
||||
$reslut = model('Room')->host_list($room_id,$type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//设置主持人收益
|
||||
public function set_host_profit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$host_id = input('user_id', 0);
|
||||
$ratio = input('ratio', 0);
|
||||
$reslut = model('Room')->set_host_profit($this->uid, $room_id, $host_id,$ratio);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//清除房间用户魅力
|
||||
public function clear_user_charm()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->clear_user_charm($this->uid, $room_id,$user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//修改房间类型
|
||||
public function change_room_type()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 1);//1-点唱,2-拍卖,3-男神,4-女神
|
||||
$reslut = model('Room')->change_room_type($this->uid, $room_id, $type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//更新用户声网的token
|
||||
public function update_user_sw_token()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->update_user_token($this->uid, $room_id);
|
||||
return V(1, '成功', $reslut);
|
||||
}
|
||||
|
||||
//更新房间声网的RTM token
|
||||
public function update_rtm_token()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->update_rtm_token($this->uid, $room_id);
|
||||
return V(1, '成功', $reslut);
|
||||
}
|
||||
|
||||
//房间信息
|
||||
public function room_info()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->room_info($this->uid, $room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//禁言 禁麦 \解禁
|
||||
public function set_mute()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$is_mute = input('is_mute', 1);//1-禁言,2-禁麦,3-解禁,4-解麦
|
||||
$reslut = model('Room')->set_mute($this->uid, $room_id, $user_id,$is_mute);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//禁麦 \解禁
|
||||
// public function set_mute_pit()
|
||||
// {
|
||||
// $room_id = input('room_id', 0);
|
||||
// $pit_number = input('pit_number', 0);
|
||||
// $is_mute = input('is_mute', 0);//0 未禁麦 1已
|
||||
// $reslut = model('Room')->set_mute_pit($this->uid, $room_id, $pit_number,$is_mute);
|
||||
// return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
// }
|
||||
|
||||
//锁麦\解锁
|
||||
public function set_lock_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$pit_number = input('pit_number', 0);
|
||||
$is_mute = input('is_lock', 0);// 0 未锁麦 1已锁麦
|
||||
$reslut = model('Room')->set_lock_pit($this->uid, $room_id, $pit_number,$is_mute);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//房间背景列表
|
||||
public function room_bg_list()
|
||||
{
|
||||
$reslut['public_bg'] = db::name('vs_room_background')->where(['upload_user'=>0,'status' => 1,'delete_time' => null])->select();
|
||||
$reslut['private_bg'] = db::name('vs_room_background')->where(['upload_user'=>$this->uid,'status' => 1,'delete_time' => null])->select();
|
||||
return V(1, '成功', $reslut);
|
||||
}
|
||||
|
||||
//上传背景图片
|
||||
public function upload_bg_img()
|
||||
{
|
||||
$id = input('id', 0);
|
||||
$image_url = input('image_url', 0);
|
||||
$reslut = model('Room')->upload_bg_img($this->uid, $image_url, $id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//关系卡,关系位
|
||||
public function relation_card()
|
||||
{
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('Room')->relation_card($this->uid, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//置顶关系卡,关系位
|
||||
public function top_relation_card()
|
||||
{
|
||||
$relation_card_id = input('id', 0);
|
||||
$reslut = model('Room')->top_relation_card($this->uid, $relation_card_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//删除关系卡,关系位
|
||||
public function delete_relation_card()
|
||||
{
|
||||
$relation_card_id = input('id', 0);
|
||||
$reslut = model('Room')->delete_relation_card($this->uid, $relation_card_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//记录房间操作
|
||||
public function room_operation_record()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 0);//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($this->uid,$room_id,$type);
|
||||
return V(1, '成功', null);
|
||||
}
|
||||
|
||||
//用户状态查询
|
||||
public function user_online_status()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', '');
|
||||
$reslut = model('Room')->user_online_status($room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//隐藏房间
|
||||
public function hide_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->hide_room($this->uid, $room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间内在线人数
|
||||
public function room_online_number()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->room_online_number($room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//房间在线列表
|
||||
public function room_online_list_ceshi()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 50);
|
||||
$reslut = model('Room')->room_online_list($room_id, $page, $limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
147
application/friendapi/controller/RoomPit.php
Normal file
147
application/friendapi/controller/RoomPit.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Db;
|
||||
|
||||
class RoomPit extends BaseCom
|
||||
{
|
||||
//申请上麦
|
||||
public function apply_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$pit_number = input('pit_number', 0);
|
||||
if($room_id == 0){
|
||||
return V(0, '房间ID不能为空', null);
|
||||
}
|
||||
$res = model('Room')->get_room_label($room_id);
|
||||
if($res['code'] != 1){
|
||||
return V(0, '房间不存在', null);
|
||||
}
|
||||
//查询房间主持麦有人吗
|
||||
$room_host_info = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
//房主,管理,主持不受此限制
|
||||
$room_owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $this->uid])->find();
|
||||
//管理
|
||||
$room_manager = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $this->uid,'type' => 2,'delete_time' => null])->find();
|
||||
//主持
|
||||
$room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $this->uid,'type' => 1,'delete_time' => null])->find();
|
||||
if($room_host_info == 0 && !$room_owner && !$room_manager && !$room_host){
|
||||
return V(0, '上麦请联系主持', null);
|
||||
}
|
||||
$room_label = $res['data']['label_id'];
|
||||
$room_type = $res['data']['type_id'];
|
||||
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4))|| $room_type == 2){
|
||||
$reslut = model('RoomPit')->apply_pit($this->uid, $room_id,$pit_number);
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
$reslut = model('RoomSong')->apply_kpit($this->uid, $room_id,$pit_number);
|
||||
}else{
|
||||
return V(0, '房间不存在', null);
|
||||
}
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($this->uid,$room_id,7,0,$pit_number);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//申请上麦列表
|
||||
public function apply_pit_list()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('RoomPit')->apply_pit_list($this->uid, $room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//上麦助力
|
||||
public function help_apply_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);
|
||||
$reslut = model('RoomPit')->help_apply_pit($this->uid, $room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//同意上麦
|
||||
public function agree_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);//逗号分割
|
||||
$reslut = model('RoomPit')->agree_pit($this->uid, $room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//拒绝上麦
|
||||
public function refuse_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', 0);//逗号分割
|
||||
$reslut = model('RoomPit')->clear_apply_pit_list($this->uid, $room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//清空上麦申请列表
|
||||
public function clear_apply_pit_list()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('RoomPit')->clear_apply_pit_list($this->uid, $room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//设置房间插麦礼物
|
||||
public function set_room_pit_apply_help_gift()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$gift_id = input('gift_id', 0);
|
||||
$gift_price = input('gift_price', 0);
|
||||
$reslut = model('RoomPit')->set_room_pit_apply_help_gift($this->uid, $room_id, $gift_id, $gift_price);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//下麦
|
||||
public function down_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$pit_number = input('pit_number', 0);
|
||||
if($room_id == 0){
|
||||
return V(0, '房间ID不能为空', null);
|
||||
}
|
||||
$res = model('Room')->get_room_label($room_id);
|
||||
if($res['code'] != 1){
|
||||
return V(0, '房间不存在', null);
|
||||
}
|
||||
$room_label = $res['data']['label_id'];
|
||||
$room_type = $res['data']['type_id'];
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)) || $room_type == 2){
|
||||
$reslut = model('RoomPit')->DownPit($this->uid, $room_id,$pit_number);
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
$reslut = model('RoomSong')->down_kpit($this->uid, $room_id);
|
||||
}
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//修改房间上麦模式
|
||||
public function change_room_up_pit_type()
|
||||
{
|
||||
$key_name = "api:room:change_room_up_pit_type:" . $this->uid;
|
||||
redis_lock_exit($key_name);
|
||||
$room_id = input('room_id', 0);
|
||||
// $user_id = input('user_id', 0);
|
||||
$reslut = model('RoomPit')->change_room_up_pit_type($this->uid, $room_id);
|
||||
redis_unlock($key_name);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//抱麦/踢麦
|
||||
public function host_user_pit()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$pit_number = input('pit_number', 0);
|
||||
$user_id = input('user_id', 0);//
|
||||
$type = input('type', 0);//1-抱麦 2-踢下去
|
||||
$reslut = model('RoomPit')->host_user_pit($this->uid, $room_id,$pit_number,$user_id,$type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
129
application/friendapi/lang/zh-cn.php
Normal file
129
application/friendapi/lang/zh-cn.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Keep login' => '保持会话',
|
||||
'Username' => '用户名',
|
||||
'User id' => '会员ID',
|
||||
'Nickname' => '昵称',
|
||||
'Password' => '密码',
|
||||
'Sign up' => '注 册',
|
||||
'Sign in' => '登 录',
|
||||
'Sign out' => '退 出',
|
||||
'Guest' => '游客',
|
||||
'Welcome' => '%s,你好!',
|
||||
'Add' => '添加',
|
||||
'Edit' => '编辑',
|
||||
'Delete' => '删除',
|
||||
'Move' => '移动',
|
||||
'Name' => '名称',
|
||||
'Status' => '状态',
|
||||
'Weigh' => '权重',
|
||||
'Operate' => '操作',
|
||||
'Warning' => '温馨提示',
|
||||
'Default' => '默认',
|
||||
'Article' => '文章',
|
||||
'Page' => '单页',
|
||||
'OK' => '确定',
|
||||
'Cancel' => '取消',
|
||||
'Loading' => '加载中',
|
||||
'More' => '更多',
|
||||
'Normal' => '正常',
|
||||
'Hidden' => '隐藏',
|
||||
'Submit' => '提交',
|
||||
'Reset' => '重置',
|
||||
'Execute' => '执行',
|
||||
'Close' => '关闭',
|
||||
'Search' => '搜索',
|
||||
'Refresh' => '刷新',
|
||||
'First' => '首页',
|
||||
'Previous' => '上一页',
|
||||
'Next' => '下一页',
|
||||
'Last' => '末页',
|
||||
'None' => '无',
|
||||
'Home' => '主页',
|
||||
'Online' => '在线',
|
||||
'Logout' => '退出',
|
||||
'Profile' => '个人资料',
|
||||
'Index' => '首页',
|
||||
'Hot' => '热门',
|
||||
'Recommend' => '推荐',
|
||||
'Dashboard' => '控制台',
|
||||
'Code' => '编号',
|
||||
'Message' => '内容',
|
||||
'Line' => '行号',
|
||||
'File' => '文件',
|
||||
'Menu' => '菜单',
|
||||
'Type' => '类型',
|
||||
'Title' => '标题',
|
||||
'Content' => '内容',
|
||||
'Append' => '追加',
|
||||
'Memo' => '备注',
|
||||
'Parent' => '父级',
|
||||
'Params' => '参数',
|
||||
'Permission' => '权限',
|
||||
'Advance search' => '高级搜索',
|
||||
'Check all' => '选中全部',
|
||||
'Expand all' => '展开全部',
|
||||
'Begin time' => '开始时间',
|
||||
'End time' => '结束时间',
|
||||
'Create time' => '创建时间',
|
||||
'Flag' => '标志',
|
||||
'Please login first' => '请登录后操作',
|
||||
'Uploaded successful' => '上传成功',
|
||||
'You can upload up to %d file%s' => '你最多还可以上传%d个文件',
|
||||
'You can choose up to %d file%s' => '你最多还可以选择%d个文件',
|
||||
'Chunk file write error' => '分片写入失败',
|
||||
'Chunk file info error' => '分片文件错误',
|
||||
'Chunk file merge error' => '分片合并错误',
|
||||
'Chunk file disabled' => '未开启分片上传功能',
|
||||
'Cancel upload' => '取消上传',
|
||||
'Upload canceled' => '上传已取消',
|
||||
'No file upload or server upload limit exceeded' => '未上传文件或超出服务器上传限制',
|
||||
'Uploaded file format is limited' => '上传文件格式受限制',
|
||||
'Uploaded file is not a valid image' => '上传文件不是有效的图片文件',
|
||||
'Are you sure you want to cancel this upload?' => '确定取消上传?',
|
||||
'Remove file' => '移除文件',
|
||||
'You can only upload a maximum of %s files' => '你最多允许上传 %s 个文件',
|
||||
'You can\'t upload files of this type' => '不允许上传的文件类型',
|
||||
'Server responded with %s code' => '服务端响应(Code:%s)',
|
||||
'File is too big (%sMiB), Max filesize: %sMiB.' => '当前上传(%sM),最大允许上传文件大小:%sM',
|
||||
'Redirect now' => '立即跳转',
|
||||
'Operation completed' => '操作成功!',
|
||||
'Operation failed' => '操作失败!',
|
||||
'Unknown data format' => '未知的数据格式!',
|
||||
'Network error' => '网络错误!',
|
||||
'Advanced search' => '高级搜索',
|
||||
'Invalid parameters' => '未知参数',
|
||||
'No results were found' => '记录未找到',
|
||||
'Parameter %s can not be empty' => '参数%s不能为空',
|
||||
'You have no permission' => '你没有权限访问',
|
||||
'An unexpected error occurred' => '发生了一个意外错误,程序猿正在紧急处理中',
|
||||
'This page will be re-directed in %s seconds' => '页面将在 %s 秒后自动跳转',
|
||||
|
||||
'操作成功' => '操作成功',
|
||||
'操作失败' => '操作失败',
|
||||
'参数错误' => '参数错误',
|
||||
'请重试' => '请重试',
|
||||
'该装扮不存在' => '该装扮不存在',
|
||||
'该装扮天数不存在' => '该装扮天数不存在',
|
||||
'该个人靓号已被购买' => '该个人靓号已被购买',
|
||||
'该房间靓号已被购买' => '该房间靓号已被购买',
|
||||
'该工会靓号已被购买' => '该工会靓号已被购买',
|
||||
'用户信息错误' => '用户信息错误',
|
||||
'非法资金类型' => '非法资金类型',
|
||||
'当前用户金币已达上限' => '当前用户金币已达上限',
|
||||
'当前用户钻石已达上限' => '当前用户钻石已达上限',
|
||||
'非法资金变动类型' => '非法资金变动类型',
|
||||
'变动的数值必须为数字' => '变动的数值必须为数字',
|
||||
'金币不足' => '金币不足',
|
||||
'钻石不足' => '钻石不足',
|
||||
'购买成功' => '购买成功',
|
||||
'购买失败' => '购买失败',
|
||||
'装扮已过期' => '装扮已过期',
|
||||
'设置失败' => '设置失败',
|
||||
'设置成功' => '设置成功',
|
||||
|
||||
|
||||
|
||||
|
||||
];
|
||||
3
application/friendapi/lang/zh-cn/common.php
Normal file
3
application/friendapi/lang/zh-cn/common.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return [];
|
||||
39
application/friendapi/lang/zh-cn/user.php
Normal file
39
application/friendapi/lang/zh-cn/user.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'User center' => '会员中心',
|
||||
'Register' => '注册',
|
||||
'Login' => '登录',
|
||||
'Sign up successful' => '注册成功',
|
||||
'Username can not be empty' => '用户名不能为空',
|
||||
'Username must be 3 to 30 characters' => '用户名必须3-30个字符',
|
||||
'Username must be 6 to 30 characters' => '用户名必须6-30个字符',
|
||||
'Password can not be empty' => '密码不能为空',
|
||||
'Password must be 6 to 30 characters' => '密码必须6-30个字符',
|
||||
'Mobile is incorrect' => '手机格式不正确',
|
||||
'Username already exist' => '用户名已经存在',
|
||||
'Nickname already exist' => '昵称已经存在',
|
||||
'Email already exist' => '邮箱已经存在',
|
||||
'Mobile already exist' => '手机号已经存在',
|
||||
'Username is incorrect' => '用户名不正确',
|
||||
'Email is incorrect' => '邮箱不正确',
|
||||
'Account is locked' => '账户已经被锁定',
|
||||
'Password is incorrect' => '密码不正确',
|
||||
'Account is incorrect' => '账户不正确',
|
||||
'Account not exist' => '账户不存在',
|
||||
'Account can not be empty' => '账户不能为空',
|
||||
'Username or password is incorrect' => '用户名或密码不正确',
|
||||
'You are not logged in' => '你当前还未登录',
|
||||
'You\'ve logged in, do not login again' => '你已经存在,请不要重复登录',
|
||||
'Profile' => '个人资料',
|
||||
'Verify email' => '邮箱验证',
|
||||
'Change password' => '修改密码',
|
||||
'Captcha is incorrect' => '验证码不正确',
|
||||
'Logged in successful' => '登录成功',
|
||||
'Logout successful' => '退出成功',
|
||||
'Operation failed' => '操作失败',
|
||||
'Invalid parameters' => '参数不正确',
|
||||
'Change password failure' => '修改密码失败',
|
||||
'Change password successful' => '修改密码成功',
|
||||
'Reset password successful' => '重置密码成功',
|
||||
];
|
||||
37
application/friendapi/library/ExceptionHandle.php
Normal file
37
application/friendapi/library/ExceptionHandle.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\library;
|
||||
|
||||
use Exception;
|
||||
use think\exception\Handle;
|
||||
|
||||
/**
|
||||
* 自定义API模块的错误显示
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
|
||||
public function render(Exception $e)
|
||||
{
|
||||
// 在生产环境下返回code信息
|
||||
if (!\think\Config::get('app_debug')) {
|
||||
$statuscode = $code = 500;
|
||||
$msg = 'An error occurred';
|
||||
// 验证异常
|
||||
if ($e instanceof \think\exception\ValidateException) {
|
||||
$code = 0;
|
||||
$statuscode = 200;
|
||||
$msg = $e->getError();
|
||||
}
|
||||
// Http异常
|
||||
if ($e instanceof \think\exception\HttpException) {
|
||||
$statuscode = $code = $e->getStatusCode();
|
||||
}
|
||||
return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
|
||||
}
|
||||
|
||||
//其它此交由系统处理
|
||||
return parent::render($e);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user