The service updates authorization code button is supported since version 6.0.0 (20).
The service updates authorization code button enables retrieval of a system-generated dynamic authorization code, which can be used to push service updates. In your atomic service, you need to set OpenType of the scenario-specific button component to REQUEST_SUBSCRIBE_MESSAGE on the page. After a user taps the button, the authorization code can be obtained through the onRequestSubscribeMessage callback.
This button is available only for atomic services. For other scenarios, error code 10004 or 10008 will be returned.
An authorization code obtained through the service updates authorization code button is unique within the service process. You must use this code to update a user's service status later.
The platform will perform checks on the button component, including whether it misleads users into tapping or obtains the code through a button unrelated to the service updates scenario.
For details, please refer to Preparations.
Apply for the permission on the service updates message capability.
The service updates scenario in your atomic service supports obtaining an authorization code using the service updates authorization code button at the frontend.
The service updates authorization code button is available on phones and tablets, and newly supports PCs/2-in-1 devices from version 6.1.0(23) onwards.
A user taps the Get service updates by authorization code button to obtain an authorization code.

Import the Scenario Fusion Kit module and related common modules.
import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
import { hilog } from '@kit.PerformanceAnalysisKit'; Declare FunctionalButton in the container, set openType for the button, and configure the callback.
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
// Build an instance of the FunctionalButton component.
FunctionalButton({
params: {
// OpenType.REQUEST_SUBSCRIBE_MESSAGE indicates that the button is used to obtain an authorization code for service updates.
openType: functionalButtonComponentManager.OpenType.REQUEST_SUBSCRIBE_MESSAGE,
label: 'Get service updates by authorization code',
// The subSceneId parameter is mandatory to obtain a service updates authorization code.
subSceneId: '',
// Adjust the button style.
styleOption: {
styleConfig: new functionalButtonComponentManager.ButtonConfig()
.fontSize(20)
}
},
// When OpenType is set to REQUEST_SUBSCRIBE_MESSAGE, the callback must be onRequestSubscribeMessage.
controller: new functionalButtonComponentManager.FunctionalButtonController()
.onRequestSubscribeMessage((err, data) => {
if (err) {
// Error processing.
hilog.error(0x0000, 'testTag', 'Failed to request subscribe message, error: %{public}d %{public}s', err.code, err.message);
return;
}
// Success processing.
hilog.info(0x0000, 'testTag', 'succeeded in requesting subscribe message');
// Process the service updates code.
let code = data.code;
})
})
}.width('100%')
.padding({ left: 16, right: 16 })
}.height('100%')
}
}
Set openType to functionalButtonComponentManager.OpenType.REQUEST_SUBSCRIBE_MESSAGE to specify the purpose of the button as to obtain an authorization code for service updates.
The subSceneId parameter is mandatory in the service updates authorization code scenario. For details, see Service Updates Scenario Templates.
Set controller to new functionalButtonComponentManager.FunctionalButtonController().onRequestSubscribeMessage.
You can use the custom Modifier to set the button style. For details, please refer to the example.
For details about other parameters, please refer to FunctionalButton (Button Component).