小编Rud*_*udy的帖子

Windows通知服务:401尝试在PHP中创建Toast通知时无效令牌

我一直在尝试向模拟器发送Toast通知.我创建了Windows Phone 8.1应用程序,并将其与商店中的应用程序相关联.之后我设法获得了我必须用来调用通道URI的访问令牌.

当我尝试使用通道URI和访问令牌发送Toast通知时,我收到此错误.

Bearer error="invalid_request",error_description="Invalid token"
Run Code Online (Sandbox Code Playgroud)

这是我创建的php测试代码.

<?php

    //GET ACCESS TOKEN
    $tokenRequest = curl_init();
    curl_setopt($tokenRequest, CURLOPT_URL, 'https://login.live.com/accesstoken.srf');

    curl_setopt($tokenRequest, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded'
    ));

    //FIELDS
    $fields = array(
        'grant_type' => 'client_credentials',
        'client_id' => '0',
        'client_secret' => 'Q',
        'scope' => 'notify.windows.com'
    );

    $fields_string = "";
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    curl_setopt($tokenRequest, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($tokenRequest,CURLOPT_POST, count($fields));
    curl_setopt($tokenRequest,CURLOPT_POSTFIELDS, $fields_string);

    $output = json_decode(curl_exec($tokenRequest));
    curl_close($tokenRequest);
    echo "<br>";
    var_dump($output);
    echo "<br>";
    $accessToken = $output->{'access_token'};


    //SEND PUSH
    $sendPush = curl_init();
    curl_setopt($sendPush, CURLOPT_URL, …
Run Code Online (Sandbox Code Playgroud)

php c# push-notification windows-phone-8

0
推荐指数
1
解决办法
853
查看次数

标签 统计

c# ×1

php ×1

push-notification ×1

windows-phone-8 ×1