|
@@ -83,11 +83,11 @@ class VPush
|
|
|
'skipType' => $this->_skipType,
|
|
|
'skipContent' => $this->_skipContent,
|
|
|
'networkType' => $this->_networkType,
|
|
|
- 'clientCustomMap' => [],
|
|
|
+ 'clientCustomMap' => (object)[],
|
|
|
];
|
|
|
|
|
|
// 请求服务接口
|
|
|
- $result = $this->getData(config('push.vivo.saveListPayload'), $data);
|
|
|
+ $result = $this->getData(config('push.server.vivo.saveListPayload'), $data);
|
|
|
$this->_taskId = getProp($result, 'taskId');
|
|
|
return $result;
|
|
|
}
|
|
@@ -100,7 +100,7 @@ class VPush
|
|
|
public function sendMessage()
|
|
|
{
|
|
|
// 参数判断
|
|
|
- $this->checkParam();
|
|
|
+ $this->checkParam(true);
|
|
|
if (!$this->_taskId) {
|
|
|
throw new InvalidArgumentException('VIVO推送必须要设置taskId');
|
|
|
}
|
|
@@ -111,7 +111,7 @@ class VPush
|
|
|
'requestId' => Utils::randCode(),
|
|
|
];
|
|
|
|
|
|
- return $this->getData(config('push.vivo.pushToList'), $data);
|
|
|
+ return $this->getData(config('push.server.vivo.pushToList'), $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -122,7 +122,7 @@ class VPush
|
|
|
public function sendAll()
|
|
|
{
|
|
|
// 校验参数
|
|
|
- $this->checkParam();
|
|
|
+ $this->checkSendAllParam();
|
|
|
$data = [
|
|
|
'requestId' => Utils::randCode(),
|
|
|
'title' => $this->_title,
|
|
@@ -132,10 +132,10 @@ class VPush
|
|
|
'skipType' => $this->_skipType,
|
|
|
'skipContent' => $this->_skipContent,
|
|
|
'networkType' => $this->_networkType,
|
|
|
- 'clientCustomMap' => [],
|
|
|
+ 'clientCustomMap' => (object)[],
|
|
|
];
|
|
|
|
|
|
- return $this->getData(config('push.vivo.sendAll'), $data);
|
|
|
+ return $this->getData(config('push.server.vivo.sendAll'), $data);
|
|
|
}
|
|
|
|
|
|
public function addTagForUsers($tag, $regIds)
|
|
@@ -164,7 +164,7 @@ class VPush
|
|
|
$this->getAccessToken();
|
|
|
|
|
|
// 拼接链接
|
|
|
- $url = config('push.vivo.getStatistics');
|
|
|
+ $url = config('push.server.vivo.getStatistics');
|
|
|
$url .= '?taskIds=' . implode(',', $taskIds);
|
|
|
|
|
|
return $this->getData($url, [], 'GET');
|
|
@@ -200,9 +200,46 @@ class VPush
|
|
|
if (!$this->_content) {
|
|
|
throw new InvalidArgumentException('VIVO推送必须要设置content');
|
|
|
}
|
|
|
+ if (!$this->_timeToLive) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置timeToLive');
|
|
|
+ }
|
|
|
if (!$this->_regId) {
|
|
|
throw new InvalidArgumentException('VIVO推送必须要设置regId');
|
|
|
}
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验参数
|
|
|
+ * @param false $sendAll
|
|
|
+ * @return $this
|
|
|
+ * @throws GuzzleException
|
|
|
+ */
|
|
|
+ private function checkSendAllParam()
|
|
|
+ {
|
|
|
+ // 授权token校验
|
|
|
+ if (!$this->_accessToken) {
|
|
|
+ $this->getAccessToken();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$this->_appId) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置appId');
|
|
|
+ }
|
|
|
+ if (!$this->_appKey) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置appKey');
|
|
|
+ }
|
|
|
+ if (!$this->_appSecret) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置appSecret');
|
|
|
+ }
|
|
|
+ if (!$this->_accessToken) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置AccessToken');
|
|
|
+ }
|
|
|
+ if (!$this->_title) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置title');
|
|
|
+ }
|
|
|
+ if (!$this->_content) {
|
|
|
+ throw new InvalidArgumentException('VIVO推送必须要设置content');
|
|
|
+ }
|
|
|
if (!$this->_timeToLive) {
|
|
|
throw new InvalidArgumentException('VIVO推送必须要设置timeToLive');
|
|
|
}
|
|
@@ -223,7 +260,7 @@ class VPush
|
|
|
];
|
|
|
$sign = md5($sendData['appId'] . $sendData['appKey'] . $sendData['timestamp'] . $this->_appSecret);
|
|
|
$sendData['sign'] = $sign;
|
|
|
- $url = config('push.vivo.auth');
|
|
|
+ $url = config('push.server.vivo.auth');
|
|
|
$data = $this->getData($url, $sendData);
|
|
|
$this->_accessToken = getProp($data, 'authToken');
|
|
|
|
|
@@ -241,20 +278,21 @@ class VPush
|
|
|
private function getData($url, $sendData, $method = 'POST')
|
|
|
{
|
|
|
// 组装请求数据
|
|
|
- $option = ['json' => $sendData];
|
|
|
+ $authToken = $this->_accessToken;
|
|
|
+ $option = ['json' => $sendData];
|
|
|
|
|
|
// 请求
|
|
|
- $client = new Client(['timeout' => 10.0, 'headers' => ['auth_token' => $this->_accessToken]]);
|
|
|
+ $client = new Client(['timeout' => 5.0, 'headers' => ['authToken' => $authToken]]);
|
|
|
if ($method === 'POST') {
|
|
|
$response = $client->request('POST', $url, $option);
|
|
|
} else {
|
|
|
$response = $client->request('GET', $url);
|
|
|
}
|
|
|
|
|
|
- $body = $response->getBody();
|
|
|
+ $body = $response->getBody()->__toString();
|
|
|
$result = json_decode($body, true);
|
|
|
|
|
|
- myLog('getDataByInfo', ['url' => $url, 'option' => $option, 'res' => $result]);
|
|
|
+ myLog('push')->info('[VIVO] getDataByInfo', compact('url', 'option', 'authToken', 'result'));
|
|
|
return $result;
|
|
|
}
|
|
|
}
|