DCore应用案例(二):购买内容

购买内容

购买内容需要几个步骤。若想购买并访问内容,您需要内容ID以及合适的解密密钥(AES密钥)

让我们先找到要下载的内容

列出有效内容

通过使用以下方法,您能够获得所有当前有效的内容列表。列表是动态的,过期或隐藏项不在列表当中。

方法介绍:
search_content - 通过搜索内容项,获取按字母顺序排列的内容列表

vector<content_summary> search_content(string term,
                                       string order,
                                       string user,
                                       string region_code,
                                       string id,
                                       string type,
                                       uint32_t count);

参数:

  • term - 搜索内容项
  • order - 序域
  • user - 内容所有者
  • region_code - 两个字母的区域代码
  • id - 开启搜索的内容目标ID
  • type - 待筛选的应用以及内容类型
  • count - 可获取内容的最大数值(不可超过100)

返回值:

  • 选取的项(内容)

举例说明:

search_content "flower" "" accountname "AE" "" "" 3

回应:

search_content "flower" "" accountname "AE" "" "" 3
[{
    "id": "2.13.72",
    "author": "publisher-account",
    "price": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "synopsis": "{\"content_type_id\":\"0\",\"title\":\"Apllejuiceflower\",\"description\":\"test descriptin for the test flower \"}",
    "status": "Uploaded",
    "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
    "_hash": "822c778d5d33d24a0d661d3249d2b9a3efc8f66f",
    "AVG_rating": 0,
    "size": 5,
    "expiration": "2017-11-17T23:59:59",
    "created": "2017-11-14T09:22:15",
    "times_bought": 0
  }
]

搜索内容的API开发者文档

购买内容

上一步,我们获取了使用统一资源标识符(URI)的某一内容的资产信息。根据URI,购买内容功能会帮您获取确切的正在购买的内容的信息。

购买内容有以下两种方法。如果内容下载者选择 automatic download (自动下载),则无法修改作者设置的应付资产价格。如果购买内容时选择了 without automatic download (未自动下载),则可能设置其他支付资产。

内容自动下载

通过自动下载内容,您可以节省一些时间并且可以少调用一些命令行。但是,您无法通过未经上传者设置的资产为内容付费。

方法介绍:

download_content - 通过提供URI下载加密的指定内容

void download_content(string consumer,
                      string URI,
                      string region_code_from,
                      bool broadcast = false);

参数:

  • consumer - 内容消费者
  • URI - 内容的URI
  • region_code_from - 两个字母的区域代码
  • broadcast - true - 若要在网络上广播交易,则显示为true

举例说明:

download_content mickey "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU" "AE" true

结果:

null

请依照在购买部分列表中的说明操作。

下载内容的API开发者文档

手动下载内容

这一步包含两项操作。第一步是使用 request_to_buy 购买请求命令访问,第二步是下载 download_package

方法介绍:
request_to_buy - 此功能用于发送购买内容的请求。播种者会收到此项需求。

signed_transaction request_to_buy(string consumer,
                                  string URI,
                                  string price_asset_name,
                                  string price_amount,
                                  string str_region_code_from,
                                  bool broadcast);

参数:

  • consumer - 内容消费者
  • URI - 内容URI
  • price_asset_name - 用于购买内容的资产Ticker符号
    - price_amount - 内容价格
  • str_region_code_from - 两个字母的区域代码
  • broadcast - 若要在网络上广播交易,则显示为true

返回值:
• 请求购买内容的已签字交易

举例说明:

request_to_buy andrew "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU" DCT 2 "AE" true

回应:

{
  "ref_block_num": 54202,
  "ref_block_prefix": 2346282037,
  "expiration": "2017-11-15T11:20:20",
  "operations": [[
      21,{
      "fee": {
          "amount": 0,
          "asset_id": "1.3.0"
        },
         "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
        "consumer": "1.2.75",
        "price": {
          "amount": 200000000,
          "asset_id": "1.3.0"
        },
        "region_code_from": 4,
        "pubKey": {
          "s": "4303628372841098204725325886169480368712308731846406620978518465243755034949712651980700780736242269928176997284623659672330921098152069204211868999952586."
        }
      }
    ]
  ],
  "extensions": [],
  "signatures": [
  "202a710e6222b4b28efeef1d287be8483c8fd49de6b3a436a3b7eafcbb28c88b0125a022facb6b6881520ea6745488f37666697c5b4e69a23a55af4ed943b3e9bf"
  ]
  }

购买请求的API开发者文档

第二步

方法介绍:

  • download_package - 下载指定内容包
void download_package(string url);

参数:

  • url - 内容包链接

举例说明:

download_package "ipfs:QmYKkYWABMNiX8Mt1VHPSqm9pVz2gAN4KTfYz81idpfBzR"

结果:

download_package "ipfs:QmYKkYWABMNiX8Mt1VHPSqm9pVz2gAN4KTfYz81idpfBzR"
null

下载内容包的API开发者文档

列出内容购买记录

正确操作需知道购买者的账户ID或名称(第一参数)。

方法介绍:
search_my_purchases - 通过与搜索项相匹配的消费者获取历史购买目标项

vector<buying_object_ex> search_my_purchases(account_id_or_name,
                                             term,
                                             order,
                                             id,
                                             uint32_t count);

参数:

  • account_id_or_name - 返回的购买内容消费者
  • term - 在“Title”(标题)和“Description”(描述)中查找的搜索项
  • order - 通过字段将数据分类排序
  • id - 开启搜索的目标ID(Object_id)
  • count - 可获取内容的最大数值(不可超过100)

返回值:

  • 与所提供消费者相匹配的历史购买目标项以及相匹配的内容项( term)。

举例说明:

search_my_purchases mickey "" "" "" 2

回应:

[{
    "id": "2.12.67",
    "consumer": "1.2.73",
    "URI": "ipfs:QmRHS5siC3bTY6hDAdD5ELagZfpLkbYbudaeoV211YJ2FU",
    "synopsis": "{\"content_type_id\":\"0\",\"title\":\"Apllejuiceflower\",\"description\":\"test descriptin for the test flower \"}",
    "price": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
     "paid_price_before_exchange": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "paid_price_after_exchange": {
      "amount": 100000000,
      "asset_id": "1.3.0"
    },
    "seeders_answered": [
      "1.2.18",
      "1.2.17"
    ],
    "size": 5,
    "rating": 0,
    "comment": "",
    "expiration_time": "2017-11-15T12:27:30",
    "pubKey": {
      "s": "10384416749140257128583102389624607251654392586672946391438154410634414297114005655788618266551181783174334468876296512914387596163700640306113614522603976."
    },
    "key_particles": [{
        "C1": {
          "s": "7713541882884265737001144964407618286238469746991155829237368493864906459364159840366328822361837163546845186666114160890902773989019773380701434654220048."
        },
        "D1": {
          "s": "2692769396320662590732095382046790594075004387215914992857698150956473426023071796292163107553139158816276027313452036566715084008768822495671492946343936."
        }
      },{
        "C1": {
          "s": "6773119226898217031462006811313926243329502497094879661060451283455969563980673100681433599331398298113160613787560192551976238315248808417231992172920752."
        },
        "D1": {
          "s": "4654198223728504093980753883811654976741761019946052282686348856710255155548774806614798135855247295621547714324832986380763167537020809512198958238385012."
        }
      }
    ],
    "expired": false,
    "delivered": true,
    "expiration_or_delivery_time": "2017-11-14T12:27:40",
    "rated_or_commented": false,
    "created": "2017-11-14T09:22:15",
    "region_code_from": 4,
    "total_key_parts": 2,
    "received_key_parts": 2,
    "total_download_bytes": 0,
    "received_download_bytes": 0,
    "status_text": "Unknown",
    "author_account": "accountname",
    "AVG_rating": 0,
    "times_bought": 1,
    "hash": "822c778d5d33d24a0d661d3249d2b9a3efc8f66f"
}]

搜索购买过内容的API开发者文档

请求获取加密密钥

方法介绍:

  • restore_encryption_key - 从储存在购买目标项的密钥粒子(particles)系统复原AES密钥(用于加密和解密内容)
DInteger restore_encryption_key(std::string account,
                                buying_id_type buying);

参数:

  • account - 消费者账户ID或名称
  • buying - 包含密钥粒子(particles)购买目标项

返回值:

  • 从粒子(particles)中复原AES密钥。

举例说明:

restore_encryption_key mickey "2.12.67"

结果:

restore_encryption_key mickey "2.12.67"
"90119978168686416626538113977783330590824857160509159322627126482134770984565."

复原加密密钥的API开发者文档

获取加密内容

方法介绍:

extract_package - 提取所选择的内容包

void extract_package(string& package_hash,
                     string& output_dir,
                     DInteger& aes_key);

参数:

  • package_hash - 内容包中需要提取的哈希
  • output_dir - 创建提取文件的目录
  • aes_key - 用于解密的AES密钥

举例说明:

extract_package "822c778d5d33d24a0d661d3249d2b9a3efc8f66f" /path/to/download/the/ content/
"90119978168686416626538113977783330590824857160509159322627126482134770984565."

结果:

extract_package "822c778d5d33d24a0d661d3249d2b9a3efc8f66f" /path/to/download/the/ content/
"90119978168686416626538113977783330590824857160509159322627126482134770984565."
null

提取内容包的API开发者文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值