提交 e28e27a3 作者: 刘添

合并分支 'sdk_doc_demo' 到 'master'

添加demo和文档

查看合并请求 zwwl/zw_game_sdk!283
{
"enabledPlugins": {
"claude-code-setup@claude-plugins-official": true
}
}
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
/.appanalyzer
\ No newline at end of file
{
"app": {
"bundleName": "com.xmdzzharmony.huawei",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:ic_float",
"label": "$string:app_name"
}
}
{
"string": [
{
"name": "app_name",
"value": "熊猫大作战"
}
]
}
{
"layered-image":
{
"background" : "$media:ic_float",
"foreground" : "$media:ic_float"
}
}
\ No newline at end of file
{
"app": {
"signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"storeFile": "D:/xmdzzDemo/xmdzz.p12",
"storePassword": "000000198F9E50DDE8455EBA62360F82FB7A2D79311BA379020176B7FEDC5D4224D5A37FD071B1A8D5",
"keyAlias": "xmdzzharmony",
"keyPassword": "00000019E263439A45216EEE2E9B7C2BD0F4AAC2635841C26CD056A6FC6AED0E7D2204DC66883468C4",
"signAlg": "SHA256withECDSA",
"profile": "D:/xmdzzDemo/熊猫大作战调试profileDebug.p7b",
"certpath": "D:/xmdzzDemo/xmdzz测试证书.cer"
}
}
],
"products": [
{
"name": "default",
"signingConfig": "default",
"targetSdkVersion": "6.0.1(21)",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
{
"files": [
"**/*.ets"
],
"ignore": [
"**/src/ohosTest/**/*",
"**/src/test/**/*",
"**/src/mock/**/*",
"**/node_modules/**/*",
"**/oh_modules/**/*",
"**/build/**/*",
"**/.preview/**/*"
],
"ruleSet": [
"plugin:@performance/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@security/no-unsafe-aes": "error",
"@security/no-unsafe-hash": "error",
"@security/no-unsafe-mac": "warn",
"@security/no-unsafe-dh": "error",
"@security/no-unsafe-dsa": "error",
"@security/no-unsafe-ecdsa": "error",
"@security/no-unsafe-rsa-encrypt": "error",
"@security/no-unsafe-rsa-sign": "error",
"@security/no-unsafe-rsa-key": "error",
"@security/no-unsafe-dsa-key": "error",
"@security/no-unsafe-dh-key": "error",
"@security/no-unsafe-3des": "error"
}
}
\ No newline at end of file
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
{
"apiType": "stageMode",
"buildOption": {
"resOptions": {
"copyCodeResource": {
"enable": false
}
}
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": false,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],
"targets": [
{
"name": "default"
},
{
"name": "ohosTest",
}
]
}
\ No newline at end of file
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import { hapPlugin } from '@hadss/hmrouter-plugin'; // 必须有这个插件
export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins: [hapPlugin()] /* Custom plugin to extend the functionality of Hvigor. */
}
\ No newline at end of file
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
-enable-property-obfuscation
-enable-toplevel-obfuscation
-enable-filename-obfuscation
-enable-export-obfuscation
\ No newline at end of file
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {}
}
import { AbilityConstant, common, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { AppUtil, LogUtil, SDKToolsManager } from 'zwgame';
const DOMAIN = 0x0000;
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
try {
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
} catch (err) {
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
}
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
SDKToolsManager.getInstance().firstInitBeforePrivacy(this.context as common.UIAbilityContext)
AppUtil.init(this.context)
}
onDestroy(): void {
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
return;
}
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
// 其中第二个参数为华为联合登陆面板展示的游戏登录的标题内容;第三个参数为游戏图标路径(华为平台要求图标大小一定不能超过35KB)
SDKToolsManager.getInstance().initSDK(windowStage,'深海花园游戏账号登录',$r('app.media.ic_float'),this.context, {
getPrivacyCallBack: (data: boolean): void => {
if (data) {
// 值为true代表同意
LogUtil.info('zfcs', '用户点击了隐私弹框的同意按钮')
}
}
})
});
}
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
SDKToolsManager.getInstance().onWindowStageDestroy()
}
onForeground(): void {
// Ability has brought to foreground
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
SDKToolsManager.getInstance().onForeground()
}
onBackground(): void {
// Ability has back to background
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
SDKToolsManager.getInstance().onBackground()
}
}
\ No newline at end of file
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
const DOMAIN = 0x0000;
export default class EntryBackupAbility extends BackupExtensionAbility {
async onBackup() {
hilog.info(DOMAIN, 'testTag', 'onBackup ok');
await Promise.resolve();
}
async onRestore(bundleVersion: BundleVersion) {
hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
await Promise.resolve();
}
}
\ No newline at end of file
import { HMDefaultGlobalAnimator, HMNavigation,
SDKToolsManager, ToastUtil} from 'zwgame'
import { AttributeUpdater } from '@kit.ArkUI'
// 定义自定义导航修饰符类
class MyNavModifier extends AttributeUpdater<NavigationAttribute> {
initializeModifier(instance: NavigationAttribute): void {
instance.hideNavBar(true); // 隐藏导航栏
}
}
@Entry
@ComponentV2
struct Index {
modifier: MyNavModifier = new MyNavModifier(); // 创建修饰符实例
build() {
Column() {
// HMNavigation 是页面的导航容器
HMNavigation({
navigationId: 'mainNavigation', // 导航实例ID,需唯一
homePageUrl:'SecondMainPage',
options: {
modifier: this.modifier, // 添加修饰符配置
standardAnimator: HMDefaultGlobalAnimator.STANDARD_ANIMATOR // 标准页面动画
}
}).width('100%').height('100%')
}.height('100%').width('100%')
}
aboutToAppear(): void {
// 参数依次 为 掌玩SDK平台获取游戏id`gameId `、游戏包名`packName`、游戏工程的版本号`versionCode`、页面横竖屏字段(0:横屏;1:竖屏)、`appStatus` 传0 (0默认SDK,1表示巨量AD,2表示快手,3表示腾讯)、宿主的上下文环境, 展示游戏的背景图,种花游戏需设置为true,其他游戏为false(true:展示;false:不展示)
SDKToolsManager.getInstance().aboutToAppear('2582','com.xmdzzharmony.huawei','1.0.0',1,'0',this.getUIContext(), false)
}
}
\ No newline at end of file
import {
AppUtils,
DialogManagerService,
SuspensionV2,
HMRouter,
SDKToolsManager,
AppUtil,
LogUtil,
} from 'zwgame';
import { DeviceInfoUtils } from 'zwgame/src/main/ets/utils/DeviceInfoUtils';
import { DeviceIdSdkUtil } from 'zwgame/src/main/ets/utils/DeviceIdSdkUtil';
@Entry
@HMRouter({ pageUrl: 'SecondMainPage', singleton: true })
@ComponentV2
export struct SecondMainPage {
@Local message: string = 'Hello World';
// 控制弹框显示的状态变量
@Local isPopupShown: boolean = false;
@Local shoudleShowWindow: boolean = false
@Local server_id:string = ''
@Local cp_role_id:string = ''
@Local deviceInfo:string = ''
@Local amount:string = ''
@Local product_price:string = ''
@Local product_cnt:string = ''
@Local loginInfo:string = '熊猫大作战游戏账号登录'
async aboutToAppear(): Promise<void> {
}
build() {
Stack() {
Scroll() {
Column() {
Button('sdk登录').onClick(() => {
SDKToolsManager.getInstance()
.showSdkLogin(this.getUIContext(), '熊猫大作战游戏账号登录', $r('app.media.ic_float'), {
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
}
}, {
onPanelClosed: (code: number, reason: string): void => {
if (code == 1002000016) {
// 用户关闭了登录面板
LogUtil.info('test', '用户关闭了联合登录面板')
}
}
})
}).width(150).height(55).margin({ top: 15 })
Button('sdk退出登录').onClick(() => {
AppUtils.outLogin({
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
}
})
}).width(150).height(55).margin({ top: 15 })
Row(){
TextInput({text: this.amount,placeholder:'请输入总金额'}).onChange((value:string)=>{
this.amount = value
}).width(100).layoutWeight(1)
TextInput({text:this.product_price, placeholder:'请输入商品单价'}).margin(5).onChange((value:string)=>{
this.product_price = value
}).width(100).layoutWeight(1)
TextInput({text:this.product_cnt, placeholder:'请输入商品数量'}).margin(5).onChange((value:string)=>{
this.product_cnt = value
}).width(100).layoutWeight(1)
}.width('90%').height(95).margin({ top: 15 })
Button('华为支付').onClick(()=>{
let jsonStr = '{"role":{"event":"other","server_id":"1","role_name":"主宰传奇","cp_role_id":"2","server_name":"主宰服","role_level":"83","role_vip":"0"},"order":{"cp_order_id":"1770709001026","amount":"100","product_price":"100","product_id":"com.product.test01","product_cnt":"1","product_name":"1元档充值","product_desc":"商品","ext":"测试数据"}}'
AppUtils.createOrderWithHuaWei(jsonStr, '1', '2', this.amount,this.product_price,this.product_cnt,'com.product.test01',
{
Success: (msg: Object): void => {
LogUtil.info('test 支付成功: ' + msg.toString())
},
Failed: (msg: string): void => {
LogUtil.info('test 支付失败: ' + msg.toString())
}
})
}).width(150).height(55).margin({ top: 15 })
Button(this.shoudleShowWindow ? '隐藏悬浮框' : '显示悬浮框').onClick(() => {
this.shoudleShowWindow = !this.shoudleShowWindow
}).width(150).height(55).margin({ top: 15 })
Row(){
TextInput({text: this.server_id,placeholder:'请输入server_id'}).onChange((value:string)=>{
this.server_id = value
}).width(150).layoutWeight(1)
TextInput({text:this.cp_role_id, placeholder:'请输入cp_role_id'}).margin(5).onChange((value:string)=>{
this.cp_role_id = value
}).width(150).layoutWeight(1)
}.width('90%').height(95).margin({ top: 15 })
Button('角色上报').onClick(() => {
const jsonStr = '{"cp_account":"cp_account","role":{"event":"create","server_id":"serviceId","server_name":"server_name","cp_role_id":"cpRoleId","role_name":"role_name","role_level":"role_level","role_vip":"role_vip","combat_num":"combatnum","online_time":"online_time","reiki_num":"reikinum","attack":"attack","profession":"profession","gang_name":"gang_name","trans_level":"translevel","sponsor_level":"sponsorlevel","main_city_level":"maincitylevel","power":"power","chapter_index":"chapterindex"}}'
AppUtils.onRole(this.server_id, this.cp_role_id, jsonStr);
}).width(150).height(55).margin({ top: 15 })
Button('获取设备信息').onClick(async ()=>{
const deviceId = await DeviceIdSdkUtil.getInstance().getDeviceId(AppUtil.getUIContext())
this.deviceInfo = '厂商: ' + DeviceInfoUtils.getInstance().getDeviceInfo().brand + ', 型号: ' + DeviceInfoUtils.getInstance().getDeviceInfo().model + ' ,系统: ' +DeviceInfoUtils.getInstance().getDeviceInfo().buildVersion + ' , 设备id: ' + deviceId
}).width(150).height(55).margin({ top: 15 })
Text(this.deviceInfo).fontSize(14).width(300).height(55).margin({ top: 15 })
}
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
.width('100%')
.padding(20)
}.width('100%').height('100%')
// 悬浮按钮
SuspensionV2().visibility(this.shoudleShowWindow ? Visibility.Visible : Visibility.None).id('trigger_text_privacy')
.hitTestBehavior(HitTestMode.None)// 重要用于点击事件穿透,不然无法点击Web内容
.height('100%')
.width('100%').zIndex(3)
}.height('100%')
.width('100%')
}
}
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"phone",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:layered_image",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"ohos.want.action.home"
]
}
]
}
], "metadata": [ // 配置如下信息
{
"name": "client_id",
"value": "6917601767187772270" // 配置为agc中获取的Client ID
},
{
"name": "app_id",
"value": "6917601767187772270" // 配置为agc中获取的APP ID
}
],
"requestPermissions": [ // 配置网络权限
{
"name": "ohos.permission.INTERNET"
}
],
"querySchemes": [
"weixin","alipays" // 声明需要查询的scheme,检测微信是否安装,必须配置项
],
"extensionAbilities": [
{
"name": "EntryBackupAbility",
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
"type": "backup",
"exported": false,
"metadata": [
{
"name": "ohos.extension.backup",
"resource": "$profile:backup_config"
}
],
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"float": [
{
"name": "page_text_font_size",
"value": "50fp"
}
]
}
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "熊猫大作战"
}
]
}
\ No newline at end of file
{
"layered-image":
{
"background" : "$media:background",
"foreground" : "$media:foreground"
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#000000"
}
]
}
\ No newline at end of file
import { hilog } from '@kit.PerformanceAnalysisKit';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function abilityTest() {
describe('ActsAbilityTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
})
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
})
})
}
\ No newline at end of file
import abilityTest from './Ability.test';
export default function testsuite() {
abilityTest();
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"deviceTypes": [
"phone",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false
}
}
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}
\ No newline at end of file
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest', () => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}
\ No newline at end of file
{
"modelVersion": "6.0.1",
"dependencies": {
"@hadss/hmrouter-plugin": "^1.2.2"
},
"execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
// "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */
},
"logging": {
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
},
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
},
"nodeOptions": {
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
}
}
import { appTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
}
\ No newline at end of file
{
"meta": {
"stableOrder": true,
"enableUnifiedLockfile": false
},
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@aliyunsls/producer@^0.3.2": "@aliyunsls/producer@0.3.2",
"@hadss/hmrouter@1.2.2": "@hadss/hmrouter@1.2.2",
"@hadss/hmrouter@^1.2.2": "@hadss/hmrouter@1.2.2",
"@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
"@ohos/hypium@1.0.24": "@ohos/hypium@1.0.24",
"@pura/harmony-utils@1.4.0": "@pura/harmony-utils@1.4.0",
"@tencent/mmkv@2.3.0": "@tencent/mmkv@2.3.0",
"@yunkss/ef_core@1.0.2": "@yunkss/ef_core@1.0.3",
"@yunkss/ef_core@1.0.3": "@yunkss/ef_core@1.0.3",
"@yunkss/ef_json@1.0.2": "@yunkss/ef_json@1.0.2",
"@yunkss/ef_rcp@1.0.12": "@yunkss/ef_rcp@1.0.12",
"class-transformer@^0.5.1": "class-transformer@0.5.1",
"libhmrouterlibrary.so@oh_modules/.ohpm/@hadss+hmrouter@1.2.2/oh_modules/@hadss/hmrouter/src/main/cpp/types/libhmrouterlibrary": "libhmrouterlibrary.so@oh_modules/.ohpm/@hadss+hmrouter@1.2.2/oh_modules/@hadss/hmrouter/src/main/cpp/types/libhmrouterlibrary",
"libmmkv.so@oh_modules/.ohpm/@tencent+mmkv@2.3.0/oh_modules/@tencent/mmkv/src/main/cpp/types/libmmkv": "libmmkv.so@oh_modules/.ohpm/@tencent+mmkv@2.3.0/oh_modules/@tencent/mmkv/src/main/cpp/types/libmmkv",
"zwgame@0.4.2": "zwgame@0.4.2"
},
"packages": {
"@aliyunsls/producer@0.3.2": {
"name": "@aliyunsls/producer",
"version": "0.3.2",
"integrity": "sha512-x/F/iC+cx15RTyCxs/q1gtRln14vWM0+HSGWpoGvHVtgVx+5hkUroMpJ8TislNAYZP0fUHEEM+G3LmHfMWTx3g==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@aliyunsls/producer/-/producer-0.3.2.har",
"registryType": "ohpm"
},
"@hadss/hmrouter@1.2.2": {
"name": "@hadss/hmrouter",
"version": "1.2.2",
"integrity": "sha512-R+g2ku+wsBCcv6+7OP2C4HpV79nAacO0i0ubRgmzksW+oK+GqywFW87s26Dkt5sLPwRtWQl8hBC+5qOwN2mtog==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@hadss/hmrouter/-/hmrouter-1.2.2.har",
"registryType": "ohpm",
"dependencies": {
"libhmrouterlibrary.so": "file:./src/main/cpp/types/libhmrouterlibrary"
}
},
"@ohos/hamock@1.0.0": {
"name": "@ohos/hamock",
"version": "1.0.0",
"integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har",
"registryType": "ohpm"
},
"@ohos/hypium@1.0.24": {
"name": "@ohos/hypium",
"version": "1.0.24",
"integrity": "sha512-3dCqc+BAR5LqEGG2Vtzi8O3r7ci/3fYU+FWjwvUobbfko7DUnXGOccaror0yYuUhJfXzFK0aZNMGSnXaTwEnbw==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.24.har",
"registryType": "ohpm"
},
"@pura/harmony-utils@1.4.0": {
"name": "@pura/harmony-utils",
"version": "1.4.0",
"integrity": "sha512-nxEYuXZCQHY+ycjsJ3u6oHCsJMlXfYePhbTz+k0yAn6AzvqvuhbJcUpZj02CBF4ym/1jXICsDVcHKnQGoVMGaw==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@pura/harmony-utils/-/harmony-utils-1.4.0.har",
"registryType": "ohpm"
},
"@tencent/mmkv@2.3.0": {
"name": "@tencent/mmkv",
"version": "2.3.0",
"integrity": "sha512-qV9zk17+TkNp02L6fCNT8CAU25H4zJQFs42z3osnF70AcPliJlke7qlE62tTT6BO3DA94EndVBygRkN2vcTYCw==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@tencent/mmkv/-/mmkv-2.3.0.har",
"registryType": "ohpm",
"dependencies": {
"libmmkv.so": "file:./src/main/cpp/types/libmmkv"
}
},
"@yunkss/ef_core@1.0.3": {
"name": "@yunkss/ef_core",
"version": "1.0.3",
"integrity": "sha512-LNuk1Lv8XeVzkOhoDG+K64wQoD9zc5Blh9sMbsZEyjSq1qO2jqSB35NXvO560PsNl1vW+lGD4ID1jeHZav1Dtg==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@yunkss/ef_core/-/ef_core-1.0.3.har",
"registryType": "ohpm"
},
"@yunkss/ef_json@1.0.2": {
"name": "@yunkss/ef_json",
"version": "1.0.2",
"integrity": "sha512-jD3n7geoooT4mKLXqu52/c1cF5VN4HAB61sqhbiOpnWndSZZcQHPhlqUZG91DXN5fmoRE4oGZLx/DjVhY3Y77Q==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@yunkss/ef_json/-/ef_json-1.0.2.har",
"registryType": "ohpm",
"dependencies": {
"@yunkss/ef_core": "1.0.2"
}
},
"@yunkss/ef_rcp@1.0.12": {
"name": "@yunkss/ef_rcp",
"version": "1.0.12",
"integrity": "sha512-OZ7zoi3LCwlV/34vIG1I2kLT31FXlbw4283LK/PWorM3qF6buimr6dHO9n6t+Gh5E4sFV+Jz+yCWvbtvatOM3Q==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@yunkss/ef_rcp/-/ef_rcp-1.0.12.har",
"registryType": "ohpm",
"dependencies": {
"@yunkss/ef_json": "1.0.2",
"@yunkss/ef_core": "1.0.3",
"class-transformer": "^0.5.1"
}
},
"class-transformer@0.5.1": {
"name": "class-transformer",
"version": "0.5.1",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==",
"resolved": "https://ohpm.openharmony.cn/ohpm/class-transformer/-/class-transformer-0.5.1.tgz",
"shasum": "24147d5dffd2a6cea930a3250a677addf96ab336",
"registryType": "ohpm"
},
"libhmrouterlibrary.so@oh_modules/.ohpm/@hadss+hmrouter@1.2.2/oh_modules/@hadss/hmrouter/src/main/cpp/types/libhmrouterlibrary": {
"name": "libhmrouterlibrary.so",
"version": "1.0.0",
"resolved": "oh_modules/.ohpm/@hadss+hmrouter@1.2.2/oh_modules/@hadss/hmrouter/src/main/cpp/types/libhmrouterlibrary",
"registryType": "local"
},
"libmmkv.so@oh_modules/.ohpm/@tencent+mmkv@2.3.0/oh_modules/@tencent/mmkv/src/main/cpp/types/libmmkv": {
"name": "libmmkv.so",
"version": "0.0.0",
"resolved": "oh_modules/.ohpm/@tencent+mmkv@2.3.0/oh_modules/@tencent/mmkv/src/main/cpp/types/libmmkv",
"registryType": "local"
},
"zwgame@0.4.2": {
"name": "zwgame",
"version": "0.4.2",
"integrity": "sha512-bFLuJuT8Uq/KE4/nsAmyQRCs0jHlCeDupIv9kEgeK2eWQ+PiAkPSNsePVVzpLLyhtISTUDC+KaGaiNdap1PNaQ==",
"resolved": "http://8.149.138.39:9099/repos/ohpm/zwgame/-/zwgame-0.4.2.har",
"registryType": "ohpm",
"dependencies": {
"@pura/harmony-utils": "1.4.0",
"@yunkss/ef_rcp": "1.0.12",
"@hadss/hmrouter": "1.2.2",
"@tencent/mmkv": "2.3.0",
"@aliyunsls/producer": "^0.3.2"
}
}
}
}
\ No newline at end of file
{
"modelVersion": "6.0.1",
"description": "Please describe the basic information.",
"dependencies": {
"zwgame": "0.4.2",
"@hadss/hmrouter": "^1.2.2"
},
"devDependencies": {
"@ohos/hypium": "1.0.24",
"@ohos/hamock": "1.0.0"
},
"dynamicDependencies": {}
}
\ No newline at end of file
-----BEGIN NEW CERTIFICATE REQUEST-----
MIIBOTCB4AIBADBOMQkwBwYDVQQGEwAxCTAHBgNVBAgTADEJMAcGA1UEBxMAMQkw
BwYDVQQKEwAxCTAHBgNVBAsTADEVMBMGA1UEAxMMeG1kenpoYXJtb255MFkwEwYH
KoZIzj0CAQYIKoZIzj0DAQcDQgAEzL3/0gvZuctv//o7qxEZog4nMzbdI/6HbIT/
BDgDLmFW6k77iDVTA/y4v5ky4i9lnm9eJvotA0CqY3x+zN7JRqAwMC4GCSqGSIb3
DQEJDjEhMB8wHQYDVR0OBBYEFHvmBjB9nH7NY73VRoO0tXuLBO/OMAoGCCqGSM49
BAMDA0gAMEUCIQDG+SyscSsxJsCyQoYFKb7wEjIoSMeczTG9e5+0OYhzMAIgRG1I
GKupAgjipZo2VjUDK7at/4+BLZozrbD9NGRDSvs=
-----END NEW CERTIFICATE REQUEST-----
-----BEGIN CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIICGjCCAaGgAwIBAgIIShhpn519jNAwCgYIKoZIzj0EAwMwUzELMAkGA1UEBhMC
Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEeMBwGA1UE
AwwVSHVhd2VpIENCRyBSb290IENBIEcyMB4XDTIwMDMxNjAzMDQzOVoXDTQ5MDMx
NjAzMDQzOVowUzELMAkGA1UEBhMCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UE
CwwKSHVhd2VpIENCRzEeMBwGA1UEAwwVSHVhd2VpIENCRyBSb290IENBIEcyMHYw
EAYHKoZIzj0CAQYFK4EEACIDYgAEWidkGnDSOw3/HE2y2GHl+fpWBIa5S+IlnNrs
GUvwC1I2QWvtqCHWmwFlFK95zKXiM8s9yV3VVXh7ivN8ZJO3SC5N1TCrvB2lpHMB
wcz4DA0kgHCMm/wDec6kOHx1xvCRo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0T
AQH/BAUwAwEB/zAdBgNVHQ4EFgQUo45a9Vq8cYwqaiVyfkiS4pLcIAAwCgYIKoZI
zj0EAwMDZwAwZAIwMypeB7P0IbY7c6gpWcClhRznOJFj8uavrNu2PIoz9KIqr3jn
BlBHJs0myI7ntYpEAjBbm8eDMZY5zq5iMZUC6H7UzYSix4Uy1YlsLVV738PtKP9h
FTjgDHctXJlC5L7+ZDY=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIDATCCAoigAwIBAgIIXmuDXbWpOB8wCgYIKoZIzj0EAwMwUzELMAkGA1UEBhMC
Q04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEeMBwGA1UE
AwwVSHVhd2VpIENCRyBSb290IENBIEcyMB4XDTIwMDcwOTAyMDQyNFoXDTMwMDcw
NzAyMDQyNFowYjELMAkGA1UEBgwCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UE
CwwKSHVhd2VpIENCRzEtMCsGA1UEAwwkSHVhd2VpIENCRyBEZXZlbG9wZXIgUmVs
YXRpb25zIENBIEcyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE65LdoIZh1hlpZ2gP
bJ6gPhHsvYSRe22KETgdqeVeYnrbRHI9wsPT6RGYS+pU4mPl6wxzgDMqN6SY/BoZ
luhkE1PzaHoPoNIWIq0O33hpyKyyYwAacIUEjYurkw1E9r9no4IBGDCCARQwHwYD
VR0jBBgwFoAUo45a9Vq8cYwqaiVyfkiS4pLcIAAwHQYDVR0OBBYEFNtek7Ij6NDk
/nF6Zumkc0dbf/NeMEYGA1UdIAQ/MD0wOwYEVR0gADAzMDEGCCsGAQUFBwIBFiVo
dHRwOi8vY3BraS1jYXdlYi5odWF3ZWkuY29tL2Nwa2kvY3BzMBIGA1UdEwEB/wQI
MAYBAf8CAQAwDgYDVR0PAQH/BAQDAgEGMGYGA1UdHwRfMF0wW6BZoFeGVWh0dHA6
Ly9jcGtpLWNhd2ViLmh1YXdlaS5jb20vY3BraS9zZXJ2bGV0L2NybEZpbGVEb3du
LmNybD9jZXJ0eXBlPTEwJi9yb290X2cyX2NybC5jcmwwCgYIKoZIzj0EAwMDZwAw
ZAIwWO1X5q2MdfpR1Q237GpUHGbL1C13rGyFg2p3AYo44FpZ2/A9ss0wOHKM4KDl
ZPqdAjBLkf8NPZy7KVog98+iCTLq35DJ2ZVxkCxknA9YhiHVyXf4HPm4JlT7rW7o
Q+FzM3c=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIC+zCCAoKgAwIBAgIOCf05J77v1HqxNMSNg9gwCgYIKoZIzj0EAwMwYjELMAkG
A1UEBgwCQ04xDzANBgNVBAoMBkh1YXdlaTETMBEGA1UECwwKSHVhd2VpIENCRzEt
MCsGA1UEAwwkSHVhd2VpIENCRyBEZXZlbG9wZXIgUmVsYXRpb25zIENBIEcyMB4X
DTI2MDQxMDAyNDQzMVoXDTI2MTAwNzAyNDQzMVowgasxCzAJBgNVBAYTAkNOMS0w
KwYDVQQKDCTmna3lt57ovbvlr5Lkv6Hmga/mioDmnK/mnInpmZDlhazlj7gxHDAa
BgNVBAsMEzE5MjUzMzM3NzMzNzM2NzY1NDUxTzBNBgNVBAMMRuadreW3nui9u+Wv
kuS/oeaBr+aKgOacr+aciemZkOWFrOWPuCgxOTI1MzMzNzczMzczNjc2NTQ1KVws
RGV2ZWxvcG1lbnQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATMvf/SC9m5y2//
+jurERmiDiczNt0j/odshP8EOAMuYVbqTvuINVMD/Li/mTLiL2Web14m+i0DQKpj
fH7M3slGo4HRMIHOMB0GA1UdDgQWBBR75gYwfZx+zWO91UaDtLV7iwTvzjAMBgNV
HRMBAf8EAjAAMB8GA1UdIwQYMBaAFNtek7Ij6NDk/nF6Zumkc0dbf/NeMFkGA1Ud
HwRSMFAwTqBMoEqGSGh0dHA6Ly9oNWhvc3RpbmctZHJjbi5kYmFua2Nkbi5jbi9j
Y2g1L2NybC9oZHJjYWcyL0h1YXdlaUNCR0hEUkcyY3JsLmNybDAOBgNVHQ8BAf8E
BAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwCgYIKoZIzj0EAwMDZwAwZAIwc9mx
mbn/0ey7Burjt3PBYdVF6KmIzHowUk/Z8NU8UWgLup/r+tfhK/JGGV2sw1WqAjBj
eB5eKJ34cMlU42AJx7E8AICzKO5W82Rbpbmw7eLjhg0gwWL7LA9umv6l4qEA9nM=
-----END CERTIFICATE-----
# 国内游戏鸿蒙客户端sdk对接文档
# 国内游戏鸿蒙客户端sdk对接文档
# 一.sdk概述
此sdk为鸿蒙版本,此sdk兼容的最低版本 api 版本为 12(鸿蒙5.0)
# 1.主要功能:
1.游戏登录
2.游戏支付
3.游戏角色上报
# 2.接入准备:
正式接入前请务必阅读掌玩SDK接入流程的介绍,并且在掌玩SDK平台获取游戏id(game_id),游戏包名(packageName),此参数将由掌玩游戏对接技术或产品对接,对接时由平台方提供game_id,packageName字段信息,请严格阅读对接时平台对接人员提供参数文档
| 名称 | 说明 | |
| ----------- | -------------- | --- |
| game_id | 游戏在平台的唯一标识 | |
| packageName | 游戏在用户设备安装的唯一标识 | |
| game_secret | 平台方提供,游戏签名密钥 | |
| appStatus | 用户在平台登录的投放媒体标识 | |
# 二.快速集成
1. 在devecostudio里项目工程目录执行如下命令:
``
ohpm config set registry  "http://8.149.138.39:9099/repos/ohpm,https://ohpm.openharmony.cn/ohpm"
``
2.在devecostudio里项目工程目录执行如下命令:
``
ohpm install zwgame@0.3.7
``
备注:0.3.7是har的版本号,按实际情况调整
3.在工程entry模块下module.json5里加入如下配置:
![](1.png)
4.在工程hvigor/hvigor-config.json5下加入以下依赖:`"@hadss/hmrouter-plugin": "^1.2.2" // 使用npm仓版本号`,来保证可以正确跳转页面,在工程根目录执行 `ohpm install @hadss/hmrouter`
![](2.png)
5.在工程entry/hvigorfile.ets文件里加入以下配置,并同步工程:
![](3.png)
# 三.sdk使用方式
1.宿主app的工程里,EntryAbility的onCreate()方法里加入如下代码:
`` SDKToolsManager.getInstance().firstInitBeforePrivacy(this.context as common.UIAbilityContext)
``
2.宿主app的工程里,EntryAbility的onWindowStageCreate()方法里加入如下代码:
``
SDKToolsManager.getInstance().initSDK(windowStage,'深海花园游戏账号登录',$r('app.media.ic_float'),this.context,{
getPrivacyCallBack: (data: boolean): void => {
if (data) {
// 值为true代表同意
LogUtil.info('zfcs', '用户点击了隐私弹框的同意按钮')
}
}
})
``
其中必传的四个参数,windowStage 对应window.WindowStage;thirdInfo: 三方账号信息名称;customerIcon: 三方游戏icon;context 对应 common.UIAbilityContext
3.宿主app的工程里,EntryAbility的onWindowStageDestory()方法里加入如下代码:
``
SDKToolsManager.getInstance().onWindowStageDestroy()
``
4.宿主app的工程里,EntryAbility的onBackground()方法里加入如下代码:
``
SDKToolsManager.getInstance().onBackground()
``
5.宿主app的工程里,EntryAbility的onForeground()方法里加入如下代码:
``
SDKToolsManager.getInstance().onForeground()
``
6.宿主app的工程里,首页 Index 页面是个过渡页面,按照demo代码来写即可(备注:“SeondMainPage”就是对应的游戏页面,替换为对应的游戏页面即可,其他不必调整)。并且 aboutToAppear()方法里加入如下代码,给游戏sdk注入掌玩SDK平台获取游戏id`gameId `、游戏包名`packName`、游戏工程的版本号`versionCode`、页面横竖屏字段(0:横屏;1:竖屏)、`appStatus`(0默认SDK,1表示巨量AD,2表示快手,3表示腾讯)、宿主的上下文环境, 展示游戏的背景图,种花游戏需设置为true(true:展示;false:不展示)
``
SDKToolsManager.getInstance().aboutToAppear('20248','com.xmdzzharmony.huawei','1.0.0',1,'1',this.getUIContext(), true)
``
7.sdk登录的方法:
其中:SDKToolsManager.getInstance() 为获取当前工具的单例对象;showSdkLogin()的对应的参数依次为:当前宿主的上下文、华为联合登陆面板展示的游戏登录的标题内容、游戏图标(图标大小不能超过35KB)、是否显示悬浮球的状态回调接口(true:显示悬浮球;false:不显示悬浮球)、关闭华为联合登录面板的回调接口(1002000016是统一错误码,代表关闭了华为联合登录面板)
````
SDKToolsManager.getInstance()
.showSdkLogin(this.getUIContext(), '深海花园游戏账号登录', $r('app.media.ic_float'), {
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
}
}, {
onPanelClosed: (code: number, reason: string): void => {
if (code == 1002000016) {
// 用户关闭了登录面板
LogUtil.info('test', '用户关闭了联合登录面板')
}
} })
````
8.sdk退出登录:
该方法的入参为:是否显示悬浮球的接口回调,其中isShowFloatBall:false代表不显示悬浮球
``
AppUtils.outLogin({
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
}
})
``
9.拉起支付的方法:
``
let jsonStr = '{"role":{"event":"other","server_id":"1","role_name":"主宰传奇","cp_role_id":"2","server_name":"主宰服","role_level":"83","role_vip":"0"},"order":{"cp_order_id":"1770709001026","amount":"100","product_price":"100","product_id":"com.product.test02","product_cnt":"1","product_name":"1元档充值","product_desc":"商品","ext":"测试数据"}}'
``
``
AppUtils.createOrderWithHuaWei(jsonStr, '1', '2', this.amount,this.product_price,this.product_cnt,'com.product.test02',
{
Success: (msg: Object): void => {
LogUtil.info('zfcs 支付成功: ' + msg.toString())
},
Failed: (msg: string): void => {
LogUtil.info('zfcs 支付失败: ' + msg.toString())
}
})
``
其中:createOrderWithHuaWei()方法里参数依次为:要传入的支付信息的json字符串(jsonStr)、server_id(区服Id)、cp角色Id(cp_role_id)、商品总价、商品单价、商品数量、商品Id(product_id)、支付结果回调:Success代表支付成功回调,Failed代表支付失败回调
> 下单支付字段说明
| 名称 | 类型 | 是否必须 | 默认值|说明 |
|:--------------|-------:|-----:|-----:|-----------------:|
| cp_order_id | string | 必须 || CP订单ID |
| amount | number | 必须 | |商品总价(单位:分 |
| product_price | number | 必须 | |商品价格(整数,后台自动换算分) |
| product_id | String | 必须 |0| 商品ID |
| product_cnt | number | 必须 | |商品数量 |
| product_name | string | 必须 |""| 商品名称 |
| product_desc | string | 非必须 |""| 商品描述 |
| ext | string | 必须 |""| 订 调用方定义 单额外信息用(json)|
| event | string | 必须 |""| 事件|
| server_id | string | 必须 |0| 区服id |
| server_name | string | 必须 |""| 区服名称|
| cp_role_id | string | 必须 | cp角色id |
| role_name | string | 必须 | ""|角色名称 |
| role_level | string | 必须 |0| 角色等级 |
| role_vip | string | 必须 | 0|角色vip等级 |
| role_id | string | 必须 |0| 角色ID |
10.角色上报的方法:
``
const jsonStr = '{"cp_account":"cp_account","role":{"event":"create","server_id":"serviceId","server_name":"server_name","cp_role_id":"cpRoleId","role_name":"role_name","role_level":"role_level","role_vip":"role_vip","combat_num":"combatnum","online_time":"online_time","reiki_num":"reikinum","attack":"attack","profession":"profession","gang_name":"gang_name","trans_level":"translevel","sponsor_level":"sponsorlevel","main_city_level":"maincitylevel","power":"power","chapter_index":"chapterindex"}}'
``
``
AppUtils.onRole('serviceId', 'cpRoleId', jsonStr);
``
参数说明
> | 参数 | 必选 | 类型 | 默认值 | 说明 |
> | :---------------------------------------------------------- | :---- | :----- | :----- | :----------- |
> | event | true | String | other | 事件类型 |
> | server_id | true | String | - | 区服ID |
> | server_name | true | String | - | 区服名称 |
> | cp_role_id | true | String | - | 游戏方角色ID |
> | role_name | true | String | - | 游戏角色名称 |
> | role_level | true | Int | - | 角色等级 |
> | cp_account | false | String | - | cp账号 |
> | role_vip | false | Int | 0 | 角色VIP等级(赞助等级) |
> | combat_num | false | String | "0" | 角色战力 |
> | reiki_num | false | Int | 0 | 角色灵符值 |
> | online_time | false | Int | 0 | 本次在线时长 |
> | attack | false | Int | 0 | 攻击力 |
> | profession | false | String | - | 职业 |
> | gang_name | false | String | - | 帮会(行会)名称 |
> | trans_level | false | Int | 0 | 转生等级 |
>
>
事件类型event
| EVENT | 说明 |
| -------- | -------- |
| create | 创建角色 |
| online | 角色上线 |
| offline | 角色下线 |
| level_up | 角色升级 |
| delete | 删除角色 |
| recharge | 角色充值 |
| other | 其他 |
11.悬浮按钮的集成方法:宿主app页面的build()根节点必须为stack,加入如下代码,可见性由sdk暴露标记值,需宿主app接收该标记:
``
SuspensionV2().visibility(this.shoudleShowWindow ? Visibility.Visible : Visibility.None).id('trigger_text_privacy')
.hitTestBehavior(HitTestMode.None)
.height('100%')
.width('100%')
``
12.获取player_id的方法:
``
UserSDKManager.getInstance().getUserLoginInfo()
``
这个方法获取本地的缓存的数据,里面有player_id这个字段,遍历取'player_id'对应的值就可以拿到
13.服务端接口 调用方直接使用http 调用接口:<a name="sec5">
### 接口地址
> 【POST】 /ohos_sdk/auth/checkLogin
##### 请求参数
> **Headers**:
>
> | 参数 | 必选 | 参数值 | 说明 |
> | ------------ | ---- | ---------------- | ----------------------------------- |
> | Content-Type | true | application/json | |
> | User-Token | true | | 登录后由 SDK 返回的user_token |
> **Body**:
>
> | 参数 | 必选 | 类型 | 默认值 | 说明 |
> | --------- | ---- | ------ | ------ | --------------------------------- |
> | game_id | true | Int | - | 游戏接入时分配的游戏ID(建议从user_token中取,#后面的数字即为game_id)|
> | player_id | true | Int | - | 游戏登录后由 SDK 返回的player_id |
> | sign | true | String | - | 参数签名 |
##### 返回参数
> | 参数 | 必选 | 类型 | 默认值 | 说明 |
> | ----------- | ----- | ------ | ------ | -------------- |
> | status_code | true | Int | - | 状态码 1 正常在线,否则不允许登录|
> | msg | true | STRING | - | 返回信息 |
> | data | false | OBJECT | [] | 返回数据(空) |
>
##### 接口说明
调用方检测当前用户是否登录过,在线状态; 如果返回参数不是正常登录则不允许登录游戏。
##### 请求示例
```php
<php?
public function checkLogin(){
$host = 'https://zyouapi.wozhangwan.com';
$checkLoginUrl = '/ohos_sdk/auth/checkLogin';
$url = $host.$checkLoginUrl;
$gameSecret = "game_secret";
$body = ["player_id" => 1245, "game_id" => 14];
$userToken = "user_token";
$body["sign"] = makeSign($body, $gameSecret);
$headers = ["Content-Type:application/json","User-Token:".$userToken];
$response = curl_post($url, $body, $hearders);
}
public function makeSign($params,$gameSecret){
$signStr = '';
ksort($params, SORT_REGULAR);
foreach ($params as $key => $val) {
if (is_array($val)) {
ksort($val, SORT_REGULAR);
$val = json_encode($val, JSON_UNESCAPED_UNICODE);
}
$signStr .= $key . '=' . $val . '&';
}
$signStr .= 'game_secret=' . $gameSecret;
return md5($signStr);
}
public function curl_post($url, $body, $headers){
//初始化
$curl = curl_init ( );
//设置抓取的url
curl_setopt ( $curl, CURLOPT_URL , $url);
//设置头文件的信息作为数据流输出
curl_setopt ( $curl, CURLOPT_HEADER , 1 );
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER , 1 );
//设置post方式提交
curl_setopt ( $curl, CURLOPT_POST , 1 );
//设置post参数
curl_setopt ( $curl, CURLOPT_POSTFIELDS , json_encode($body) );
//设置请求头
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//执行命令
$data = curl_exec ( $curl );
//关闭URL请求
curl_close ( $curl );
//显示获得的数据
return json_decode($data, true);
}
```
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论