|
|
@@ -28,9 +28,6 @@ class pushNotice
|
|
|
const appId = 'YjALucIHmI7DylcjlMZEx2';
|
|
|
const masterSecret = 'zSbdBLOQrxAa5IcDNqIne7';
|
|
|
|
|
|
- //版本2:个推开放平台接口前缀(BaseUrl): https://restapi.getui.com/v2/$appId
|
|
|
- const baseUrl = 'https://restapi.getui.com/v2';
|
|
|
-
|
|
|
public static function push($adminId, $cId, $title, $body)
|
|
|
{
|
|
|
$notify = new GTNotification();
|
|
|
@@ -168,7 +165,7 @@ class pushNotice
|
|
|
$push->setPushChannel($pushChannel);
|
|
|
|
|
|
|
|
|
- //创建API,APPID等配置参考 环境要求 进行获取
|
|
|
+ //创建API,APPID等配置
|
|
|
$api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
|
|
|
//处理返回结果
|
|
|
$result = $api->pushApi()->pushToSingleByCid($push);
|
|
|
@@ -181,75 +178,4 @@ class pushNotice
|
|
|
$time = ($sec . substr($usec, 2, 3));
|
|
|
return $time;
|
|
|
}
|
|
|
-
|
|
|
- // 执行cid单推
|
|
|
- public static function newPush($cId, $title, $body)
|
|
|
- {
|
|
|
- $bodyArr['title'] = $title;
|
|
|
- $bodyArr['body'] = $body;
|
|
|
- $bodyArr['click_type'] = 'startapp';
|
|
|
-
|
|
|
- $token = Yii::$app->redis->executeCommand('GET', ['getui_token']);
|
|
|
-
|
|
|
- if (empty($token)) {
|
|
|
- $token = self::getToken();
|
|
|
- if ($token == "") {
|
|
|
- Yii::error('generate getui token fail');
|
|
|
- return;
|
|
|
- }
|
|
|
- Yii::$app->redis->executeCommand('SET', ['getui_token', $token, 'EX', 86400]);
|
|
|
- }
|
|
|
-
|
|
|
- $client = new Client([
|
|
|
- 'base_uri' => self::baseUrl,
|
|
|
- 'timeout' => 5.0,
|
|
|
- ]);
|
|
|
-
|
|
|
- try {
|
|
|
- $response = $client->request('POST', self::baseUrl . '/push/single/cid', [
|
|
|
- 'form_params' => [
|
|
|
- 'request_id' => time(),
|
|
|
- 'settings' => ['ttl' => 86400000],
|
|
|
- 'audience' => [
|
|
|
- 'cid' => $cId,
|
|
|
- ],
|
|
|
- 'push_message' => [
|
|
|
- 'notification' => $bodyArr
|
|
|
- ],
|
|
|
- 'headers' => [
|
|
|
- 'token' => $token
|
|
|
- ]
|
|
|
- ]
|
|
|
- ]);
|
|
|
- } catch (GuzzleException $e) {
|
|
|
- Yii::error('push/single/cid: ' . $e->getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 失败,则生重新获取 token ,再发送
|
|
|
- }
|
|
|
-
|
|
|
- public static function getToken()
|
|
|
- {
|
|
|
- $i = 0;
|
|
|
- do{
|
|
|
- $client = new Client([
|
|
|
- 'base_uri' => self::baseUrl,
|
|
|
- 'timeout' => 5.0
|
|
|
- ]);
|
|
|
- $response = $client->request('POST', self::baseUrl . '/auth', [
|
|
|
- 'form_params' => [
|
|
|
- "sign" => hash('sha256', self::appKey . time() . self::masterSecret),
|
|
|
- "timestamp" => round(microtime(true) * 1000),
|
|
|
- "appkey" => self::appKey
|
|
|
- ]
|
|
|
- ]);
|
|
|
- $data = json_decode($response, true);
|
|
|
- }while(!isset($data['data']['token']) && $i++ < 3);
|
|
|
-
|
|
|
- if ($i > 3) {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- return $data['data']['token'];
|
|
|
- }
|
|
|
}
|