我已经在我的测试站点 http://whatisthesite.com 上实现了在 https://code.google.com/p/iap-php/找到的示例代码。正如您可能能够看到的那样,单击"购买"按钮后会出现一条模糊的错误消息:
There is an error in the setup for your purchase. Please contact the merchant with this error message: Expected 3 components in jwt: $jwtToken
控制台提供:
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://whatisthesite.com" from accessing a frame with origin "https://sandbox.google.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.
markdown-here.js:33
findFocusedElem markdown-here.js:33
intervalCheck
演示站点 http://iap-php.appspot.com/不是https:代码中也没有定义协议的任何地方。任何建议将不胜感激,谢谢!
更新:
这与示例使用"Here Doc"语法在 JS 函数中使用内联 PHP 变量有关。更改了此语法:
echo <<< INDEX <button id='runDemoButton' value='buy' class='buy-button' onclick='DemoButton("$jwtToken");'><b>Purchase</b></button> INDEX;
对此:
<button id='runDemoButton' value='buy' class='buy-button' onclick='DemoButton("<?php echo $jwtToken;?>");'><b>Purchase</b></button>
但现在给出了一个更模糊的错误。
对话框错误(如"购买设置中存在错误")会将相应的错误代码返回到客户端故障处理程序:
https://developers.google.com/wallet/digital/docs/jsreference#failurehandler
在您的情况下,错误代码MERCHANT_ERROR表示 JWT 格式不正确。这可能是由于使用了不正确的卖家密钥或秘密来签署 JWT。