|
|
@@ -2,6 +2,10 @@
|
|
|
|
|
|
namespace common\components;
|
|
|
|
|
|
+use GTClient;
|
|
|
+use GTNotification;
|
|
|
+use GTPushMessage;
|
|
|
+use GTPushRequest;
|
|
|
use GuzzleHttp\Client;
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
use Yii;
|
|
|
@@ -47,6 +51,34 @@ class pushNotice
|
|
|
$api->pushApi()->pushToSingleByCid($push);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static function nPush($adminId, $cId, $title, $body)
|
|
|
+ {
|
|
|
+ //设置推送参数
|
|
|
+ $time = time();
|
|
|
+ $rand = rand(1000, 9999);
|
|
|
+ $rId = $time . $rand . $adminId;
|
|
|
+ $push = new GTPushRequest();
|
|
|
+ $push->setRequestId($rId);
|
|
|
+ $message = new GTPushMessage();
|
|
|
+ $notify = new GTNotification();
|
|
|
+ $notify->setTitle($title);
|
|
|
+ $notify->setBody($body);
|
|
|
+
|
|
|
+ //点击通知后续动作,目前支持以下后续动作:
|
|
|
+ //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
|
|
|
+ $notify->setClickType("startapp");
|
|
|
+ $message->setNotification($notify);
|
|
|
+ $push->setPushMessage($message);
|
|
|
+ $push->setCid($cId);
|
|
|
+
|
|
|
+ //创建API,APPID等配置参考 环境要求 进行获取
|
|
|
+ $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
|
|
|
+ //处理返回结果
|
|
|
+ $result = $api->pushApi()->pushToSingleByCid($push);
|
|
|
+ Yii::info('push/single/cid: ' . json_encode($result));
|
|
|
+ }
|
|
|
+
|
|
|
// 执行cid单推
|
|
|
public static function newPush($cId, $title, $body)
|
|
|
{
|
|
|
@@ -97,7 +129,10 @@ class pushNotice
|
|
|
{
|
|
|
$i = 0;
|
|
|
do{
|
|
|
- $client = new Client(['timeout' => 5.0]);
|
|
|
+ $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),
|