Hi,
About Windows IAP receipt verify, I found this document:
https://msdn.microsoft.com/en-us/windows/uwp/monetize/use-receipts-to-verify-product-purchases
But this document code is .NET(C#), my server is written by Java, I test a lot way to verify this, but failed, I paste my Java logic code and hope someone can help me solve it.
public static boolean verifyReceipt(String _receiptXml){
try{
DocumentBuilderFactory t_factory = DocumentBuilderFactory.newInstance();
t_factory.setNamespaceAware(true);
DocumentBuilder builder = t_factory.newDocumentBuilder();
Document t_doc = builder.parse(new InputSource(new StringReader(_receiptXml)));
PublicKey t_pubKey = getPublicKey(t_doc.getDocumentElement().getAttribute("CertificateId"));
// TODO improve following method to verfy
// we cannot use this function to verify
NodeList nl = t_doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
DOMValidateContext valContext = new DOMValidateContext(t_pubKey,nl.item(0));
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
XMLSignature signature = fac.unmarshalXMLSignature(valContext);
return signature.validate(valContext);
}catch (Exception e){
log.error("verify error \n {} \n {}",_receiptXml,e);
return false;
}
}
private static PublicKey getPublicKey(String _certificateId)throws Exception{
PostParameter[] t_params =
{
new PostParameter("LinkId", "246509"),
new PostParameter("cid",URLEncoder.encode(_certificateId, "UTF-8")),
};
String t_result = PostAnswer.requestURL("https://go.microsoft.com/fwlink/", "GET", null, t_params,true);
log.info(t_result);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
return certificateFactory.generateCertificate(new ByteArrayInputStream(t_result.getBytes("UTF-8"))).getPublicKey();
}