提交 f1adf7f7 作者: 刘添

合并分支 'sdk_doc_demo' 到 'master'

添加demo和文档

查看合并请求 zwwl/zw_game_sdk!289
......@@ -31,7 +31,6 @@ export default class EntryAbility extends UIAbility {
return;
}
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
// 其中第二个参数为华为联合登陆面板展示的游戏登录的标题内容;第三个参数为游戏图标路径(华为平台要求图标大小一定不能超过35KB)
setTimeout(()=>{
SDKToolsManager.getInstance().initSDK(windowStage,'深海花园游戏账号登录',$r('app.media.ic_float'),this.context, {
getPrivacyCallBack: (data: boolean): void => {
......@@ -42,7 +41,7 @@ export default class EntryAbility extends UIAbility {
}
}, {
sdkCodeCallback: (code: number): void => {
// code=1 :修改密码;code = 2:退出登录;3:切换账号
// code=1 :修改密码;code = 2:退出登录;3:切换账号;4:账号登录异常
LogUtil.info('zfcs ','sdkCodeCallback: ' + code)
}
})
......
......@@ -6,10 +6,16 @@ import {
SDKToolsManager,
AppUtil,
LogUtil,
NetWorkAdManager,
AdsKitManager,
} from 'zwgame';
import { window } from '@kit.ArkUI';
import { DeviceInfoUtils } from 'zwgame/src/main/ets/utils/DeviceInfoUtils';
import { DeviceIdSdkUtil } from 'zwgame/src/main/ets/utils/DeviceIdSdkUtil';
import { UserSDKManager } from 'zwgame/src/main/ets/manager/UserSDKManager';
import { common } from '@kit.AbilityKit';
@Entry
@HMRouter({ pageUrl: 'SecondMainPage', singleton: true })
......@@ -25,8 +31,35 @@ export struct SecondMainPage {
@Local amount:string = ''
@Local product_price:string = ''
@Local product_cnt:string = ''
@Local loginInfo:string = '熊猫大作战游戏账号登录'
@Local loginInfo:string = '深海花园游戏账号登录'
async aboutToAppear(): Promise<void> {
// 获取当前窗口并设置横屏
try {
const win = await window.getLastWindow(getContext(this));
// 关键:将页面设置为横屏
await win.setPreferredOrientation(window.Orientation.PORTRAIT);
} catch (err) {
console.error('设置横屏失败: ' + JSON.stringify(err));
}
// let thirdAccountInfo1: gamePlayer.ThirdAccountInfo = {
// 'accountName': '深海花园游戏账号登录' , // 可以修改为自定义名称
// 'accountIcon': $r('app.media.ic_float') // 确保图标存在
// };
// let request: gamePlayer.UnionLoginParam = {
// showLoginDialog: true, // 是否弹出联合登录面板。true表示强制弹出面板,false表示优先使用玩家上一次的登录选择,不弹出联合登录面板,若玩家首次登录或卸载重装,则正常弹出
// thirdAccountInfos: [
// thirdAccountInfo1 // 若游戏无官包或无官方账号体系,请传空数组
// ],
// loginPanelType: gamePlayer.LoginPanelType.BUTTON
// };
// SDKToolsManager.getInstance().setRequest(request)
// 初始化日志打印悬浮框入口,release包不显示
// AppLog.getAppLog().showLog(() => {
// //AppLog.getAppLog().hideLog()
// this.getUIContext().getRouter().back()
// })
}
build() {
......@@ -38,23 +71,48 @@ export struct SecondMainPage {
.showSdkLogin(this.getUIContext(), '熊猫大作战游戏账号登录', $r('app.media.ic_float'), {
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
const info = UserSDKManager.getInstance().getUserLoginInfo()
LogUtil.info('zfcs 登录成功: ' + this.shoudleShowWindow +', '+ info )
}
}, {
onPanelClosed: (code: number, reason: string): void => {
if (code == 1002000016) {
// 用户关闭了登录面板
LogUtil.info('test', '用户关闭了联合登录面板')
}
LogUtil.info('test', '用户关闭了联合登录面板code: ' + code)
}
})
}).width(150).height(55).margin({ top: 15 })
Button('sdk退出登录').onClick(() => {
AppUtils.outLogin({
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
Button('展示广告').onClick(() => {
NetWorkAdManager.getInstance().getAdvertiser(this.getUIContext().getHostContext() as common.UIAbilityContext, '333333',
{
onAdSubscribeFail: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdPlayFailed: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdPlayReward: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdOpen: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdClick: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdClose: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdPlayBegin: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdPlayEnd: (info: string): void => {
LogUtil.info('zfcs', info);
},
onAdDataEmpty:(info: string): void => {
LogUtil.info('zfcs', info);
}
})
})
// AdsKitManager.getInstance().loadAds(this.getUIContext().getHostContext() as common.UIAbilityContext)
}).width(150).height(55).margin({ top: 15 })
Row(){
TextInput({text: this.amount,placeholder:'请输入总金额'}).onChange((value:string)=>{
......@@ -68,17 +126,25 @@ export struct SecondMainPage {
}).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',
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.test03","product_cnt":"1","product_name":"1元档充值","product_desc":"商品","ext":"测试数据"}}'
AppUtils.createOrderWithHuaWei(jsonStr, '1', '2', this.amount,this.product_price,this.product_cnt,'com.product.test03',
{
Success: (msg: Object): void => {
LogUtil.info('test 支付成功: ' + msg.toString())
LogUtil.info('zfcs 支付成功: ' + msg.toString())
},
Failed: (msg: string): void => {
LogUtil.info('test 支付失败: ' + msg.toString())
LogUtil.info('zfcs 支付失败: ' + msg.toString())
}
})
}).width(150).height(55).margin({ top: 15 })
Button('sdk手动支付').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":"101","product_cnt":"1","product_name":"1元档充值","product_desc":"商品","ext":"测试数据"}}'
AppUtils.createOrderV2(jsonStr, '1', '2', this.amount,this.product_price,this.product_cnt)
}).width(150).height(55).margin({ top: 15 })
Button('sdk支付').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":"101","product_cnt":"1","product_name":"1元档充值","product_desc":"商品","ext":"测试数据"}}'
AppUtils.createOrder(jsonStr, '1', '2')
}).width(150).height(55).margin({ top: 15 })
Button(this.shoudleShowWindow ? '隐藏悬浮框' : '显示悬浮框').onClick(() => {
this.shoudleShowWindow = !this.shoudleShowWindow
}).width(150).height(55).margin({ top: 15 })
......@@ -97,7 +163,7 @@ export struct SecondMainPage {
}).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
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 })
}
......@@ -112,10 +178,13 @@ export struct SecondMainPage {
SuspensionV2().visibility(this.shoudleShowWindow ? Visibility.Visible : Visibility.None).id('trigger_text_privacy')
.hitTestBehavior(HitTestMode.None)// 重要用于点击事件穿透,不然无法点击Web内容
.height('100%')
.width('100%').zIndex(3)
.width('100%').zIndex(100)
}.height('100%')
.width('100%')
}
aboutToDisappear(): void {
DialogManagerService.getInstance().closePaymentDialog();
}
}
......@@ -2,7 +2,7 @@
"modelVersion": "6.0.1",
"description": "Please describe the basic information.",
"dependencies": {
"zwgame": "0.4.2",
"zwgame": "0.6.0",
"@hadss/hmrouter": "^1.2.2"
},
"devDependencies": {
......
# 国内游戏鸿蒙客户端sdk对接文档
# 国内游戏鸿蒙客户端sdk对接文档
......@@ -34,9 +34,9 @@ ohpm config set registry  "http://8.149.138.39:9099/repos/ohpm,https://ohpm.ope
2.在devecostudio里项目工程目录执行如下命令:
``
ohpm install zwgame@0.3.7
ohpm install zwgame@0.6.0
``
备注:0.3.7是har的版本号,按实际情况调整
备注:0.6.0是har的版本号,按实际情况调整
3.在工程entry模块下module.json5里加入如下配置:
......@@ -68,7 +68,7 @@ setTimeout(()=>{
}
} }, {
sdkCodeCallback: (code: number): void => {
// code=1 :修改密码;code = 2:退出登录;3:切换账号
// code=1 :修改密码;code = 2:退出登录;3:切换账号 ;4:账号登录异常
LogUtil.info('zfcs ','sdkCodeCallback: ' + code)
}
})
......@@ -117,17 +117,7 @@ SDKToolsManager.getInstance()
} })
```
8.sdk退出登录:
该方法的入参为:是否显示悬浮球的接口回调,其中isShowFloatBall:false代表不显示悬浮球
``
AppUtils.outLogin({
getBooleanData: (isShowFloatBall: boolean): void => {
this.shoudleShowWindow = isShowFloatBall
}
})
``
9.拉起支付的方法:
8.拉起支付的方法:
``
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":"测试数据"}}'
......@@ -166,7 +156,9 @@ AppUtils.createOrderWithHuaWei(jsonStr, '1', '2', this.amount,this.product_price
| role_level | string | 必须 | 0 | 角色等级 |
| role_vip | string | 必须 | 0 | 角色vip等级 |
| role_id | string | 必须 | 0 | 角色ID |
| 10.角色上报的方法: | | | | |
| | | | | |
9.角色上报的方法:
``
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"}}'
......@@ -208,7 +200,7 @@ AppUtils.onRole('serviceId', 'cpRoleId', jsonStr);
| recharge | 角色充值 |
| other | 其他 |
11.悬浮按钮的集成方法:宿主app页面的build()根节点必须为stack,加入如下代码,可见性由sdk暴露标记值,需宿主app接收该标记:
10.悬浮按钮的集成方法:宿主app页面的build()根节点必须为stack,加入如下代码,可见性由sdk暴露标记值,需宿主app接收该标记:
``
SuspensionV2().visibility(this.shoudleShowWindow ? Visibility.Visible : Visibility.None).id('trigger_text_privacy')
.hitTestBehavior(HitTestMode.None)
......@@ -216,13 +208,13 @@ SuspensionV2().visibility(this.shoudleShowWindow ? Visibility.Visible : Visibili
.width('100%')
``
12.获取player_id的方法:
11.获取player_id的方法:
``
UserSDKManager.getInstance().getUserLoginInfo()
``
这个方法获取本地的缓存的数据,里面有player_id这个字段,遍历取'player_id'对应的值就可以拿到
13.服务端接口 调用方直接使用http 调用接口:<a name="sec5">
12.服务端接口 调用方直接使用http 调用接口:<a name="sec5">
### 接口地址
......@@ -311,10 +303,9 @@ UserSDKManager.getInstance().getUserLoginInfo()
}
```
14、拉起广告
````
13、拉起广告
```
NetWorkAdManager.getInstance().getAdvertiser(this.getUIContext().getHostContext() as common.UIAbilityContext, '333333',
{
onAdSubscribeFail: (info: string): void => {
......@@ -342,8 +333,7 @@ onAdPlayEnd: (info: string): void => {
LogUtil.info('zfcs', info);
}
})
````
```
备注:第一个参数是context(应用的上下文),第二个参数是:广告的场景Id,第三个是数据的状态回调。
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论