PUSH ERROR 成功解析推送发送后收到来自 Parse 的无效 JSON 错误

Posted

技术标签:

【中文标题】PUSH ERROR 成功解析推送发送后收到来自 Parse 的无效 JSON 错误【英文标题】:PUSH ERRORReceived an error with invalid JSON from Parse after successful parse push send 【发布时间】:2017-12-05 12:11:07 【问题描述】:

推送成功后出现以下错误,阻止推送:

0|parse-wr | #### PUSH ERRORReceived an error with invalid JSON from Parse: <html>
0|parse-wr | <head><title>400 Bad Request</title></head>
0|parse-wr | <body bgcolor="white">
0|parse-wr | <center><h1>400 Bad Request</h1></center>
0|parse-wr | <hr><center>nginx/1.10.3 (Ubuntu)</center>
0|parse-wr | </body>
0|parse-wr | </html>

这是在我更改了我的 ubuntu 服务器 DNS 之后发生的,这里是我的 nginx 站点启用/默认

server 
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
        root /mnt/psapp/;
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name psappco.ir www.psappco.ir;

        location / 
           try_files $uri $uri/ =404;
         
        # location /test 
          # root /mnt/psapp;
        # 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ 
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht 
        #       deny all;
        #

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/psappco.ir/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/psappco.ir/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



    if ($scheme != "https") 
        return 301 https://$host$request_uri;
     # managed by Certbot


    # Redirect non-https traffic to https
    # if ($scheme != "https") 
    #     return 301 https://$host$request_uri;
    #  # managed by Certbot
    location /parse/ 
 proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:1337/parse/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                # WebSocket support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        
        location /dashboard/ 
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-NginX-Proxy true;
         proxy_pass http://localhost:4040/dashboard/;
         proxy_ssl_session_reuse off;
         proxy_set_header Host $http_host;
         proxy_redirect off;
        
        client_max_body_size 100M;

我是否应该在 nginx 中添加与推送适配器相关的内容,我已经使用 let encrypt 激活了 ssl。 nginx版本:nginx/1.10.3(Ubuntu) 解析服务器版本 2.3.8 我使用的云代码是:

Parse.Cloud.define('driveRequest', function(request, response) 
    // request has 2 parameters: params passed by the client and the authorized user
    var params = request.params;
    var user = request.user;
    // extract out the channel to send
    var action = params.action;
    var launch = params.launch;
    // use to custom tweak whatever payload you wish to send
    var pushQuery = new Parse.Query(Parse.Installation);
    var driverQuery = new Parse.Query(Parse.User);
    driverQuery.equalTo("isonline",true);
    driverQuery.equalTo("riderordriver","driver");
    //var nearbyDriversQuery = new Parse.Query(Parse.User);
    var riderLocation = new Parse.GeoPoint(latitude: params.riderLatitude, longitude: params.riderLongitude);
    driverQuery.withinKilometers("location",riderLocation,2.0);
    //var driverQuery = Parse.Query.or(nearbyDriversQuery,isOnlineQuery);
    pushQuery.matchesQuery('users',driverQuery);
   // pushQuery.matchesQuery('isonlineusers',isOnlineQuery);
    var payload = 
        "action": action,
        "launch": launch,
    ;

    // Note that useMasterKey is necessary for Push notifications to succeed.

    Parse.Push.send(
        where: pushQuery,
        data: payload
    ,  success: function() 
        console.log("#### PUSH OK");
    , error: function(error) 
        console.log("#### PUSH ERROR" + error.message);
    ,useMasterKey:true);
    response.success('success');
);

和 ParseServer index.js:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');  
var path = require('path');
var FSStoreAdapter = require('parse-server-fs-store-adapter');
var fs_store_adapter = new FSStoreAdapter(
    filesSubDirectory: "/root/parsefiles" 
);
//var Parse = require('parse/node').Parse;

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) 
  console.log('DATABASE_URI not specified, falling back to localhost.');


var pushConfig = ;

if (process.env.GCM_SENDER_ID && process.env.GCM_API_KEY) 
    pushConfig['android'] =  senderId: process.env.GCM_SENDER_ID || 'my sender id',
                              apiKey: process.env.GCM_API_KEY || 'my key';


var api = new ParseServer(
  databaseURI: databaseUri || 'mongodb://localhost:27017/taxifinder',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'My app_ID',
  masterKey: process.env.MASTER_KEY || 'My master key', //Add your master key here. Keep it secret!
  push: pushConfig,
  filesAdapter: fs_store_adapter,
  serverURL: process.env.SERVER_URL || 'https/localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: 
    classNames: ['Test'],
    redisURL: 'redis://localhost:6379'
  ,
  maxUploadSize: "100mb"
);
var app = express();
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
//app.get('/', function(req, res) 
 // res.status(200).send('I dream of being a website.  Please star the parse-server repo on GitHub!');
//      res.sendFile(path.join(__dirname, '/public/index.html'));
//);

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() 
    console.log('parse-server-example running on port ' + port + '.');
);
ParseServer.createLiveQueryServer(httpServer,
        redisURL: 'redis://localhost:6379'
);

var dashboard = new ParseDashboard(  
  "apps": [
      "serverURL": 'https://psappco.ir/parse', // Not localhost
      "appId": 'my app id',
      "masterKey": 'My master key',
      "appName": "PSAPP",
      "production": false,
      "iconName": "app-icon.png",
  ],
  "users": [
    
      "user":"---",
      "pass":"----"
    
  ],
  "iconsFolder": "icons"
);

var dashApp = express();

// make the Parse Dashboard available at /dashboard
dashApp.use('/dashboard', dashboard);  

// Parse Server plays nicely with the rest of your web routes
dashApp.get('/', function(req, res)   
  res.status(200).send('Parse Dashboard App');
);

var httpServerDash = require('http').createServer(dashApp);  
httpServerDash.listen(4040, function()   
    console.log('dashboard-server running on port 4040.');
);

【问题讨论】:

【参考方案1】:

这可能与您的配置有关。 SERVER_URL 的值是多少?是否包含/parse

【讨论】:

以上是关于PUSH ERROR 成功解析推送发送后收到来自 Parse 的无效 JSON 错误的主要内容,如果未能解决你的问题,请参考以下文章

APNS Apple 推送通知服务未收到来自 Apple 的成功消息

解析,如何向目标用户发送推送通知

解析推送通知发送数据

推送通知在 iphone 中没有收到来自 Parse.com 服务器的某些时间

push message (短消息推送) 技术Java怎么实现,有没有大神可以讲解一下

Android push推送消息到达成功率优化