This document is applicable for enterprise or individual developers that access to LinkToken exchange applications on the basis of Xunlei Blockchain technology.
20180406 v1.0
ThunderChain is a high-performance Blockchain with millions of tps high-concurrent processing capability and on-second-confirmation capability created by its Onething Technologies. On this basis, ThunderChain Open Platform is built to assist developers in quickly developing and deploying smart contracts. Enterprises or individuals can easily implement their products and services to take easier steps to develop Blockchain applications.
ThunderChain Open Platform is an open platform for Blockchain services built by Onething Technologies on the strength of the "ThunderChain". Xunlei opens more than ten years of distributed technology precipitation and its hundreds of millions of user base, shares millions of active individuals of LinkToken ecology to lead the industry with a high starting point, which jointly build the world-leading Blockchain ecology.
Make it possible for the user of LinkToken Pocket to activate the LinkToken Pocket Exchange Module by scanning or by skipping in the Merchant's APP, exchanging corresponding services easily.
ThunderChain provides stable, fast and low-cost blockchain services, helping developers reduce costs and create decentralized applications in various industries including financing, e-commerce, game and social media. It helps developers quickly deploy the smart contracts, allows enterprises to easily implement their products and services on the blockchain and develop blockchain applications more conveniently
Before an individual or enterprise developer wants to use the LinkToken exchange and the smart contract, you must firstly regist as the user of the platform. The phone number is the unique identification of the user. After successful registration, you can bind the E-mail. Login
Procedures of registration are as follows:
After binding the E-mail, it is convenient to receive the message notification, which is convenient for contacting with the official. If you forget your password, you can reset your password via E-mail. Binding Now
User may fail to login if he/she forgot the password; under the circumstance, the password can be reset by phone number or email address.
Reset password by phone number verification code
Reset password by E-mail verification
Individual developers who want to submit a contract or use the LinkToken exchange function must first verify their personal information. Please register as a platform user before performing personal authentication. Please have your ID card and the photos of both sides of the ID card (the photos must be clear, where your profile picture must be included).
Enterprise developers need to conduct enterprise authentication whose information includes the name of the enterprise, the scanned copy of the business license, the scanned copy of the legal representative's ID card or the scanned copy of the authorization. After the enterprise authentication is passed, the LinkToken exchange and smart contract functions can be used.
LinkToken exchange and smart contract are related to the app. Before using the functions, an app must be created. Or else, the functions cannot be used. The user needs to submit the app information to the open platform for approval.
The app is in two types, namely mobile app and web app. Software package for downloading or verification should be provided for mobile app. The accessible website page and website registration information must be provided for web app.
The mode of the exchange system module is completed in the mobile application APP of the accessing party. Exchange Function of LinkToken Pocket APP Code Scanning: the partner's own transaction system generates an exchange QR code according to LinkToken exchange protocol, and the user then completes the exchange mode by using the “RichScan”in the LinkToken Pocket App. Currently supported phone systems are: iOS (Apple), Android (Android).
The accessing party needs to follow the LinkToken Pocket APP protocol to generate order information from its own background and generate signature according to the rules (the signature is used to protect the order from being tampered with); The LinkToken Pocket converts this into transaction information on the Blockchain. After the user completes the exchange, the information is permanently recorded on the Blockchain. In order to optimize the access process of the accessing party, our company provides a background callback process for quickly notifying the accessing party of the status of the exchange process.
http://red.xunlei.com/html/guider.html?action=
Parameter
action :Provided by the business party, which needs url encoding for the LinkToken Pocket request for transaction information
The structure returned by the accessing party after the LinkToken Pocket accesses the url pointed to by the action
// Result
{
"iRet":0,
"sMsg": "ok",
"data": {
"tx_data": ""
}
}
The interface of tx_data is as follows:
Parameter | Type | Description |
---|---|---|
desc | string | paymenttitle |
callback | string | do url encoding and link the background callback |
to | string | roll out the LinkToken Pocket address (all lowercase) |
value | string | quantity of LinkToken (unit wei) |
prepay_id | string | prepaid order number obtained from Blockchain interface |
service_id | string | business id, need to apply for service_id and signature key from Onething Technologies |
sign | string | signature value, refer to How to calculate signature |
Need to do base64 encoding on tx_data as a whole Example:
callback=http%3A%2F%2F47.91.153.110%3A3000&desc=极速竞拍拍点充值&prepay_id=201712111442180000000377203337907978&service_id=3&sign=3b82f2275d9f84bbda82eae9bdf32fb7&to=0x8cfa8ab1ff90aa86714ffe731021f899a5ce4f35&value=10000000000000000000
callback=http%3A%2F%2F47.91.153.110%3A3000&desc=Extremely rapid aution point recharge &prepay_id=201712111442180000000377203337907978&service_id=3&sign=3b82f2275d9f84bbda82eae9bdf32fb7&to=0x8cfa8ab1ff90aa86714ffe731021f899a5ce4f35&value=10000000000000000000
Do base64 encoding on tx_data as a whole
{
"iRet":0,
"sMsg": "ok",
"data": {
"tx_data":
"Y2FsbGJhY2s9aHR0cCUzQSUyRiUyRjQ3LjkxLjE1My4xMTAlM0EzMDAwJmRlc2M95p6B6YCf56ue5ouN5ouN54K55YWF5YC8Jm9yZGVyX2lkPTMmcHJlcGF5X2lkPTIwMTcxMjExMTQ0MjE4MDAwMDAwMDM3NzIwMzMzNzkwNzk3OCZzZXJ2aWNlX2lkPTMmc2lnbj0zYjgyZjIyNzVkOWY4NGJiZGE4MmVhZTliZGYzMmZiNyZ0bz0weDhjZmE4YWIxZmY5MGFhODY3MTRmZmU3MzEwMjFmODk5YTVjZTRmMzUmdmFsdWU9MTAwMDAwMDAwMDAwMDAwMDAwMDA="
}
}
otcpay.jar
to libs
Directory.PayEntryActivity
toAndroidManifest.xml
<activity android:name="onething.otcpay.PayEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="false"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
OtcPayManager.getInstance().callOtcPay(Activity context, byte[] tx_data, byte[] resource)
in the Activity
/ Fragment
that needs to be paidonActivityResult()
in the corresponding Activity
/ Fragment
to handle the callback.@Override
protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
OtcPayManager.OtcPayCallBack(requestCode, resultCode, data, newOtcResultCallback() {
@Override
publicvoidonOtcTransferSuccess() {
}
@Override
publicvoidonOtcPaySuccess() {
}
@Override
publicvoidonOtcPayFail(interrorCode) {
}
@Override
publicvoidonOtcPayCancel() {
}
});
}
Parameter | Type | Description |
---|---|---|
tx-data | byte[] | Base64 Encoding mainly contain the paid order information,key=value form,with & connection |
resource | byte[] | Base64 Encoding source app, prompt [return XXX] after successful payment |
Parameter | Type | Description |
---|---|---|
desc | string | paymenttitle |
callback | string | need URLEncode and link the background callback |
to | string | trasfer to LinkToken Pocket address |
value | string | quantity of LinkToken (unit wei) |
prepay_id | string | prepaid order number |
service_id | string | business id, apply the transaction center for service_id and signature key (background fetch). Reserved field |
sign | string | signature value |
Initiate transfer -> Transfer successfully (deducted amount) -> Write to block -> Sync block-> Block verification succeeded (the other party receives the amount, and the payment gets success)
Since the synchronization of the block requires an indefinite time, different callbacks are needed to record the user's operating state.
onOtcTransferSuccess()
, indicating that the user has successfully initiated the transfer operation, and the successful debit payment waits for the block verification, hereafter it will not receive the callback of onOtcPaySuccess()
.onOtcPaySuccess()
, indicating that the other party has successfully received the transfer. The transaction is successfully completed and at the same time it will not receive the callback of onOtcTransferSuccess()
.onOtcPayFail(int errorCode)
, and the currenterrorCodeis onlythe OtcPayManager#OTC_ERROR_CODE_INVALID_ARGUMENT
, which is the parameter verification error when the payment is adjusted.onOtcPayCancel()
.Evoke the agreement
The smart contract execution requests third-party app to wake LinkToken Pocket APP or code scanning through LinkToken Pocket APP.
LinkToken Pocket evoking agreement is otst://payment?
Request parameter description
Parameter | type | required | description |
---|---|---|---|
scheme | string | Yes | LinkToken Pocket scheme otst |
host | string | Yes | LinkToken Pocket host value: payment |
tx-data | byte[] | Yes | Base64 coding, mainly including order details for payment, key=value format, connected by & |
resource | byte[] | Yes | Base64 coding, source app (source dealer name), restricted to 10 characters |
cb-data | byte[] | No | Base64 coding (optional), payment caller needs extra information returned by LinkToken Pocket |
x-source | string | No | source app scheme eg. wky-app (iOS callback optional, no processing for Android), reserved field |
callback | string | No | url coding. After payment is completed, LinkToken callback address or schema http://www.xx.com or scheme://host/?hash=transaction receipt&msg=error description(base64)&code=error code&cb-data=transparent transmission information&result=(success|fail|cancel) |
iOS-User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E302 OneWallet/2.0.3 (iPhone; iOS 11.3.1; Scale/3.00; origin/2; nc/IN)
tx-data Parameter Description
Parameter | Type | Required | Description |
---|---|---|---|
desc | string | Yes | smart contract execution description. The prefix “smart contract execution-” must be attached |
callback | string | No | url coding. Third-party app background is to receive callback address after Blockchain transaction is completed |
to | string | Yes | transfer-out LinkToken Pocket address |
value | string | Yes | LinkToken number (unit wei), 1 LinkToken= 10 ** 18 wie, input integer, with no unit. For example, transfer of 1 LinkToken is1 000 000 000 000 000 000 |
prepay_id | string | Yes | prepayment order No. Get from interface getPrepayId |
service_id | string | Yes | business id. Apply for LinkToken exchange service to get service_id and signature key |
data | string | No | In case of smartcontract execution, input smart contract execution function and parameter code beginning with 0x. In case of LinkToken exchange, it is blank. |
gas_limit | string | No | Maximum gas for payment: In contract transaction, it is estimated execution service fee; it is blank in case of LinkToken exchange service, and the default transaction fee is 0.01; If transaction fee is above actual execution deduction amount, exceeding amount will be refunded to the payer; |
tx_type | string | No | In case of contract transaction, fixed value is contract; For LinkToken exchange, fixed value is tx_third; Default value is tx_third |
sign | string | Yes | transaction signature sign=md5(sha512(callback=xxx&prepay_id=xxx&service_id=xxx&to=xxx&value=xxx&key= private key)) callback url here do not need coding |
APP callback returns
(http://www.xx.com|scheme://host)?hash= transaction receipt &msg= error description (base64)&code= error code &cb-data= transparent transmission information&result=(success|fail|cancel)
Call the LinkToken Pocket from the OneThing Cloud
otst://payment/?tx-data=ZGVzYz3nlLXlvbFYWFhYJnRvPTB4MTIzNDU2Nzg5MDEyMzQ1Njc4OTAmdmFsdWU9MTIzLjQwJmdhc2xpbWl0PTUwMDAwJmRhdGE9MHgwMTAyMDMwNDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDEmc2lnbj0wNEI3QTU1QzQ3NDQwRDk4NUE0NDgzNkZENTVFQkVCNw==&resource=d2t5&x-source=wky&callback=wky://x-callback-url/&cb-data=base64 encoded callback transparent transmission parameter
Specific Analysis
The following information is included after decoding
APP callback return
(http://www.xx.com|scheme://host)?hash= transaction receipt &msg= error description (base64)&code= error code &cb-data= transparent transmission information&result=(success|fail|cancel)
ErrParams = Error{Code: -3001, Message: "Parameter Error"}
ErrTxEmpty = Error{Code: -3002, Message: "Transaction is empty"}
ErrTxSign = Error{Code: -3003, Message: "Transaction signature is not valid"}
ErrTxFail = Error{Code: -3004, Message: "Transaction failed"}
Err3rdSignErr = Error{Code: -3016, Message: "Signature verification failed"}
ErrInvalidServiceID = Error{Code: -3017, Message: "service_id is illegal"}
Sign generated by the business logic server
Transfer path
Business background-> Business front end->LinkToken Pocket app->Blockchain access->Blockchain
Signature algorithm:
sign=md5(sha512(callback=xxx&prepay_id=xxx&service_id=xxx&to=xxx&value=xxx&key= private key)),replace xxx with the parameter value.
As an operational resource, the LinkToken Pocket supports the ability to open the corresponding url page directly in the pocket by scanning the code.
Developers can contact the ThunderChain operation (open@onethingcloud.com) to apply for the corresponding domain name (must be https), which can achieve that the scan code can be opened to open the corresponding domain name page.
Request method: post
Parameter | Type | Description |
---|---|---|
service_id | int | business number, distributed by Onething Technologies |
sign | string | signature, signature algorithm:md5(sha512("service_id= business number &key= private key")), private key distributed by Onething Technologies |
timeout | int | The lifetime of the generated prepay_id, in seconds |
Request format and example:
//In order to maintain the same format as the Ethereum, request post body data is in accordance with the following format:
{
"jsonrpc": "2.0",
"method": "getPrepayId",
"params": {
"service_id": 0,
"sign": "f93d2813227b68f77bf0db84c62011ca",
"timeout": 1800
}
}
Response Parameter:
Parameter | Type | Description |
---|---|---|
iRet | int | 0 success |
sMsg | string | return description |
data | json object | if succeed, return prepay_id: 'xxxx',if failed, return the error information |
Return example:
{
"iRet":0,
"sMsg": "ok",
"data": {\"prepay_id\":\"201711291656030000000101431771972107\"}
}
Request url
Test environment:https://sandbox-pocketapi.lianxiangcloud.com/getOrderStatusByPrepayId
Formal environment:https://walletapi.onethingpcs.com:443/getOrderStatusByPrepayId
Parameter | Type | Description |
---|---|---|
service_id | int | business number, distributed by Onething Technologies |
prepay_id | string | obtain when the order is submitted |
Request format and example:
{"jsonrpc":"2.0","method":"getOrderStatusByPrepayId","params":{"service_id":1,"prepay_id":"20171019xxxxxxxxxxxx"}}
Response Parameter:
Parameter | Type | Description |
---|---|---|
iRet | int | 0 success |
sMsg | int | return description |
data | array | return data, json encoded string |
dataformat:
Parameter | Type | Description |
---|---|---|
from | string | payment address |
to | string | receiving address |
value | string | LinkToken amount,string,unit:wei, for example:"1000000000000000000" |
status | string | order status,0 initial,1 success,2 failure |
ctime | string | transaction time,for example:2017-10-19 15:37:00 |
hash | string | transaction hash |
payload | string | transaction payload |
Return example:
{
"iRet":0,
"sMsg":"success",
"data":{
"from":"0x7b6837189a3464d3c696069b2b42a9ae8e17dda1",
"to":"0x00a2810b56e763406cad8be8ee90b0b89b370829",
"value":"1000",
"ctime":"2018-12-28 11:56:00",
"status":0,
"hash":"0xe254b5a67458e8d2b20472028738baba7bf5f10c5fd19f471b31c6725e58b10e",
"pay_load":""
}
}
After the successful transaction, the Blockchain notification module will callback the prepay_id to the accessing party which needs to receive the processing and return a response.
When the background notification interaction is performed, if it is unsuccessful or overtime that the Blockchain notification module receives the accessing party's response, the module will consider that the notification fails. It can periodically re-initiates the notification with a certain policy, as far as possible, to improve the success rate of notification, which does not guarantee that the notification will eventually succeed. (The notification frequency is 15/15/30/180/1800/1800/1800/1800/3600, unit: second)
Note: The same notification may be sent to the accessing system for multiple times. The accessing system must be able to handle duplicate notifications correctly.
The recommended practice is to first check the status of the corresponding service data when it receives the notification for processing, and determine whether the notification has been processed. If it has not been processed, continuing to do it. If it is processed, returning the successful result directly. Before the status check and processing of business data, data locks should be used for concurrent processing capability control to avoid data confusion caused by function reentry. Special reminder: The accessing system must perform signature verification on the content of the transaction result notification to prevent data leakage from causing “false notification”.
Blockchain notification module callback protocol(post):
Parameter | Type | Description |
---|---|---|
prepay_id | string | prepay ID |
from | string | payment address |
to | string | receiving address |
value | string | LinkToken amount,string,unit:wei, for example:"1000000000000000000" |
status | string | order status,0 initial,1 success,2 failure |
timestamp | string | unix timestamp |
sign | string | md5(sha512(from=xxxxxx&prepay_id=xxxxxxxxxxxxx&status=1×tamp=1512893272&to=xxxxx&value=xxxx&key= private key )) |
For example:
from=xxxxxx&prepay_id=xxxxxxxxxxxxx&status=1×tamp=1512893272&to=xxxxx&value=100000000000000&sign=4124bc0a9335c2xxxxxxxxxxxxxx
one of them where sign=md5(sha512(from=xxxxxx&prepay_id=xxxxxxxxxxxxx&status=1×tamp=1512893272&to=xxxxx&value=xxxx&key= private key ))
After the accessing party receives the callback, it needs to respond to the Blockchain notification module(response):
return_code=0&return_msg=ok
Download and install by scanning code
Download and install by scanning code
After the user downloads and installs the APP, the account can be generated through the APP.