【问题标题】:How to use Bitpay with Java如何在 Java 中使用 Bitpay
【发布时间】:2017-01-15 05:33:51
【问题描述】:

我发现了这篇关于 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);
    }

我应该如何实现私钥?

【问题讨论】:

  • 看看这个link
  • 是的,我已经测试过了,但我无法编写工作代码。请给我看看工作示例好吗?
  • 能否提供堆栈跟踪

标签: java payment-gateway


【解决方案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);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 2013-02-20
    • 2014-12-09
    • 2023-04-11
    • 2016-03-28
    • 2014-07-04
    相关资源
    最近更新 更多