如何使用Bitpay与Java

前端之家收集整理的这篇文章主要介绍了如何使用Bitpay与Java前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现这个关于BitPay的帖子,但是不清楚我如何使用它.

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

我实现了这个代码

  1. public void createInvoice() throws BitPayException
  2. {
  3. ECKey key = KeyUtils.createEcKey();
  4. BitPay bitpay = new BitPay(key);
  5. InvoiceBuyer buyer = new InvoiceBuyer();
  6. buyer.setName("Satoshi");
  7. buyer.setEmail("satoshi@bitpay.com");
  8.  
  9. Invoice invoice = new Invoice(100.0,"USD");
  10. invoice.setBuyer(buyer);
  11. invoice.setFullNotifications(true);
  12. invoice.setNotificationEmail("satoshi@bitpay.com");
  13. invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
  14.  
  15. Invoice createInvoice = bitpay.createInvoice(invoice);
  16. }

如何实现私钥?

解决方法

我相信这个答案可以在以下文件中找到: https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/BitPay.java – 也就是说,您将在BitPay客户端实例上设置私钥.在那里,您可以根据需要找到适当的构造函数.您将根据具体需要使用以下一个或多个字段:
  1. private ECKey _ecKey = null;
  2. private String _identity = "";
  3. private String _clientName = "";
  4. private Hashtable<String,String> _tokenCache;

编辑:您的私钥的加密和解密存在于这里:https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/KeyUtils.java

例如,如果您使用以下构造函数

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

您将传入您的私钥的URI.

具体说明如下:https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md

两个很简单的例子:

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

第二:

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

实现私钥后,您将需要初始化客户端并连接到服务器.

猜你在找的Java相关文章