房间密码
This commit is contained in:
@@ -39,7 +39,7 @@ class Room extends BaseCom
|
||||
$room_cover = input('room_cover', '');
|
||||
$room_intro = input('room_intro', '');
|
||||
$room_background_id = input('room_background', '');
|
||||
$password = input('password');
|
||||
$password = input('room_password');
|
||||
if($room_id <= 0){
|
||||
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
96
application/api/controller/Wechat.php
Normal file
96
application/api/controller/Wechat.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
class Wechat extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 核心:用code换取openid的方法
|
||||
* @param string $code 微信回调带来的code
|
||||
* @return string|bool 成功返回openid,失败返回false
|
||||
*/
|
||||
private function exchangeCodeForOpenId()
|
||||
{
|
||||
$code = input('code', 0);
|
||||
|
||||
// 构建请求URL
|
||||
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?" .
|
||||
"appid={$this->appId}&" .
|
||||
"secret={$this->appSecret}&" .
|
||||
"code={$code}&" .
|
||||
"grant_type=authorization_code";
|
||||
|
||||
Log::info('[微信授权] 请求微信接口URL:' . $url);
|
||||
|
||||
// 发送请求
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
Log::error('[微信授权] 请求失败:' . curl_error($ch));
|
||||
curl_close($ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
Log::info('[微信授权] 微信返回原始数据:' . $response);
|
||||
|
||||
// 解析返回的JSON
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (empty($data) || isset($data['errcode'])) {
|
||||
Log::error('[微信授权] 解析失败或返回错误', $data);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 成功获取到openid
|
||||
return $data['openid'] ?? false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 获取用户信息
|
||||
* @param string $user_code 用户的user_code
|
||||
* @return array|bool 成功返回用户信息,失败返回false
|
||||
*/
|
||||
public function getUserInfo($user_code)
|
||||
{
|
||||
$user_info = db::name('user')
|
||||
->field('id user_id,nickname,avatar,mobile')
|
||||
->where(['u.user_code' => $user_code,'u.status' => ['<>',0]])->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '用户不存在或已注销', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 可充值的金额
|
||||
* @param string $user_code 用户的user_code
|
||||
* @return array|bool 充值金额,失败返回false
|
||||
*/
|
||||
public function getRechargeMoney($user_code)
|
||||
{
|
||||
$money_coin = [
|
||||
['coin' => '1', 'money' => '0.10'],
|
||||
['coin' => '60', 'money' => '6.00'],
|
||||
['coin' => '1000', 'money' => '100.00'],
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $money_coin];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class Room extends Model
|
||||
$data['room_background'] = $room_background_id;
|
||||
}
|
||||
if($password){
|
||||
$data['password'] = $password;
|
||||
$data['room_password'] = $password;
|
||||
}
|
||||
if(!empty($data)){
|
||||
$reslut = $this->where('id', $room_id)->update($data);
|
||||
@@ -965,6 +965,11 @@ class Room extends Model
|
||||
$room_names = db::name('vs_room')->where(['id' => $room_pit])->value('room_name');
|
||||
return ['code' => 202, 'msg' => '您已经在房间'.$room_names.'中,请先下麦后并退出房间', 'data' => ['room_id' => $room_pit,'msg'=>'您在'.$room_names .'房间游戏中,不支持进入新房间']];
|
||||
}
|
||||
|
||||
if($room['room_password'] != ''){
|
||||
return ['code' => 101, 'msg' => '密码房', 'data' => ''];
|
||||
}
|
||||
|
||||
return ['code' => 1,
|
||||
'msg' => '成功',
|
||||
'data' => null
|
||||
@@ -1027,8 +1032,8 @@ class Room extends Model
|
||||
Cache::set('room_info_' . $room_id, json_encode($room), 7200);
|
||||
}
|
||||
|
||||
if(isset($room['password']) && $user_id != $room['user_id']){
|
||||
if (empty($password) || $room['password'] != md5($password)) {
|
||||
if(isset($room['room_password']) && $user_id != $room['user_id']){
|
||||
if (empty($password) || $room['room_password'] != $password) {
|
||||
return ['code' => 0, 'msg' => '密码错误', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user