问题描述
尝试使用/update-cache/请求更新一些AMP页面,但出现403错误.
因为我没有发布这么多链接的声誉,但是从网址中删除了开头部分/协议,但是所有内容都是https.
我在以下页面上有以下页面:www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert -biohajklinika-szepsegapolas-egeszseg/amp
从AMP缓存中:www-qponverzum-hu.cdn.ampproject.org/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosingsztika-hajhagyma-es- fejborvizsgalattal-tanacsadas-5000 ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp
我一直在遵循developers.google.com/amp/cache/update-ping
上的文档如果我发出/update-ping请求,它似乎工作正常,返回200无内容响应,但是由于大量的url/页面,我们希望使用/update-cache,因为它允许请求率更高.
我已经创建了一个私有和公共RSA密钥,并通过以下网址可以访问该公共密钥:www.qponverzum.hu/.well-known/amphtml/apikey.pub
我一直在尝试使用以下php代码生成更新缓存网址
$ampBaseUrl = "https://www-qponverzum-hu.cdn.ampproject.org";
$signatureUrl = '/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp?amp_action=flush&_ts='.time();
// opening the private key
$pkeyid = openssl_pkey_get_private("file://private-key.pem");
// generating the signature
openssl_sign($signatureUrl, $signature, $pkeyid)
// urlsafe base64 encoding
$signature = urlsafe_b64encode($signature);
// final url for updating
$ampUrl = $ampBaseUrl.$signatureUrl."&_url_signature=".$signature;
我正在使用的urlsafe_b64encode函数:
function urlsafe_b64encode($string) {
return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}
如果我通过浏览器或curl对该URL进行简单的GET请求,则会收到403错误(您的客户端无权获取URL").
我已经检查了网络服务器日志,但似乎没有对公共密钥URL进行任何请求.
我认为我缺少一些非常明显的东西,因此,我们将不胜感激.
$signatureUrl
中存在错误-查询参数中应该为 amp_ts 而不是 _ts 并在openssl_sign
中添加第四个参数openssl_sign($signatureUrl, $signature, $pkeyid, OPENSSL_ALGO_SHA256);
签名需要使用 SHA256 进行签名,如果省略最后一个使用 SHA1
的参数,在我的工作项目中,我已经将您的脚本与这两个更改一起使用,并且工作正常.
如果可以的话,它应该在响应正文中返回"OK".
选中此 https://gist.github.com/krzysztofbukowski/739ccf4061d69360b5b2c8306 > Trying to use /update-cache/ requests to update some AMP pages, but i'm getting 403 errors. Removed the opening part/protocol from the urls since i don't have the reputation to post this many links, but everything is https. I have a page at: www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp From the AMP cache: www-qponverzum-hu.cdn.ampproject.org/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp I've been following the documentation at developers.google.com/amp/cache/update-ping If i make an /update-ping request, it seems to work fine, returns a 200 no content response, but due to the high amount of urls/pages we would like to use /update-cache since it allows for a higher request rate. I've created a private and public RSA key and made the public key acessible at www.qponverzum.hu/.well-known/amphtml/apikey.pub I've been trying to use the following php code to generate the update-cache url The urlsafe_b64encode function I'm using: If I make a simple GET request to this url(with a browser or curl) i get a 403 error('Your client does not have permission to get URL'). I've checked the webserver logs, but it doesn't seem like there're any requests made to the public keys url. I think I'm missing something very obvious, so any feedback would be greatly appreciated. There's an error in The signature needs to be signed with SHA256, if you omit the last parameter it uses SHA1 I've used your script with these 2 changes for my work project and it's working fine. It should return "OK" in the response body if it's fine. Check this https://gist.github.com/krzysztofbukowski/739ccf4061d69360b5b2c8306f5878bd 这篇关于使用/update-cache请求更新AMP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!$ampBaseUrl = "https://www-qponverzum-hu.cdn.ampproject.org";
$signatureUrl = '/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp?amp_action=flush&_ts='.time();
// opening the private key
$pkeyid = openssl_pkey_get_private("file://private-key.pem");
// generating the signature
openssl_sign($signatureUrl, $signature, $pkeyid)
// urlsafe base64 encoding
$signature = urlsafe_b64encode($signature);
// final url for updating
$ampUrl = $ampBaseUrl.$signatureUrl."&_url_signature=".$signature;
function urlsafe_b64encode($string) {
return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}
$signatureUrl
- it should be amp_ts instead of _ts in the query params and in openssl_sign
add the fourth parameter openssl_sign($signatureUrl, $signature, $pkeyid, OPENSSL_ALGO_SHA256);