使用Pushme.to将推送通知发送到iphone

时间:2011-11-25 15:37:28

标签: php iphone curl push-notification

我正在使用http://www.barattalo.it/2010/08/09/send-push-notification-to-iphone-with-php-and-pushme-to/

当我调用该函数时,我收到错误消息。

Notice: Undefined offset: 1 in <PATH>ServiceDesk.php on line 15

Notice: Undefined offset: 1 in <PATH>ServiceDesk.php on line 15

Notice: Undefined offset: 1 in <PATH>ServiceDesk.php on line 17

这是代码

function pushMeTo($widgeturl,$text,$signature) {
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12";
    if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $widgeturl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    $page = curl_exec($ch);
    preg_match("/form action=\"(.*?)\"/", $page, $form_action);
    preg_match("/textarea name=\"(.*?)\"/", $page, $message_field);
    preg_match("/input type=\"text\" name=\"(.*?)\"/", $page, $signature_field);
    $ch = curl_init();
    $strpost = $message_field[1].'=' . urlencode($text) . '&'.$signature_field[1].'=' . urlencode($signature);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $strpost );
    curl_setopt($ch, CURLOPT_URL, $form_action[1]);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    $page = curl_exec($ch);
}


$url = "<MY URL HERE>";
 pushmeTo ($url,"This Is A Test","ServiceDesk");

我之前从未使用过CURL,但我对PHP没问题。

我怀疑它可能是代理问题,但我只允许在每个脚本的基础上设置代理。任何人都可以告诉我如何在此脚本中使用CURL设置代理。

谢谢,

1 个答案:

答案 0 :(得分:1)

$form_action[1]未定义(意思是你在$ form_action数组中的索引1没有任何东西),所以我会在第一个curl_exec之后查看$page,并且在这里正则表达式preg_match("/form action=\"(.*?)\"/", $page, $form_action);


编辑

再看一下,看起来你所有的正则表达式都失败了所以再看看$page并且所有的shure使正则表达式返回的所有值都是你需要的。