Interface Description
1. Related Interfaces
The web-view component loads pages that can use the JSSDK 1.4.20, JSSDK 1.4.20(ESM)The provided interface calls PhizClip-related capabilities.
Supported interfaces are:
| Interface Name | Description | Minimum Version |
|---|---|---|
| pz.miniProgram.navigateTo | The parameters are the same as the PhizClip interface | 1.0.0 |
| pz.miniProgram.navigateBack | Requires the delta parameter; if not passed, it is 1 | 1.0.0 |
| pz.miniProgram.switchTab | The parameters are the same as the PhizClip interface | 1.0.0 |
| pz.miniProgram.redirectTo | The parameters are the same as the PhizClip interface | 1.0.0 |
| pz.miniProgram.reLaunch | The parameters are the same as the PhizClip interface | 1.0.0 |
| pz.miniProgram.postMessage | Sending a message to an PhizClip will trigger the component's message event at a specific time (PhizClip back, component destruction, sharing) | 1.0.0 |
| pz.miniProgram.getEnv | Get the current environment | 1.0.0 |
| pz.miniProgram.close | Close the PhizClip | 1.0.3 |
| pz.miniProgram.navigateToMiniProgram | Jump to PhizClip | 1.0.4 |
| pz.miniProgram.navigateBackMiniProgram | Back to the previous PhizClip | 1.0.4 |
| pz.miniProgram.onWebviewEvent | Listening to events sent by mini-apps | 1.4.1 |
| pz.miniProgram.offWebviewEvent | Remove listening to events sent by mini-apps | 1.4.1 |
| pz.miniProgram.sendWebviewEvent | Triggers the bindevent method of the webview tag binding | 1.4.1 |
| pz.miniProgram.onShow | PhizClip onShow event registration callback | 1.0.6 |
| pz.miniProgram.onHide | PhizClip onHide event registration callback | 1.0.8 |
| pz.miniProgram.onUnload | PhizClip onUnload event registration callback | 1.0.8 |
| pz.chooseImage | Take a photo or upload | 1.0.1 |
| pz.getLocalImgData | Get image base64 | 1.0.9 |
| pz.getLocation | Get current geolocation information | 1.0.9 |
| pz.chooseLocation | Open map location | 1.0.9 |
| pz.downloadFile | Download file | 1.0.0 |
| pz.openDocument | Open file | 1.0.0 |
| pz.getAppletInfo | Return the current PhizClip base information | 1.0.0 |
| pz.getStorage | The parameters are the same as the PhizClip interface | 1.0.9 |
| pz.setStorage | The parameters are the same as the PhizClip interface | 1.0.9 |
| pz.removeStorage | The parameters are the same as the PhizClip interface | 1.0.9 |
| pz.clearStorage | The parameters are the same as the PhizClip interface | 1.0.9 |
| pz.getStorageInfo | The parameters are the same as the PhizClip interface | 1.0.9 |
| pz.canGoBack | Whether the current H5 page can return to the previous page | 1.2.0 |
| pz.canNavigateBack | Whether the current PhizClip page can return to the previous page | 1.2.0 |
| pz.setNavigationBarTitle | Set the current PhizClip page title | 1.2.0 |
| pz.request | Initiating a network request,The parameters are the same as the PhizClip interface | 1.3.9 |
| pz.callNativeAPI | H5 calls to native methods | 1.4.1 |
| pz.registNativeAPIHandler | Register H5 methods for native calls | 1.4.1 |
| pz.complete | Send load completion event to PhizClip | 1.4.11 |
Some sample code for API calls
js
pz.miniProgram.navigateTo({ url: '/path/to/page' })
pz.miniProgram.reLaunch({ url: '/path/to/page' })
pz.miniProgram.postMessage({ data: 'foo' })
pz.miniProgram.postMessage({ data: { foo: 'bar' } })
pz.miniProgram.getEnv(function(res) {
console.log(res.env) // miniprogram
console.log(res.version) // support on 1.4.18
})
// Synchronization method to determine the current H5 runtime environment
console.log(window.__fcjs_environment) // miniprogram
// Close the PhizClip
pz.miniProgram.close()
pz.miniProgram.navigateBackMiniProgram({
extraData: {},
success: function(res) {
console.log('navigateBackMiniProgram success callback:')
console.log(res)
}
})
pz.miniProgram.navigateToMiniProgram({
appId: '',
success: function(res) {
console.log('navigateToMiniProgram success callback:')
console.log(res)
}
})
pz.miniProgram.onShow((res) => {
console.log(res)
// res.data indicates the current PhizClip routing query
})
pz.miniProgram.onHide((res) => {
// Do Some Thing
})
pz.miniProgram.onUnload((res) => {
// Do Some Thing
})
pz.downloadFile({
url,
header,
timeout,
filePath
})
pz.openDocument({
filePath,
fileType
})
pz.chooseImage({
count: 1, // Default 9
sizeType: ['original', 'compressed'], // You can specify whether it is the original or compressed image, both are available by default
sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, both are available by default
success: (res) => {
console.log(res)
}
})
pz.getMini-AppInfo({
success: (res) => {
console.log('getMini-AppInfo', res)
// {
// appAvatar = "icon address";
// appDescription = "Description Information";
// appId = "PhizClip id";
// path = "The path to the PhizClip page when you click on the forward";
// appThumbnail = "The path to the cover image of the PhizClip, which may be a network path or a local path, with an aspect ratio of5:4";
// appTitle = "PhizClip name";
// userId = "Developers id";
// }
}
})
pz.chooseImage({
count: 1, // Default 9
sizeType: ['original', 'compressed'], // You can specify whether it is the original or compressed image, both are available by default
sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, both are available by default
success: (res) => {
console.log(res)
window.fc.miniProgram.getLocalImgData({
path: res.tempFilePaths[0],
success: (res) => {
console.log(res)
}
})
}
})
// Get whether the current H5 page can return to the previous page
pz.canGoBack({
success: function(res) {
console.log(res)
}
})
// Get whether the PhizClip can return to the previous page
pz.canNavigateBack({
success: function(res) {
console.log(res)
}
})
// Set up the PhizClip page title
pz.setNavigationBarTitle({
title: 'page title'
})
pz.request({
url: 'https://some.url',
method: 'GET',
data: {
param1: 'test'
},
success: function(res) {
console.log('success', res)
},
fail: function(res) {
console.log('fail', res)
},
complete: function(res) {
console.log('complete', res)
}
})2. PhizClip Special interfaces
| Interface Name | Description | Minimum Version |
|---|---|---|
| pz.miniProgram.onWebviewEvent | Listening to events sent by PhizClip | 1.4.1 |
| pz.miniProgram.offWebviewEvent | Remove listening to events sent by PhizClip | 1.4.1 |
| pz.miniProgram.sendWebviewEvent | Triggers the bindevent method of the webview tag binding | 1.4.1 |
| pz.callNativeAPI | Native API calls for H5 pages | 1.4.1 |
| pz.registNativeAPIHandler | Register for native calls to the API in H5 | 1.4.1 |
2.1 H5 page calls native api
Example interface name:js2AppFunction
2.1.1 iOS Example
objectivec
[[FATClient sharedClient] fat_registerWebApi:@"js2AppFunction" handle:^(id param, FATExtensionApiCallback callback) {
NSString *name = param[@"name"];
// id params = param[@"data"];
if ([name isEqualToString:@"getLocation"]) {
// Execute positioning logic
// Return results to HTML
NSDictionary *dict = @{@"errno":@"403", @"errmsg":@"No permission", @"result": @{@"address":@"Space Science and Technology Square, Nanshan District, Shenzhen, Guangdong Province"}};
callback(FATExtensionCodeSuccess, dict);
} else if ([name isEqualToString:@"getColor"]) {
// Execute other logic
// Return results to HTML
NSDictionary *dict = @{@"r":@"110",@"g":@"150",@"b":@"150"};
callback(FATExtensionCodeSuccess, dict);
}
}];2.1.2 Android Example
api example
java
public class WebApi extends BaseApi {
public WebApi(Context context) {
super(context);
}
@Override
public String[] apis() {
return new String[]{"js2AppFunction"}; //api name
}
@Override
public void invoke(String event, JSONObject param, ICallback callback) {
// The native counterpart of the operation when the method is called
}
}Kotlin
java
FinAppClient.extensionWebApiManager.registerApi(WebApi(this))Java
java
FinAppClient.INSTANCE.getExtensionWebApiManager().registerApi(new WebApi(this));2.1.3 HTML Example
Referencing our bridge JSSDK file within the HTML will invoke the registered method above.
Example of calling the registered method from within within HTML
js
pz.callNativeAPI('js2AppFunction', { name:'getLocation' }, (result) => {
console.log(result)
});2.2 Calling methods in HTML natively
Example interface name: app2jsFunction
2.2.1 iOS API
The native side calls the following API to call JS functions in HTML.
objectivec
NSString *jsonParams = @""; //This should be the json string converted from the parameter dictionary.
NSNumber *pageId = @(1234); //Here is the pageId passed from the HTML
[[FATClient sharedClient] fat_callWebApi:@"app2jsFunction" paramString:jsonParams pageId:pageId handler:^(id result, NSError *error) {
}];2.2.2 Android API
java
/**
* Native calls to JS functions
*
* @param appId mini-appid
* @param funcName JS function name
* @param funcParams JS function parameters
* @param webViewId WebView id
* @return The result of the function call, returned as [Single]<[String]>
*/
fun callJS(appId: String, funcName: String?, funcParams: String?, webViewId: Int): Single<String?>Calling Example
Kotlin
kotlin
FinAppClient.mini-appApiManager.callJS("appId", "app2jsFunction", "funParams", 1)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
context.toast("callJs successfully : $it")
}) { Log.d(TAG, "callJs failed : ${it.localizedMessage}") }Java
java
FinAppClient.INSTANCE.getMini-AppApiManager().callJS("appId", "app2jsFunction", "funParams", 1)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
result -> Toast.makeText(context, "callJS successfully : " + result, Toast.LENGTH_SHORT).show(),
throwable -> Toast.makeText(context, "callJS failed : " + throwable.getLocalizedMessage(), Toast.LENGTH_SHORT).show()
);2.2.3 HTML API
The same HTML references the JSSDK file for bridging, and then registers the method in the HTML, e.g. method named app2jsFunction.
js
pz.registNativeAPIHandler('app2jsFunction', function(res) {
// app2jsFunction callback
})2.3 H5 pages send events to PhizClip
2.3.1 H5
js
// H5
pz.miniProgram.sendWebviewEvent({
test: 123
})2.3.2 PhizClip
Logic Layer
js
// PhizClip /pages/index/index.js
Page({
onEvent(e) {
console.log(e.detail.test) // 123
},
})View Layer
HTML
<!-- PhizClip /pages/index/index.fxml -->
<web-view src="https://xxx.xxx" bindevent="onEvent"></web-view>2.4 PhizClip send events to H5 pages
2.4.1 H5
js
function onEvent(e) {
console.log(e.test) // 123
}
// Register to listen
pz.miniProgram.onWebviewEvent(onEvent)
// Remove Listening
pz.miniProgram.offWebviewEvent(onEvent)2.4.2 PhizClip
js
pz.sendWebviewEvent({ test: 123 })