如何使用Bitpay与Java

我发现这个关于bitpay的帖子,但是不清楚我如何使用它.

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("satoshi@bitpay.com");

        Invoice invoice = new Invoice(100.0,"USD");
        invoice.setBuyer(buyer);
        invoice.setFullNotifications(true);
        invoice.setNotificationEmail("satoshi@bitpay.com");
        invoice.setPosData("ABCDEFGHIJKLMnopQRSTUVWXYZ1234567890");

        Invoice createInvoice = bitpay.createInvoice(invoice);
    }

如何实现私钥?

解决方法

我相信这个答案可以在以下文件中找到: 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);

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

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...