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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。