更新直播送礼
This commit is contained in:
parent
6bc794b48b
commit
65f4469139
@ -30,45 +30,14 @@ use GuzzleHttp\Client;
|
|||||||
*/
|
*/
|
||||||
class Zhibo extends BaseController
|
class Zhibo extends BaseController
|
||||||
{
|
{
|
||||||
private $checkUrl = 'http://ceshi-zhibo.lihaink.cn/api/zhibo/checkGift';
|
|
||||||
private $giftUrl = 'http://ceshi-zhibo.lihaink.cn/api/zhibo/sendGiftMessage';
|
|
||||||
|
|
||||||
//用户直播送礼
|
//用户直播送礼
|
||||||
public function reward()
|
public function reward()
|
||||||
{
|
{
|
||||||
$params = $this->request->params(['live_stream_id', 'gift_id', 'master_id']);
|
$params = $this->request->params(['live_stream_id', 'gift_id', 'master_id']);
|
||||||
$user = $this->request->userInfo();
|
$user = $this->request->userInfo();
|
||||||
if (empty($params['live_stream_id']) || empty($params['master_id']) || empty($params['gift_id'])) {
|
if (empty($params['live_stream_id']) || empty($params['master_id']) || empty($params['gift_id'])) {
|
||||||
return app('json')->fail('live_stream_id, master_id, gift_id 参数不能为空');
|
return app('json')->fail('live_stream_id, master_id, gift_id, live_name, gift_name, amount 参数不能为空');
|
||||||
}
|
}
|
||||||
$token = request()->header('x-token');
|
|
||||||
//查询直播间及礼物接口,验证直播间信息及礼物信息
|
|
||||||
|
|
||||||
try {
|
|
||||||
$client = new Client();
|
|
||||||
$response = $client->request('POST', $this->checkUrl, [
|
|
||||||
// 'timeout' => 5,
|
|
||||||
'verify' => false,
|
|
||||||
'headers' => ['X-Token' => $token],
|
|
||||||
'json' => [
|
|
||||||
"live_stream_id" => $params['live_stream_id'],
|
|
||||||
"master_id" => $params['master_id'],
|
|
||||||
"gift_id" => $params['gift_id']
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
$responseData = json_decode($response->getBody()->getContents(), true);
|
|
||||||
} catch (RequestException $e) {
|
|
||||||
return app('json')->fail($e->getMessage());
|
|
||||||
}
|
|
||||||
$responseData = json_decode($response->getBody()->getContents(), true);
|
|
||||||
if (empty($responseData['code'])) {
|
|
||||||
$failMsg = $responseData['msg'];
|
|
||||||
return app('json')->fail($failMsg);
|
|
||||||
}
|
|
||||||
$giftData = $responseData['data'];
|
|
||||||
$params['live_name'] = $giftData['live_name'];
|
|
||||||
$params['gift_name'] = $giftData['gift_name'];
|
|
||||||
$params['amount'] = $giftData['gift_price'];
|
|
||||||
if ($params['amount'] > $user['now_money']) {
|
if ($params['amount'] > $user['now_money']) {
|
||||||
return app('json')->fail('余额不足');
|
return app('json')->fail('余额不足');
|
||||||
}
|
}
|
||||||
@ -118,19 +87,6 @@ class Zhibo extends BaseController
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return app('json')->fail($e->getMessage());
|
return app('json')->fail($e->getMessage());
|
||||||
}
|
}
|
||||||
//发送礼物消息
|
|
||||||
$message = "{$user['nickname']} 送出了 {$params['gift_name']}";
|
|
||||||
$client = new Client();
|
|
||||||
$client->request('POST', $this->giftUrl, [
|
|
||||||
'verify' => false,
|
|
||||||
'headers' => ['X-Token' => $token],
|
|
||||||
'json' => [
|
|
||||||
"live_stream_id" => $params['live_stream_id'],
|
|
||||||
"app_name" => 'shop',
|
|
||||||
"gift_id" => $params['gift_id'],
|
|
||||||
"message" => $message
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
return app('json')->success('送礼成功');
|
return app('json')->success('送礼成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user