Files
Artveris/docs/天河链文档.md
T
Nixevol e644e38ff3 feat: 天河链升级为存证+发行(NFT)双层,新增轮换 UserKey 与 C 端 tokenId 展示
- 上链流程:upload 存证 → publish 铸 NFT → 接口9确认 mint → ONCHAIN,记录 tokenId/合约地址
- blockchain_proof 加 token_id/contract_address 字段(迁移),schema 补 VarChar 注解消除 drift
- TianheProvider 新增 publish/updateUserKey;合约地址与 maxTokenId 存系统设置维护 baseTokenId
- 轮换 UserKey:接口7 + 设置页「轮换密钥」(二次确认+回显强提示+操作日志)
- C 端区块链卡展示数字藏品编号(tokenId)与合约地址
- 测试环境全链路实测通过;媒体上链层级待甲方确认,暂维持 JSON 存证
- docs/天河链文档.md 标注以 APIFox 为准并列勘误
2026-07-10 11:35:44 +08:00

346 lines
27 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> ⚠️ 本文件为语雀文档的历史快照,部分内容已过时/有误(如接口 5 路径应为 `/api/v2/nfr/transaction/detail`、接口 9 `status` "0x0"=成功等)。
> **对接以 APIFox 在线文档为准**:https://s.apifox.cn/470f2b03-5edb-49d4-8e54-e2684feab256
> 我方对接决策与勘误详见 `aidocs/天河链对接分析与建议.md`。
### <img src="https://cdn.nlark.com/yuque/0/2022/png/100786/1649734825883-1e3cf974-8023-4120-b2d6-a8cd7f0c6889.png" width="1144.5" title="" crop="0,0,1,1" id="u4a1b200e" class="ne-image">
测试环境接口域名:https://test.api.tichain.tianhecloud.com
生产环境接口域名:https://api.tichain.tianhecloud.com<font style="color:#E8323C;">(生产环境,务必使用该域名)</font>
测试环境浏览器:[https://test.explorer.tianhecloud.com](https://test.explorer.tianhecloud.com/#/tiChain/index)
生产环境浏览器:[https://explorer.tianhecloud.com](https://explorer.tianhecloud.com/#/tiChain/index)
**<font style="color:#E8323C;">在对接前,请务必先查看以下文档,更好的理解业务,高效对接:</font>**
数字商品介绍文档**<font style="color:#E8323C;">(必看)</font>**:[链接](https://thgy.yuque.com/docs/share/637835e5-7cbb-44bf-8a96-c842b1a600f3)
天河链数字商品对接FAQ:[链接](https://thgy.yuque.com/docs/share/c922881d-ef55-4ef0-b8fe-404cd25c757c)
🎉<font style="background-color:#B7EB8F;">可在线调试接口文档:</font>[<font style="background-color:#B7EB8F;">https://www.apifox.cn/apidoc/shared-470f2b03-5edb-49d4-8e54-e2684feab256</font>](https://www.apifox.cn/apidoc/shared-470f2b03-5edb-49d4-8e54-e2684feab256)
### 1 用户链上身份注册
| **接口调用** | | | |
| --- | --- | --- | --- |
| **说明:该接口在天河链平台注册一个托管用户钱包,打开钱包的密码由userKey决定。** | | | |
| **标题** | **描述** | | |
| 接口 | https://api.tichain.tianhecloud.com/api/v2/user | | |
| method | post | | |
| content-type | application-json | | |
| **接口入参(Body JSON传输)** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID,和业务系统关联的ID | 字符串 | 是 |
| userKey | 用户秘钥,最好是用户支付密码关联的秘钥,用于执行交易,例如用户支付密码为6位数字,客户平台加特定字符再计算hash作为用户秘钥,执行交易时提交该秘钥作为托管钱包的秘钥(天河链平台不留存用户密码) | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/>"pubKey":{<br/>"address": "公钥地址" //(用户链上身份)<br/>"publicKey": "公钥" //(请忽略这个字段,只需要address)<br/>} <br/>} | | |
| **<font style="color:#000000;">curl 样例</font>** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/user'](https://dev.tichain.tianhecloud.com/api/v2/user') \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000000001",<br/> "appKey": "xyusdjysdsdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456"<br/>}<br/>' | | | |
### 2 数字商品发行
| **接口调用** | | | |
| --- | --- | --- | --- |
| **说明:该接口在天河链发行数字商品(NFR),并自动派发给指定的用户地址(userID对应的钱包)上面,该接口会执行合约部署、并初始化指定数量的数字商品,并转移到该用户地址上(铸造)。**<br/>**该接口执行时长和铸造数量正相关,一次调用不能连续发行10000个,建议在5000左右,如果需要发行超过10000个,后面需要传递合约地址(contractAddress)参数(第一次调用会返回合约地址)。**<br/>⚠️发行接口会将交易提交到区块链上,当网络中交易量过大,链存在无法及时返回交易回执(数据的tokenId)的现象,所以需要通过返回的交易哈希(transactionHash)进一步查询和判断。 | | | |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/publish | | |
| method | post | | |
| content-type | application-json | | |
| **接口入参(Body JSON传输)** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID,一般为平台自己的用户ID,用来接收商品 | 字符串 | 是 |
| userKey | 用户秘钥,参加链上身份注册流程的秘钥 | 字符串 | 是 |
| name | 专题名称,字符长度不超过 <u>42</u> | 字符串 | 是 |
| pieceCount | NFR份数[1-10000] | 整型 | 是 |
| feature | 作品对应的媒体文件地址,例如图片链接,字符长度不超过 <u>500</u> | 字符串 | 是 |
| productIds | 商家数字商品ID数组,可以是有意义的产品编号,每一个NFT一个 | 字符串数组 | 否 |
| author | 作者,字符长度不超过 <u>120</u> | 字符串 | 否 |
| baseTokenId | 自定义 tokenId 起始值,创建合约有效 (若请求参数指定了 contractAddress ,则 baseTokenId 需设置为**已发行** tokenId 的最大值。) | 整型 | 否 |
| initPrice | 发行价格,字符长度不超过 <u>20</u> | 字符型 | 否 |
| contractAddress | 合约地址参数(0xabc...),用于在某合约上分批铸造,字符长度为 <u>42</u> | 字符型 | 否 |
| <font style="color:#000000;">multiAddress</font> | 发行目标地址,铸造后,直接转移到该地址,和需要发行的数量匹配或者唯一一个,该参数为空时,所有Token发给调用用户,有且只有一个发给唯一用户地址,正常一一匹配 | 字符串数组 | 否 |
| operateId | 请求ID,每个请求需要填唯一的id,重复请求用相同的id | 字符串 | 否 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息,wait for mint消息的错误代码为0,表示提交到链是成功的,只是链的响应时间未在指定时间返回,可通过transactionHash通过查询接口进行查询。 | | |
| data | {<br/>"contractAddress":"合约地址",<br/>"products": [<br/>{<br/>"transactionHash" : "交易哈希",<br/>"productId": "商家数字商品ID",<br/>"tokenId": "token编号(-1表示当时没有查询到,正常情况为实际TokenId,如果失败,通过上述交易哈希查询结果)",<br/>"address":"0xabcd123...(发行目标用户地址)"<br/>}<br/>......<br/>]<br/>} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/nfr/publish'](https://dev.tichain.tianhecloud.com/api/v2/nfr/publish') \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> <br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456",<br/> "productIds": ["000001","000002","000003","000004","000005","000006","000007","000008","000009","000010"],<br/> "name": "Luna",<br/> "pieceCount": 10,<br/> "author": "XiaoTian",<br/> "feature": "Future is coming!"<br/>}<br/>' | | | |
| ⚠️关于wait for mint消息是表明当前相同参数的请求还在执行,需要通过上一步的消息返回值进一步判断。天河链API接口为保证调用发布接口因网络异常终端,导致客户端未接收到消息,设计了参数缓存机制,在采用相同参数调用时,如果上一次执行没有成功放回,则返回wait for mint消息。 | | | |
### 3 数字商品交易
| **接口调用** | | | |
| --- | --- | --- | --- |
| **说明:基于数字商品进行数字资产交易,必须是持有该数字商品 TokenId的用户ID,并指定Key才能执行成功,同时请确保userId对应的区块链地址和from是同一个地址。**<br/>**<font style="color:rgb(23, 26, 29);">避免重复请求,10分钟内保证对于同一操作发起的一次请求或者多次请求的结果是一致的</font>** | | | |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/transfer | | |
| method | post | | |
| content-type | application-json | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家密钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| contractAddress | 合约地址,字符长度为 <u>42</u> | 字符串 | 是 |
| tokenId | token编号,非负整数 | 整型 | 是 |
| from | 发起方公钥地址,字符长度为 <u>42</u> | 字符串 | 是 |
| to | 接收方公钥地址,字符长度为 <u>42</u> | 字符串 | 是 |
| operateId | 请求ID,每个请求需要填唯一的id,重复请求用相同的id | 字符串 | 否 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {"transactionHash":"交易哈希"} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/nfr/transfer'](https://api.tichain.tianhecloud.com/api/v2/nfr/transfer') \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456",<br/> "contractAddress": "0x4010edbb5824f975e435795ac2b202873f2ecad7",<br/> "tokenId": 3,<br/> "from": "0x85aa7cdeba55cb08427018d066a26719b956ceff",<br/> "to": "0x08ae7bbe61dc7db7795f90ee9899f44105622961"<br/>}' | | | |
### 4 销毁数字商品
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/burn | | |
| method | post | | |
| content-type | application-json | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| contractAddress | 合约地址,字符长度为 <u>42</u> | 字符串 | 是 |
| tokenId | token编号,非负整数 | 整型 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {"transactionHash":"交易哈希"} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/nfr/burn'](https://api.tichain.tianhecloud.com/api/v2/nfr/burn') \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456",<br/> "contractAddress": "0xe4d8dee08edf730ba9835c607593f2aa6ac3eca7",<br/> "tokenId": 3<br/>}' | | | |
### 5 交易结果查询
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/transaction/detail | | |
| method | post | | |
| content-type | application-json | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| transactionHash | 交易哈希,字符长度为 <u>66</u> | 字符串 | 是 |
| methodName | 查询的方法名(查询数字商品交易的情况,输入"transferFrom";查询销毁数字商品的情况,输入:"burn";查询数字商品发行输入"mint"。) | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | { "isSuccess":"交易是否成功(true or false)",<br/>"output":"交易输出信息",<br/>"tokenId":"NFT编号,仅在mint时有效"<br/>} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/transaction/detail](https://dev.tichain.tianhecloud.com/api/v2/transaction/detail)' \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456",<br/> "transactionHash": "0x945623e7dfa05ab52dc8273d4870e50dffbc0d11e154f582436e659ad696ba69",<br/> "methodName": "burn"<br/>}' | | | |
### 6 数字商品元数据上链存储(将数字商品对应的媒体文件保存到区块链)
| **接口调用**<br/>**对数字商品进行存证,可以获得链上存证哈希,数字商品唯一哈希和存证链接(将该存证链接放在数字商品发行API中的feature字段,将在浏览器的藏品详情页进行展示)** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/upload | | |
| method | post | | |
| content-type | form-data | | |
| **接口入参(****⚠️****Body JSON传输,Multi-Part方式接收数据)** | | | |
| **键** | **值** | **类型** | **是否必须** |
| userDto | {<br/>"appId":"商家编号",<br/>"appKey":"商家秘钥",<br/>"userId":"用户ID",<br/>"userKey":"用户秘钥"<br/>} | JSON对象<br/>字符串 | 是 |
| file | 图片、音乐、视频、文档等文件,最大为100M | 文件 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/> "digest": 文件哈希, // 数字商品唯一哈希<br/> "url": 文件下载地址, // 数字商品链上URI<br/>"transactionHash": 交易哈希 //链上存证Hash<br/>} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/nfr/upload'](https://dev.tichain.tianhecloud.com) \<br/>--form 'file=@"/C:/Users/TiChain/upload/tichain.png"' \<br/>--form 'userDto="{<br/> \"appId\": \"tichain0000000360001\",<br/> \"appKey\": \"xyusdjysdsafdsasds3UyZ\",<br/> \"userId\": \"T\",<br/> \"userKey\": \"123456\"<br/>}";type=application/json' | | | |
| **PHP示例代码** | | | |
| [upload_demo.php](https://thgy.yuque.com/attachments/yuque/0/2022/php/518409/1652255858229-98aec9d6-85cd-496d-a7c1-eae3275bc434.php) | | | |
### 7 用户链上身份秘钥修改
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/user/update | | |
| method | post | | |
| content-type | form-data | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| newUserKey | 用户新密钥 | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | 无 | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/user/update'](https://api.tichain.tianhecloud.com) \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456",<br/> "newUserKey": "654321"<br/>}<br/>' | | | |
### 8 用户链上身份查询
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/user/info | | |
| method | post | | |
| content-type | form-data | | |
| **接口入参(Body)** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/>"address": "公钥地址"<br/>"publicKey": "公钥" //(请忽略这个字段,只需要address)<br/><br/>} | | |
| **curl 样例** | | | |
| curl --location --request POST '[https://dev.tichain.tianhecloud.com/api/v2/user/info'](https://api.tichain.tianhecloud.com) \<br/>--header 'Content-Type: application/json' \<br/>--data-raw '{<br/> "appId": "tichain0000000360001",<br/> "appKey": "xyusdjysdsafdsasds3UyZ",<br/> "userId": "T",<br/> "userKey": "123456"<br/>}<br/>' | | | |
### 9 根据交易哈希查询 TokenID
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | [https://api.tichain.tianhecloud.com/api/v2/nfr/transaction/status](https://api.tichain.tianhecloud.com/api/v2/nfr/transaction/status) | | |
| method | get | | |
| content-type | application/json | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| transactionHash | 交易哈希,字符长度 <u>66</u> | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/>"status": "0x0", <br/>"blockHash":区块哈希, <br/>"blockNum": 区块高度, <br/>"transactionHash": 交易哈希, <br/>"tokenId": TokenID(若为非 token 直接相关交易,则返回-999)<br/><br/>} | | |
| **curl 样例** | | | |
| <font style="color:#000000;background-color:#fffffe;">curl --location --request GET </font><font style="color:#2a00ff;background-color:#fffffe;">'https://test.api.tichain.tianhecloud.com/api/v2/nfr/transaction/status'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="color:#000000;background-color:#fffffe;">--header </font><font style="color:#2a00ff;background-color:#fffffe;">'Content-Type: application/json'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="color:#000000;background-color:#fffffe;">--data-raw </font><font style="color:#2a00ff;background-color:#fffffe;">'{</font><br/><font style="color:#000000;background-color:#fffffe;"> </font><font style="color:#2a00ff;background-color:#fffffe;">"appId"</font><font style="color:#000000;background-color:#fffffe;">: </font><font style="color:#2a00ff;background-color:#fffffe;">"</font>tichain0000000360001<font style="color:#2a00ff;background-color:#fffffe;">"</font><font style="color:#000000;background-color:#fffffe;">,</font><br/><font style="color:#000000;background-color:#fffffe;"> </font><font style="color:#2a00ff;background-color:#fffffe;">"appKey"</font><font style="color:#000000;background-color:#fffffe;">: </font><font style="color:#2a00ff;background-color:#fffffe;">"</font>xyusdjysdsafdsasds3UyZ<font style="color:#2a00ff;background-color:#fffffe;">"</font><font style="color:#000000;background-color:#fffffe;">,</font><br/><font style="color:#000000;background-color:#fffffe;"> </font><font style="color:#2a00ff;background-color:#fffffe;">"transactionHash"</font><font style="color:#000000;background-color:#fffffe;">: </font><font style="color:#2a00ff;background-color:#fffffe;">"0xeb76543763f94a83c64eab02a9db1dea29383d6768ddc8539149fda382f952a4"</font><br/><font style="color:#000000;background-color:#fffffe;">}</font><font style="color:#2a00ff;background-color:#fffffe;">'</font> | | | |
### 10 NFR 所属者地址查询
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/token/query | | |
| method | post | | |
| content-type | form-data | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| contractAddress | 合约地址,字符长度为<u>42</u> | 字符串 | 是 |
| tokenId | token 编号,非负整数 | 整数 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/><font style="background-color:#fffffe;"> "address": 所属用户地址</font><br/>} | | |
| **curl 样例** | | | |
| <font style="color:#000000;background-color:#fffffe;">curl --location --request POST </font><font style="color:#2a00ff;background-color:#fffffe;">'https://test.api.tichain.tianhecloud.com//api/v2/nfr/token/query'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="color:#000000;background-color:#fffffe;">--header </font><font style="color:#2a00ff;background-color:#fffffe;">'Content-Type: application/json'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="color:#000000;background-color:#fffffe;">--</font><font style="background-color:#fffffe;">data-raw '{</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"appId"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"</font>tichain0000000360001<font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"appKey"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"</font>xyusdjysdsafdsasds3UyZ<font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> "contractAddress": "0xab7aab90aa38a6da3f4359c45595c64740c6695f",</font><br/><font style="background-color:#fffffe;"> "tokenId": 1</font><br/><font style="background-color:#fffffe;">}'</font> | | | |
### 11 NFR 所属者判断
| **接口调用** | | | |
| --- | --- | --- | --- |
| **标题** | **描述** | | |
| 接口名 | https://api.tichain.tianhecloud.com/api/v2/nfr/token/approve | | |
| method | post | | |
| content-type | form-data | | |
| **接口入参** | | | |
| **键** | **值** | **类型** | **是否必须** |
| appId | 商家编号 | 字符串 | 是 |
| appKey | 商家秘钥 | 字符串 | 是 |
| userId | 用户ID | 字符串 | 是 |
| userKey | 用户秘钥 | 字符串 | 是 |
| contractAddress | 合约地址,字符长度为<u>42</u> | 字符串 | 是 |
| tokenId | token 编号,非负整数 | 字符串 | 是 |
| **返回** | | | |
| **标题** | **描述** | | |
| code | 错误码,0成功 | | |
| message | 错误信息 | | |
| data | {<br/>"result": true<font style="color:#8C8C8C;">(false)</font><br/>} | | |
| **curl 样例** | | | |
| <font style="color:#000000;background-color:#fffffe;">curl --location --request POST </font><font style="color:#2a00ff;background-color:#fffffe;">'https://test.api.tichain.tianhecloud.com//api/v2/nfr/token/approve'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="color:#000000;background-color:#fffffe;">--header </font><font style="color:#2a00ff;background-color:#fffffe;">'Content-Type: application/json'</font><font style="color:#000000;background-color:#fffffe;"> \</font><br/><font style="background-color:#fffffe;">--data-raw '{</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"appId"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"</font>tichain0000000360001<font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"appKey"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"</font>xyusdjysdsafdsasds3UyZ<font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"userId"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"TiChain-001"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"userKey"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"123456"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"contractAddress"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">0xab7aab90aa38a6da3f4359c45595c64740c6695f</font><font style="background-color:#fffffe;">"</font><font style="background-color:#fffffe;">,</font><br/><font style="background-color:#fffffe;"> </font><font style="background-color:#fffffe;">"tokenId"</font><font style="background-color:#fffffe;">: </font><font style="background-color:#fffffe;">1</font><br/><font style="background-color:#fffffe;">}'</font> | | | |
## 📢Q&A
### 1. 正确导入 curl 到 postman
PostMan导入文件(需配置软件的环境变量):[TiChain.postman_collection.json](https://thgy.yuque.com/attachments/yuque/0/2022/json/100786/1659945439458-328f2c45-f54e-4309-a072-9ced6b283f85.json)
<img src="https://cdn.nlark.com/yuque/0/2022/png/518409/1652061120710-3c70afb7-c4b9-4085-8696-18dba1d84b59.png" width="1887" title="" crop="0,0,1,1" id="ufa38546a" class="ne-image">
<img src="https://cdn.nlark.com/yuque/0/2022/png/518409/1652061202717-bb6b77ee-6605-4aa7-bf21-b86b885b5348.png" width="1903" title="" crop="0,0,1,1" id="u22cf8e3e" class="ne-image">
### 2. upload 接口上传失败,报错 “Media Type Error”,如何解决?
核查红框内容,是否符合文档要求。
<img src="https://cdn.nlark.com/yuque/0/2022/png/518409/1652095002133-a57e2f98-379b-4130-9888-7de74ad197f8.png" width="1471" title="" crop="0,0,1,1" id="u714400e3" class="ne-image">
###
### 3. 为什么返回 message 是成功,但 data 里面仍有错误信息呢?
message 显示成功,表示调用当前接口过程成功。
data 里面有错误信息,表明 NFR 服务内部调度出现了问题,需要及时反馈。
### 4. 出现“400 Bad Request”如何解决?
这个错误属于请求参数构造错误,第一步核对参数是否设置有误,若无误,则第二步检查请求头设置问题。
### 5. 数字商品交易接口返回成功,代表链上交易成功?
不代表,该处的返回成功仅代表这笔交易上链成功(成功提交到链上),不代表链上交易成功,如果要查询一笔交易真正在链上完成,请使用"交易结果查询"接口。
### 6.关于并发
关于上链与并发问题,是所有业务系统均会存在的。天河链并发性能数万TPS,可以满足大多数应用场景诉求。上链接口属于旁路接口,不建议在业务流程直接调用上链接口,可以通过消息队列实现削峰填谷处理。订单号和链上交易订单对应在执行交易后,将其进行关联。步骤如下:
【1】将交易提交到链上,得到交易hash
【2】延时查询交易执行状态,如果正常,则交易结束,如果异常,需要重新提交交易,并更换交易hash,正常情况下是不会有异常的。