2016-09-07 19 views
11

我發現這篇文章關於BitPay,但它不是很清楚我可以如何使用它。如何使用Bitpay與Java

https://help.bitpay.com/development/how-do-i-use-the-bitpay-java-client-library

我實現了這個代碼:

public void createInvoice() throws BitPayException 
    { 
     ECKey key = KeyUtils.createEcKey(); 
     BitPay bitpay = new BitPay(key); 
     InvoiceBuyer buyer = new InvoiceBuyer(); 
     buyer.setName("Satoshi"); 
     buyer.setEmail("[email protected]"); 

     Invoice invoice = new Invoice(100.0, "USD"); 
     invoice.setBuyer(buyer); 
     invoice.setFullNotifications(true); 
     invoice.setNotificationEmail("[email protected]"); 
     invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); 

     Invoice createInvoice = bitpay.createInvoice(invoice); 
    } 

我應該如何實現私鑰?

+0

看看這個[鏈接](https://support.bitpay.com/hc/en-us/articles/204546905-Creating-Private-Keys-and-Public-Keys) –

+0

是的,我已經測試過,但我無法制作工作代碼。你能告訴我工作的例子嗎? –

+0

你能提供堆棧跟蹤嗎? – Rishi

回答

-1

我相信這個答案可以在以下文件中找到:https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/BitPay.java - 也就是說,您將在BitPay客戶端實例上設置您的私鑰。在那裏你可以找到適合你需求的構造函數。您將要使用以下字段的一個或多個具體取決於您的特定需求:

private ECKey _ecKey = null; 
private String _identity = ""; 
private String _clientName = ""; 
private Hashtable<String, String> _tokenCache; 

編輯:加密和私鑰解密的存在這裏:https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/KeyUtils.java

如果,例如,你所使用的以下構造函數:

public BitPay(URI privateKey) throws BitPayException, URISyntaxException,  IOException { 
    this(KeyUtils.loadEcKey(privateKey), BITPAY_PLUGIN_INFO, BITPAY_URL); 
} 

您會傳遞URI的私鑰。

這個可以在這裏特別說明:https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md

兩個非常簡單的例子:

BitPay bitpay = new BitPay(); 
ECKey key = KeyUtils.createEcKey(); 
this.bitpay = new BitPay(key); 

號之二:

// Create the private key external to the SDK, store it in a file, and inject the private key into the SDK. 
String privateKey = KeyUtils.getKeyStringFromFile(privateKeyFile); 
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey); 
this.bitpay = new BitPay(key); 

實施私有密鑰後,您會直到需要初始化客戶端並連接到服務器。