Webview Template Feature
#
BackgroundSuppose you have a Mobile Web Application (H5), and you wish to transition it to a Binance mini program, necessitating a complete code rewrite. To accelerate developers' journey in mini program creation, we have constructed an H5 mini program template. This template enables you to develop a mini program from your own webpage, negating the need for any code alterations.
#
Quick StartYour first steps should entail creating an application on the Mini Program Management Platform. Next, navigate to the application detail page, select the upload button, and pick Use a template
.
Enter the version, H5 Application Link, and a description. Click submit to finish.
That's it! After Mini Program Auditor approval, your application is ready for publishing. Remember, if you've not done it before, you may need to add the web view host to the white list.
Confused about the Mini Program Management Platform? Refer to the Management Portal document for more details.
When your code is executing on the web page, you can still call the mini program API. This, however, necessitates SDK file importing to your page first.
Note: To ensure a consistent and controlled speed experience for users, it's recommended for developers to position the SDK file on their own CDN.
A global object, bn
, is injected by the SDK. Using the postMassage
method to send request and using onMessage
to handle the callback of response. The parameter action
is the API name and the parameter payload
is the API options. Both request and response maintain the same format.
Consult the mini program API documentation to identify which API is suitable for use.
#
How to Integrate Binance Pay On Webview Feature#
Integrating with Binance PayTake a look at the document of Binance Pay for guidelines on a back-end server integration to generate 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 will require a signature calculation for the mini program, using the prepareId from the previous step, adhering to the same rules for order creation.
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 programOnce you have all the steps in place, evoke the payment process from the mini program by calling the API requestPayment({})
.
Note:
- The API
requestPayment
needs special permissions. Please check with Binance Support whether your mini program appid holds the necessary permissions. - The timeStamp to
requestPayment
is a string.
#
Debug on Real DevicesFor debugging on real devices, you need to create an experience QR code. When the QR code is scanned, you can view the logs on the real devices.
Refer to Mini Program Experience Version