none
关于Windows IAP的验证

    问题

  • 你好,

    关于Windows IAP (内购) 的订单XML验证我找到如下文档:

    https://msdn.microsoft.com/en-us/windows/uwp/monetize/use-receipts-to-verify-product-purchases

    但是这个文档是关于.Net C#的,我使用Java语言无法进行验证,我在后面贴出我的Java代码,希望那位大神能够指点迷津。

    JAVA CODE:

    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();
    	}

    2016年3月9日 2:53

全部回复

  • 您好,

    这里是微软官方论坛,不支持跟java有关的问题,请您去java的官方论坛提问。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年3月10日 5:49
    版主
  • 谢谢你的回答。

    我终于知道为啥我选择插入代码块的时候,没有java了。

    2016年3月10日 5:51