使用/update-cache请求更新AMP页面 [英] Using /update-cache requests to update AMP pages

查看:144
本文介绍了使用/update-cache请求更新AMP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用/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."&amp_url_signature=".$signature;

我正在使用的urlsafe_b64encode函数:

function urlsafe_b64encode($string) {
    return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}

$ ampUrl最终看起来像这样: https://www-qponverzum-hu.cdn.ampproject.org/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest Elozd-Meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ert-bio-biohajklinika-szepsegapolas-egeszseg/amp? amp_action =冲洗&安培; amp_ts = 1500362660&安培; amp_url_signature = NjTCnmqUGpMY_CokGxchoczSOxnTLQvcQsX4fv2gIhW3H8hVw24mKCpmNoyV-9LND3OAR9ld80KeMH3lip863p_wBorIy1BAag7bRfvWcxsPrbqbox87VMrUWCEsry5epWxKYl2qNCT1GMv8SYAJ5WR0QZR0Qjvw5MXfZjohmbvrxJ7mWlc7fcvWoIXuO_q_yFkhi7A-fOZWm9sy8UDIlq-zNEPkVUwfqfWc_HbNHgvrk9Z6zZSNzB-dWAOT6QYAc1KeEVOIbvQxKkLkGMArTpydj5iLxz0aERvglKRl215Bqh6_jZu95T5yKv7X4R127ylpWYW2YDlTR9bgRE7Faw

如果我通过浏览器或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

$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."&amp_url_signature=".$signature;

The urlsafe_b64encode function I'm using:

function urlsafe_b64encode($string) {
    return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}

$ampUrl ends up looking like this: https://www-qponverzum-hu.cdn.ampproject.org/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&amp_ts=1500362660&amp_url_signature=NjTCnmqUGpMY_CokGxchoczSOxnTLQvcQsX4fv2gIhW3H8hVw24mKCpmNoyV-9LND3OAR9ld80KeMH3lip863p_wBorIy1BAag7bRfvWcxsPrbqbox87VMrUWCEsry5epWxKYl2qNCT1GMv8SYAJ5WR0QZR0Qjvw5MXfZjohmbvrxJ7mWlc7fcvWoIXuO_q_yFkhi7A-fOZWm9sy8UDIlq-zNEPkVUwfqfWc_HbNHgvrk9Z6zZSNzB-dWAOT6QYAc1KeEVOIbvQxKkLkGMArTpydj5iLxz0aERvglKRl215Bqh6_jZu95T5yKv7X4R127ylpWYW2YDlTR9bgRE7Faw

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 $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);

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页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆