You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB
PHTML

5 years ago
<?php
namespace Base\Tool;
use GuzzleHttp\Client;
class ServiceClient
{
const SUCCESS = '0000';
protected $client;
public function __construct()
{
$this->client = new Client([
'base_uri' => C('SERVICE_URL'),
'timeout' => 10.0,
]);
}
protected function post($uri, $data)
{
$response = $this->client->post($uri, [
'verify' => false,
'form_params' => $data
]);
$result = (string)$response->getBody();
return json_decode($result, true);
}
public function sendSmsCode(string $mobile, string $clientIp)
{
$options = ['type' => 'code', 'client_ip' => $clientIp];
return $this->sendSms($mobile, $options);
}
public function sendSmsContent(string $mobile, string $content)
{
$options = ['type' => 'content', 'content' => $content];
return $this->sendSms($mobile, $options);
}
public function sendSmsBatch(array $mobiles, string $content)
{
$options = ['type' => 'batch', 'content' => $content];
return $this->sendSms($mobiles, $options);
}
private function sendSms($mobile, array $options)
{
return $this->post('/message/sms-send', ['mobile' => $mobile, 'options' => $options]);
}
public function checkSms($mobile, $code)
{
return $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]);
}
public function registerEvent($userId, $source)
{
return $this->post('/game-event/register', ['user_id' => $userId, 'source' => $source]);
}
}