Skip to content

Métodos de retorno de chamada

Parte do negócio no applet é definida no resumo e Essas abstrações são expostas ao mundo exterior na forma de Interfaces, que podem imaginar a lógica dos negócios de especificação. Esses métodos de proxy são declarados em classes abstratas, como [Iapplethandler], [iappletprocesshandler], etc.

1. ICPLETHANDLER

Parte do negócio abstrato é definido em IAppletHandler , O O aplicativo pode passar na instância de IAppletHandler para o SDK por chamando setAppletHandler DE IAppletApiManager , onde está os negócios Acionado, o SDK ligará de volta ao externo através do IAppletHandler Quando o negócio estiver em tribos, o SDK liga de volta Ao mundo externo através do método correspondente de IAppletHandler Para executar a lógica de negócios de especificação fotografada pelo externo mundo.

kotlin
/**
 * :: Applets abstract business callback interfaces, and the SDK
exposes these abstractions to external parties in the form of
interfaces, which are implemented concretely by external parties
*/
interface IAppletHandler {

 interface IAppletCallback {
 /**
* Success callback
*/
 fun onSuccess(result: JSONObject? = null)
 /**
* Failure to call back
*/
 fun onFailure()
 /**
* Cancel callbacks
*/
Subscribe to DeepL Pro to edit this document.
Visit www.DeepL.com/profor more information.
 fun onCancel()
 }
 /**
* Forwarding applets
*
* @param appInfo applet information, a string of json containing
information such as applet id, applet name, applet icon, user id, and
the content of the data forwarded.
* The content of [appInfo] is in the following format.
* {
*  "appTitle" :  "Vantaa Applet" ,
*  "appAvatar" :
"https:\/\/www.finogeeks.club\/statics\/images\/swan_mini\/swan_logo.pn
g",
*  "appId" :  "5df36b3f687c5c00013e9fd1" ,
*  "appType" :  "trial" ,
*  "userId" :  "finogeeks" ,
*  "cryptInfo" :
"SFODj9IW1ENO8OA0El8P79aMuxB1DJvfKenZd7hrnemVCNcJ+Uj9PzkRkf/Pu5nMz0cGjj
0Ne4fcchBRCmJO+
As0XFqMrOclsqrXaogsaUPq2jJKCCao03vI8rkHilrWxSDdzopz1ifJCgFC9d6v29m9jU29
wTxlHsQUtKsk/wz0BROa+aDGWh0rKvUEPgo8mB+40/
zZFNsRZ0PjsQsi7GdLg8p4igKyRYtRgOxUq37wgDU4Ymn/yeXvOv7KrzUT",
*  "params" : {
*  "title" : "apt-test-tweet-Interface-test-released-dynamics! @#$
%......&*(",
*  "desc" :  "Service Experts by Your Side" ,
*  "imageUrl" : "finfile:\/\/tmp_fc15edd8-2ff6-4c54-9ee9-
fe5ee034033d1576550313667.png",
*  "path" : "pages\/tweet\/tweet-detail.html?fcid=
%40staff_staff1%3A000000.finogeeks.com&timelineId=db0c2098-031e-41c4-
b9c6- 87a5bbcf681d&shareId=3dfa2f78-19fc-42fc-b3a9-4779a6dac654",
*  "appInfo" : {
*  "weixin" : {
*  "path" : "\/studio\/pages\/tweet\/tweet-detail" ,
*  "query" : {
*  "fcid" : "@staff_staff1:000000.finogeeks.com" ,
*  "timelineId" :  "db0c2098-031e-41c4-b9c6-87a5bbcf681d" 
* }
* }
* }
* }
* }
* Description of the fields in [appInfo].
* appId applet ID
* appTitle applet name
* appAvatar applet avatar
* appType applet type, where trial means experience, temporary
means temporary, review means review, release means online and
development means development
* userId User ID
* cryptInfo Applet encryption information
* other parameters attached to params, passed by the applet itself
*
* @param bitmap The applet cover image. If the
[appInfo].params.imageUrl field is a link address of http, https, then
the applet cover image
* Just take the image corresponding to [appInfo].params.imageUrl,
otherwise the cover image of the applet is taken as [bitmap].
*/
 fun shareAppMessage(appInfo: String, bitmap: Bitmap?, callback:
IAppletCallback)
 /**
* :: Obtaining user information
*
* @return UserInfo[Map]
*/
 fun getUserInfo(): Map<String, String>
 /**
* :: Obtain the user's mobile phone number
* Information is returned via callbacks in json format, generally
in the following format.
* { "phone" :  "xxxxxxxxxxxx" }
*/
 override fun getPhoneNumber(callback:
IAppletHandler.IAppletCallback) {
 callback.onSuccess(JSONObject().put( "phone" ,  "xxxxxxxxxxxx" ))
 }
 /**
 * :: Return to the host app page event from the applet page, with
the host app implementing this action.
* @return Returns true if the event was handled correctly,
otherwise false.
*/
 override fun launchApp(appParameter: String?): Boolean {
 return false
 }
 /**
* :: Opening of the  "Feedback"  page, which is taken over by the
host app.
* @return returns true if the host app takes over this event,
otherwise false and opens the default feedback page.
*/
 override fun feedback(bundle: Bundle): Boolean {
 return false
 }
 /**
* Get user avatar, return information via callback, pass through
to applet by SDK
*/
 override fun chooseAvatar(callback: IAppletHandler.IAppletCallback)
{
 callback.onFailure()
 }
 /**
* Open a customer service session and have the host app implement
the specific operation
* @param json Data passed from the applet to the host app
* @return Returns true if the session is successfully opened,
otherwise returns false
*/
 override fun contact(json: JSONObject): Boolean {
 return false
 }
 /**
* Get the registered  "More"  menu item
*
* @param appId applet ID
* @return registered  "More"  menu item
*/
 fun getRegisteredMoreMenuItems(appId: String): List<MoreMenuItem>?
 /**
* The  "More"  menu item of the registration is clicked
*
* @param appId applet ID
* @param path applet page path
* @param menuItemId The ID of the clicked menu item
* @param appInfo applet information, a string of json containing
information such as applet id, applet name, applet icon, user id, and
the content of the data forwarded.
* The content of [appInfo] is in the following format.
* {
*  "appTitle" :  "Vantaa Applet" ,
*  "appAvatar" :
"https:\/\/www.finogeeks.club\/statics\/images\/swan_mini\/swan_logo.pn
g",
*  "appId" :  "5df36b3f687c5c00013e9fd1" ,
*  "appType" :  "trial" ,
*  "userId" :  "finogeeks" ,
*  "cryptInfo" :
"SFODj9IW1ENO8OA0El8P79aMuxB1DJvfKenZd7hrnemVCNcJ+Uj9PzkRkf/Pu5nMz0cGjj
0Ne4fcchBRCmJO+
As0XFqMrOclsqrXaogsaUPq2jJKCCao03vI8rkHilrWxSDdzopz1ifJCgFC9d6v29m9jU29
wTxlHsQUtKsk/wz0BROa+aDGWh0rKvUEPgo8mB+40/
zZFNsRZ0PjsQsi7GdLg8p4igKyRYtRgOxUq37wgDU4Ymn/yeXvOv7KrzUT",
*  "params" : {
*  "title" : "apt-test-tweet-Interface-test-released-dynamics! @#$
%......&*(",
*  "desc" :  "Service Experts by Your Side" ,
*  "imageUrl" : "finfile:\/\/tmp_fc15edd8-2ff6-4c54-9ee9-
fe5ee034033d1576550313667.png",
*  "path" : "pages\/tweet\/tweet-detail.html?fcid=
%40staff_staff1%3A000000.finogeeks.com&timelineId=db0c2098-031e-41c4-
b9c6- 87a5bbcf681d&shareId=3dfa2f78-19fc-42fc-b3a9-4779a6dac654",
*  "appInfo" : {
*  "weixin" : {
*  "path" : "\/studio\/pages\/tweet\/tweet-detail" ,
*  "query" : {
*  "fcid" : "@staff_staff1:000000.finogeeks.com" ,
*  "timelineId" :  "db0c2098-031e-41c4-b9c6-87a5bbcf681d" 
* }
* }
* }
* }
* }
* Description of the fields in [appInfo].
* appId applet ID
* appTitle applet name
* appAvatar applet avatar
* appType applet type, where trial means experience, temporary
means temporary, review means review, release means online and
development means development
* userId User ID
* cryptInfo Applet encryption information
* other parameters attached to params, passed by the applet itself
*
* @param bitmap The applet cover image. If the
[appInfo].params.imageUrl field is a link address of http, https, then
the applet cover image
* Just take the image corresponding to [appInfo].params.imageUrl,
otherwise the cover image of the applet is taken as [bitmap].
*/
 fun onRegisteredMoreMenuItemClicked(appId: String, path: String,
menuItemId: String, appInfo: String?, bitmap: Bitmap?, callback:
IAppletCallback)
 /**
* Get the grey-scale release configuration parameters
*
* @param appId applet ID
* @return grayscale release configuration parameters
*/
 fun getGrayAppletVersionConfigs(appId: String):
List<GrayAppletVersionConfig>?
 /**
* The  "Close"  button in the applet navigation bar is clicked
*
* @param appId applet ID
*/
 fun onNavigationBarCloseButtonClicked(appId: String)
}

API

kotlin
/**
* Set the [IAppletHandler] implementation class
*
* @param appletHandler [IAppletHandler] implementation class
*/
fun setAppletHandler(appletHandler: IAppletHandler)

Exemplo de uma chamada para #### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.setAppletHandler(
 object : IAppletHandler {
 override fun shareAppMessage(
 appInfo: String,
 bitmap: Bitmap?
 callback: IAppletHandler.
 ) {
 }
 })

:::

::: tab "Java"

java
FinAppClient. INSTANCE. getAppletApiManager(). setAppletHandler(new
IAppletHandler() {
 @Override
 public void shareAppMessage(@NotNull String appInfo,
 @Nullable Bitmap bitmap,
 @NotNull IAppletCallback callback) {
 }
});

::: ::::

Nota

  • A classe final precisa ser usada no processo de applet.
  • Para métodos de retorno de chamada assíncronos (com retornos de chamada como parâmetros), Faça da Surethat que você usa retornos de chamada, independentemente de se o negócio A lógica terá sucesso ou não, caso contrário, o resultado da chamada não será Recebido no lado do applet.

2. IaApppletProcessHandler

API

kotlin
/**
* Set the implementation class of [IAppletProcessHandler].
*
* @param appletProcessHandler [IAppletProcessHandler] implementation
class
*/
fun setAppletProcessHandler(appletProcessHandler:
IAppletProcessHandler)

Exemplo de uma chamada para #### :::: tabs ::: tab "Kotlin"

kotlin
FinAppProcessClient.appletProcessApiManager.setAppletProcessHandler(
 object : IAppletProcessHandler {
 override fun onNavigationBarMoreButtonClicked(
 context: Context,
 appId: String
 ): Boolean {
 return true // return true means that the "more" button
click event is handled by itself, blocking the default menu display
logic.
 }
 })

:::

::: tab "Java"

java
FinAppProcessClient. INSTANCE. getAppletProcessApiManager().
setAppletProcessHandler(new IAppletProcessHandler(){
 @Override
 public boolean onNavigationBarMoreButtonClicked(@NonNull Context
context, @NonNull String appId) {
 return true; // return true means that the "more" button click
event is handled by itself, blocking the default menu display logic.
 }
});

::: ::::

Nota

  • A classe FINAppProclient precisa ser usada no processo de applet. Por favor, use o FinAppClient.INSTANCE.isFinAppProcess() Método para Determine se você está em um processo de applet
  • O método da interface IAPPLETPROCESSHANDLER é executado no applet Processo.

3. IAAPPletlifeCycleCallback

Se um partido excérmico precisou para a vida útil do applet, Eles podem chamar de setAppletLifecycleCallback interface do IAppletApiManager para passar na instância de IAppletLifecycleCallback Para o SDK, e quando o ciclo de vida do applet mudar, o SDK irá Ligue de volta à parte externa viaWhen the lifecycle of the applet changes, the SDK will call back to the outside via the corresponding method of IAPPLETLIFECYCLECALLBACK` .

kotlin
/**
* :: Applet lifecycle callback interface
*/
interface IAppletLifecycleCallback {

 /**
* The current page state of the applet, corresponding to
[Activity]. [onCreate] corresponds to
*/
 fun onCreate(appId: String)
 /**
* The current page state of the applet, corresponding to
[Activity]. [onStart] corresponds to
*/
 fun onStart(appId: String)
 /**
* The current page state of the applet, corresponding to
[Activity]. [onResume] corresponds to
*/
 fun onResume(appId: String)
 /**
* The current page state of the applet, corresponding to
[Activity]. [onPause] corresponds to
*/
 fun onPause(appId: String)
 /**
* The current page state of the applet, corresponding to
[Activity]. [onStop] corresponds to
*/
 fun onStop(appId: String)
 /**
* The current page state of the applet, which corresponds to
[Activity]. [onDestroy] corresponds to
*/
 fun onDestroy(appId: String)
}

API

kotlin
/**
* Set [IAppletLifecycleCallback]
*
* @param appletLifecycleCallback [IAppletLifecycleCallback] object
*/
fun setAppletLifecycleCallback(appletLifecycleCallback:
IAppletLifecycleCallback)

Example of a call to #### :::: tabs ::: tab "Kotlin"

kotlin
FinAppClient.appletApiManager.setAppletLifecycleCallback(object :
IAppletLifecycleCallback {
override fun onCreate(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onCreate : $appId")
 }
 override fun onInitComplete(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onInitComplete : $appId")
 }
 override fun onStart(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onStart : $appId")
 }
 override fun onResume(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onResume : $appId")
 }
 override fun onPause(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onPause : $appId")
 }
 override fun onStop(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onStop : $appId")
 }
 override fun onDestroy(appId: String) {
 Log.d(TAG, "IAppletLifecycleCallback onDestroy : $appId")
 }
 override fun onFailure(appId: String, errMsg: String) {
 Log.d(TAG, "IAppletLifecycleCallback onFailure : $appId ,
$errMsg")
 }
})

:::

::: tab "Java"

java
FinAppClient. INSTANCE. getAppletApiManager().
setAppletLifecycleCallback(new IAppletLifecycleCallback() {
 @Override
 public void onCreate(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onCreate : " + appId);
 }
 @Override
 public void onInitComplete(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onInitComplete : " +
appId);
 }
 @Override
 public void onStart(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onStart : " + appId);
 }
 @Override
 public void onResume(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onResume : " + appId);
 }
 @Override
 public void onPause(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onPause : " + appId);
 }
 @Override
 public void onStop(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onStop : " + appId);
 }
 @Override
 public void onDestroy(@NotNull String appId) {
 Log. d(TAG, "IAppletLifecycleCallback onDestroy : " + appId);
 }
 @Override
 public void onFailure(@NotNull String appId, String errMsg) {
 Log. d(TAG, "IAppletLifecycleCallback onFailure : " + appId);
 }
});

::: ::::

4. IAppletOpenTypeHandler

Starting with 2.37.3 , the Iapplethandler is split into interface classes dedicated to abrir-Tipo type events, including GetphoneNumber , Chooseavatar , Lançamento do Aplicativo , contal , ShareAppMessage, opinião.

Code example.

:::: tabs

::: tab "Kotlin"

kotlin
FinAppClient.appletOpenTypeHandler = MyAppletOpenTypeHandler()

:::

::: tab "Java"

java
FinAppClient. INSTANCE. setAppletOpenTypeHandler(new
MyAppletOpenTypeHandler());

:::

::::

Note

  • The FINAPPCLIENT class needs to be used in the applet process.
  • Setting up IAPPLETOPENTYPEHANDLER will override the implementation of the abrir-Tipo method above in Iapplethandler .
  • If the Phiz Extension SDK (PhizSDK) is integrated, do not use this interface class, but instead use.
Kotlin
WechatopentypeClient.instance.iwechatopeEntypeHandler =
MywechatappleToPEntypeHandler ()