doucang6914 2014-06-06 08:15
浏览 21
已采纳

在GET上添加到PHP变量

This PHP file that sends a push GCM

I tried to add another variable to file "val" And probably made ​​a mistake that the file is not working right now.

<?php
define("GOOGLE_API_KEY", "AIzaSyBNSwEoWlFQAW9AoHvlMcf2eXx2NchURaE");
define("GOOGLE_GCM_URL", "https://android.googleapis.com/gcm/send");

function send_gcm_notify($reg_id, $message, $val1) {

    $fields = array(
        'registration_ids'  => array( $reg_id ),
        'data'              => array( "message" => $message ),
        'data'              => array( "val1" => $val1 ),
    );

    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY,
        'Content-Type: application/json'
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, GOOGLE_GCM_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Problem occurred: ' . curl_error($ch));
    }

    curl_close($ch);
    echo $result;
 }

$reg_id = file_get_contents("TXTreg.txt");
$msg = filter_input (INPUT_GET, 'msg', FILTER_SANITIZE_EMAIL);
$val = filter_input (INPUT_GET, 'val', FILTER_SANITIZE_EMAIL);
send_gcm_notify($reg_id, $msg, $val1);

What should be done to the file will work with the variable "val"?

  • 写回答

1条回答 默认 最新

  • douliao8402 2014-06-06 08:17
    关注

    you are passing data index in array more than once, change:

    $fields = array(
        'registration_ids'  => array( $reg_id ),
        'data'              => array( "message" => $message ),
        'data'              => array( "val1" => $val1 ),
    );
    

    to

    $fields = array(
        'registration_ids'  => array( $reg_id ),
        'data'              => array( "message" => $message, "val1" => $val1 )
    );
    

    and you declared $val variable and are trying to use $val1, change to:

    $val = filter_input (INPUT_GET, 'val', FILTER_SANITIZE_EMAIL);
    send_gcm_notify($reg_id, $msg, $val);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路