【问题标题】:Pushwoosh Remote API for cordova用于科尔多瓦的 Pushwoosh 远程 API
【发布时间】:2014-10-09 08:49:24
【问题描述】:

我想通过pushwoosh从客户端(我的科尔多瓦(离子)应用程序)发送推送通知。

是否有任何示例代码或指南?

谢谢!

【问题讨论】:

    标签: javascript cordova ionic-framework pushwoosh


    【解决方案1】:

    您必须使用需要付费计划的Remote Access API。 我创建了一个对象,其中包含我要发送的文本和我要发送到的设备令牌,并将其作为参数传递给以下函数:

    function push(object) {
      var params = {
        "request": {
          "application": "PW_ID GOES HERE",
          "auth": "Find in your API Access page",
          "notifications": [{
            // Content Settings
            "send_date": "now",
            "ignore_user_timezone": true,
            "content": {
              "en": object.text
            },
            "platforms": [1, 3], // 1 - iOS; 3 - Android;
            // iOS Related
            "ios_category_id": "1",
            "ios_badges": "+1",
            // Android Related
            "android_icon": "icon",
            // Who to send it to
            "devices": object.tokens
          }]
        }
      };
      $http.post('https://cp.pushwoosh.com/json/1.3/createMessage', params).then(success, failure);
    
      function success() {
        console.log("successful notification push");
      }
    
      function failure(error) {
        console.log('error sending notification', error);
      }
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 我已经成功地为cordova android设置了一切,当我从pushwoosh.com发送它时,我的设备正在接收推送通知。我在用于 sending 来自客户端的推送通知的 phonegap 插件的存储库中找不到任何示例代码。我忽略了什么吗?
      • 您无法从客户端推送。客户端(设备)只能注册接收通知。
      • 我也遇到了同样的问题,你找到解决办法了吗?
      【解决方案3】:

      这是我使用的东西

      • 向服务器发送请求

      $http.get('http://test.com/push.php?token=' + ushToken + '&message=' + encodeURIComponent(message)).then(function (resp) {
      }, function (err) {
          console.error(err);
      });
      • 在服务器端做

      <?php
      
      define('PW_AUTH', '...');
      define('PW_APPLICATION', '...');
      define('PW_DEBUG', FALSE);
      
      function pwCall($method, $data)
      {
      	$url     = 'https://cp.pushwoosh.com/json/1.3/' . $method;
      	$request = json_encode(['request' => $data]);
      
      	$ch = curl_init($url);
      	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      	curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
      	curl_setopt($ch, CURLOPT_HEADER, TRUE);
      	curl_setopt($ch, CURLOPT_POST, TRUE);
      	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
      
      	$response = curl_exec($ch);
      	$info     = curl_getinfo($ch);
      	curl_close($ch);
      
      	if (defined('PW_DEBUG') && PW_DEBUG) {
      		var_dump(json_decode($request));
      		var_dump($response);
      		var_dump($info);
      	}
      }
      
      if (isset($_GET['message']) && isset($_GET['token'])) {
      	$payload = [
      		'application'   => PW_APPLICATION,
      		'auth'          => PW_AUTH,
      		'notifications' => [
      			[
      				'send_date' => 'now',
      				'content'   => $_GET['message'],
      				'devices'   => [$_GET['token']]
      			]
      		]
      	];
      
      	pwCall('createMessage', $payload);
      }

      【讨论】:

        猜你喜欢
        • 2016-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-27
        • 2017-06-08
        相关资源
        最近更新 更多