我正在尝试遵循谷歌网上商店 API 文档中给出的这个简单示例。不幸的是,他们最小的 PHP 示例包含很多我不需要的东西(并且没有设置)。
所以我正在考虑将基本内容硬编码到 HTML 文件中,只是为了与谷歌服务器进行通信:
我的代码如下所示:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
purchase = function() { console.log("Old purchase function"); }
generatedJwt = "..."; // I use a real JWT here....
google.load('payments', '1.0', {
'packages': ['sandbox_config'],
callback: function()
{
//Success handler
var successHandler = function(purchaseAction){
if (window.console != undefined) {
console.log("Purchase completed successfully.",purchaseAction);
}
}
//Failure handler
var failureHandler = function(purchaseActionError)
{
if (window.console != undefined)
{
console.log("Purchase did not complete.", purchaseActionError);
}
}
var purchase = function()
{
goog.payments.inapp.buy({
'jwt' : generatedJwt,
'success' : successHandler,
'failure' : failureHandler
});
}
}
});
</script>
<button class="buy-button" id="buybutton1" name="buy" type="button" onClick="purchase()">
Buy
</button>
</body>
当我点击购买按钮时,我会从谷歌弹出一条错误消息,并在控制台中出现以下错误:
Unsafe JavaScript attempt to access frame with URL
http://localhost/google_iap/buy_page.html
from frame with URL
https://sandbox.google.com/checkout/inapp/static/gwt/payments.html?viewportScreenCenterX=-857.5&viewportScreenCenterY=611#id=I1_1324454042050&parent=http%3A%2F%2Flocalhost&rpctoken=166967692&_methods=onPurchaseActionStatus%2CgetJwt%2C_ready%2C_close%2C_open%2C_resizeMe.
Domains, protocols and ports must match.
我需要做什么才能使这个简单的示例工作?
附录:
我从谷歌找到了一个更好的例子:
https://sandbox.google.com/checkout/customer/gadget/inapp/demo.html
但是,将源代码保存到我的机器并在本地访问它(如http://localhost/google_iap/google_demo.html)会产生相同的跨域错误。