使用PHP验证Windows 8购买(收据)

编程入门 行业动态 更新时间:2024-10-10 04:23:08
本文介绍了使用PHP验证Windows 8购买(收据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用PHP验证在Windows 8应用程序服务器端进行的应用内购买。 MSDN的文档页面仅在C#中有一个示例。现在我花了一整天的时间来寻找一种在PHP中实现它的方法。没有成功。在整个互联网上只有关于这个主题的.NET示例。

I need to verify in-app purchases made in Windows 8 applications server-side using PHP. MSDN's documentation page has an example only in C#. Right now I've spent a whole day by searching for a way to do it in PHP. No success. All over the internet there are only .NET examples on this topic.

我发现了一些关于签名XML和x509的部分信息,一些库(xmlseclibs - 无用,用途openssl_ *函数不支持sha256; phpseclib - 看起来很有前途,但是他们的文档和示例很差,没有任何帮助。)

I've found some partial information about signed XML and x509, some libraries (xmlseclibs - useless, uses openssl_* functions which do not support sha256; phpseclib - looks promising but their documentation and examples are poor with no help).

是否有可能以某种方式做到而无需学习所有内容关于签名的XML,RSA和x509?现在我几乎阅读了所有内容,但到处都是关于编码的信息。没有关于验证。

Is it possible to do it somehow without learning everything about signed XML, RSA and x509? Right now I've read almost everything but everywhere is info only about encoding. Nothing about verifying.

推荐答案

我设法使用 xmlseclibs 库。

此外,还需要启用php curl。

Also, you need php curl enabled.

do { $doc = new DOMDocument(); $xml = $_POST['receipt_data']; // your receipt xml here! // strip unwanted chars - IMPORTANT!!! $xml = str_replace(array("\n","\t", "\r"), "", $xml); //some (probably mostly WP8) receipts have unnecessary spaces instead of tabs $xml = preg_replace('/\s+/', " ", $xml); $xml = str_replace("> <", "><", $xml); $doc->loadXML($xml); $receipt = $doc->getElementsByTagName('Receipt')->item(0); $certificateId = $receipt->getAttribute('CertificateId'); $ch = curl_init("lic.apps.microsoft/licensing/certificateserver/?cid=$certificateId"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $publicKey = curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch); if ($errno != 0) { $verifyFailed = true; break; } // Verify xml signature require('./xmlseclibs.php'); $objXMLSecDSig = new XMLSecurityDSig(); $objDSig = $objXMLSecDSig->locateSignature($doc); if (!$objDSig) { $verifyFailed = true; break; } try { $objXMLSecDSig->canonicalizeSignedInfo(); $retVal = $objXMLSecDSig->validateReference(); if (!$retVal) { throw new Exception("Error Processing Request", 1); } $objKey = $objXMLSecDSig->locateKey(); if (!$objKey) { throw new Exception("Error Processing Request", 1); } $key = NULL; $objKeyInfo = XMLSecEnc::staticLocateKeyInfo($objKey, $objDSig); if (! $objKeyInfo->key && empty($key)) { $objKey->loadKey($publicKey); } if (!$objXMLSecDSig->verify($objKey)) { throw new Exception("Error Processing Request", 1); } } catch (Exception $e) { $verifyFailed = true; break; } $productReceipt = $doc->getElementsByTagName('ProductReceipt')->item(0); $prodictId = $productReceipt->getAttribute('ProductId'); $purchaseDate = $productReceipt->getAttribute('PurchaseDate'); } while(0); if ($verifyFailed) { // invalid receipt } else { // valid receipt }

更多推荐

使用PHP验证Windows 8购买(收据)

本文发布于:2023-11-26 09:07:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收据   PHP   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!