Webview Template Feature
#
BackgroundIf you have a Mobile Web Application(H5) and want to migrate it to the Binance mini program, you have to rewrite all the code. To help developers build mini programs more quickly, we create an H5 mini program template. With this template, you can build a mini program from your own web page even without changing any code.
#
Quick StartBefore getting started, you should create an application in the Mini Program Management Platform.
Then go to the application detail page, click the upload button and choose Use a template
Input the version, H5 Application Link, description and click submit.
That’s all. After being approved by the Mini Program Auditor, you can publish your application.
You may need to add the web view host to the white list if you never do that before.
For more details about the Mini Program Management Platform, you can refer to Management Portal document.
Calling the Mini Program API Even though your code is running on the web page, you can still call the mini program API. In order to do this, you must import the SDK file to your page first
Note: it is recommended that developers put the SDK file on their own CDN so that they can provide users with an uniform and controlled speed experience.
bn
is a global object injected by the SDK. The request and response have the same format
When sending a request, action is the API name and payload is the API argument if needed. When receiving a response, action is the API name and payload is the API response.
Because we are using postMessage, we can’t get the response immediately. So we have to listen to the API we called.
Please refer to the mini program API documentation to see which API you can use.
#
Example How to Integrate Binance Pay On Webview feature#
Integrate with Binance PayPlease refer to the document of Binance Pay, and integrate with your backend server to create an order.
The Create Order API will return your server with the parameter prepayId
. A sample response looks like this:
#
Calculate the payment signature for mini programThe backend needs to calc a signature for the mini program, by the prepareId from the previous step, which follows the same rules of create a new order:
Example:
String payload = "certSn=317c110ebf7baf641e8f49ab6851331737dbe98541947c53b9dbba27f8c8414f" + "&" + "merchantId=98765987" + "&" + "noncestr=5K8264ILTKCH16CQ2502SI8ZNMTM67VS" + "&" + "prepayId=98765987" + "&"+ "timeStamp=1618302830073"; String signature = hex(hmac("sha512", payload, secretKey)).toUpperCase();
A sample code in node js will be like:
Return everything to your mini program app
#
Evoke the payment process from mini programCall the api requestPayment({})
, like
Notice
- The api requestPayment needs special permission. Please check with the Binance Supporter whether your mini program appid has the permission.
- The timeStamp to requestPayment is a string
#
How To Debug It on Real Devices- Create the experience qrcode
Refer to Mini Program Experience Version
Scan the qrcode
Get the logs on the real devices