gpt4 book ai didi

php - Azure 通知中心 PHP

转载 作者:行者123 更新时间:2023-12-02 07:30:59 25 4
gpt4 key购买 nike

我正在尝试从 PHP 更新通知中心注册。这里展示了如何从 PHP 发送通知: http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-php-backend-how-to/

我尝试以这种方式调整代码以使用其他 API 方法: https://msdn.microsoft.com/en-us/library/azure/dn223262.aspx

public function updateRegistration($registrationId) {
# build uri
$uri = $this->endpoint . $this->hubPath . "/registrations/" . $registrationId . NotificationHub::API_VERSION;

$ch = curl_init($uri);

$contentType = "application/atom+xml;type=entry;charset=utf-8";

$token = $this->generateSasToken($uri);

$headers = [
'Authorization: '.$token,
'Content-Type: '.$contentType,
'x-ms-version: 2013-08',
'If-Match: update'
];

curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => '<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag, myOtherTag</Tags>
</WindowsRegistrationDescription>
</content>
</entry>'
));

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
throw new Exception(curl_error($ch));
}

$info = curl_getinfo($ch);

if ($info['http_code'] <> 201) {
throw new Exception('Error :'. $info['http_code'] . ' msg: ' . $response);
}

}

但我收到此错误:

“错误:405 消息:405指定的 HTTP 谓词 (POST) 无效。”

我做错了什么?

谢谢!

最佳答案

根据文档,它仅接受 PUT

所以,代码应该是:

curl_setopt_array($ch, array(
CURLOPT_CUSTOMREQUEST => 'PUT', // add this line
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => '<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<WindowsRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<Tags>myTag, myOtherTag</Tags>
</WindowsRegistrationDescription>
</content>
</entry>'
));

关于php - Azure 通知中心 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28855628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com