Javascript 谷歌地图api秘密关键问题
我想在我的谷歌地图api中添加api密钥和签名 在从google控制台生成api密钥和密钥之后,我们是否需要做加密之类的事情,或者我们可以在url中直接使用该密钥Javascript 谷歌地图api秘密关键问题,javascript,google-maps,Javascript,Google Maps,我想在我的谷歌地图api中添加api密钥和签名 在从google控制台生成api密钥和密钥之后,我们是否需要做加密之类的事情,或者我们可以在url中直接使用该密钥 $url .= "&key=abcdefghijklmnopqrstuvwxyz&signature=abcdefghijkliimnopqrstuvwxyz"; 如果我使用签名,那么它不会加载我的地图,解决方案是什么?是的,您可以直接在URL中使用api密钥,而无需任何修改。如果我使用签名,谷歌只需要使用带有Go
$url .= "&key=abcdefghijklmnopqrstuvwxyz&signature=abcdefghijkliimnopqrstuvwxyz";
如果我使用签名,那么它不会加载我的地图,解决方案是什么?是的,您可以直接在URL中使用api密钥,而无需任何修改。如果我使用签名,谷歌只需要使用带有Google maps JS的api密钥。如果我只使用api密钥,那么有时我的网站不会加载google静态地图,所以我想尝试使用Signature。我认为这根本不是问题,它的google政策允许你一些免费的请求,如果您超过这些限制,它将关闭地图加载您使用的任何产品,如自动建议、地图等
$url='http://maps.googleapis.com/maps/api/staticmap?&size=$dimensions&maptype=roadmap&sensor=false&key=abcdefghijklmnopqrstuvwxyz';
$url1=$url;
$url = parse_url($url1);
$urlPartToSign = $url['path'] . "?" . $url['query'];
// Decode the private key into its binary format
$decodedKey = decodeBase64UrlSafe('abcdefghijklmnopqrstuvwxy');
// Create a signature using the private key and the URL-encoded
// string using HMAC SHA1. This signature will be binary.
$signature = hash_hmac("sha1",$urlPartToSign, $decodedKey, true);
$encodedSignature = encodeBase64UrlSafe($signature);
$url=$url1."&signature=".$encodedSignature;
return saveImageUrlToDisk($imagePath, $url);
}
function encodeBase64UrlSafe($value)
{
return str_replace(array('+', '/'), array('-', '_'),
base64_encode($value));
}
// Decode a string from URL-safe base64
function decodeBase64UrlSafe($value)
{
return base64_decode(str_replace(array('-', '_'), array('+', '/'),
$value));
}