|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-31 10:45:44
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-04-08 17:33:14
|
|
|
+ * @LastEditTime: 2025-04-09 14:33:13
|
|
|
* @Description: CocosHandler 处理类负责与安卓交互
|
|
|
*/
|
|
|
import { native } from 'cc';
|
|
|
@@ -41,27 +41,6 @@ export class CocosHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //微信登录
|
|
|
- async wechat_login() {
|
|
|
- const param = {
|
|
|
- "appId": "wx1234567890", //这个ID没申请下来
|
|
|
- "callback":
|
|
|
- {
|
|
|
- "onSuccess": "CocosHandler.inst.wechat_login_success",
|
|
|
- "onFaile": "CocosHandler.inst.wechat_login_fail"
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const data: CocosHandlerType = {
|
|
|
- method: "auth.wechat",
|
|
|
- param: JSON.stringify(param)
|
|
|
- }
|
|
|
-
|
|
|
- let result = await this.sendMessageToAndroid(data);
|
|
|
- console.log("微信登录结果>>>>>>>>>>", result);
|
|
|
- // smc.account.AccountModel.
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
//获取隐私授权状态
|
|
|
async getPrivacyStatus() {
|
|
|
@@ -90,8 +69,7 @@ export class CocosHandler {
|
|
|
|
|
|
//打开隐私协议或者用户协议
|
|
|
openAgreement() {
|
|
|
- const type = smc.account.AccountModel.ProtocolType;
|
|
|
- console.log(">>>>>协议类型>>>>>>>>>>>>>>>>>>", type)
|
|
|
+ const type = smc.account.AccountModel.protocolType;
|
|
|
const param = {
|
|
|
"url": type == 1 ? oops.config.game.gamePrivacyUrl : oops.config.game.gameProtocolUrl
|
|
|
}
|
|
|
@@ -102,40 +80,131 @@ export class CocosHandler {
|
|
|
this.sendMessageToAndroid(data);
|
|
|
}
|
|
|
|
|
|
- //方法請求
|
|
|
- async methodRequest(type: number) {
|
|
|
|
|
|
- let param = {};
|
|
|
|
|
|
- switch (type) {
|
|
|
- case 1:
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- break;
|
|
|
+ //微信登录
|
|
|
+ async wechat_login() {
|
|
|
+ const param = {
|
|
|
+ "callback":
|
|
|
+ {
|
|
|
+ "onSuccess": "CocosHandler.inst.wechat_login_success",
|
|
|
+ "onFaile": "CocosHandler.inst.wechat_login_fail"
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ const data: CocosHandlerType = {
|
|
|
+ method: "auth.wechat",
|
|
|
+ param: JSON.stringify(param)
|
|
|
}
|
|
|
+ this.sendMessageToAndroid(data);
|
|
|
+ }
|
|
|
|
|
|
- param = {
|
|
|
- "url": "",
|
|
|
- "callback":
|
|
|
- {
|
|
|
- "onSuccess": "CocosHandler.inst.methodRequest_success",
|
|
|
- "onFaile": "CocosHandler.inst.methodRequest_fail"
|
|
|
- },
|
|
|
- " param": {
|
|
|
+
|
|
|
+ //微信登录成功回调
|
|
|
+ wechat_login_success(str: string) {
|
|
|
+ console.log("微信登录成功回调", str);
|
|
|
+ //保存数据
|
|
|
+ // oops.message.dispatchEvent(GameEvent.WechatLoginSuss);
|
|
|
+ // 获取用户信息
|
|
|
+ //然后就是和服务器通信
|
|
|
+ this.wx_login(str);
|
|
|
+ }
|
|
|
+
|
|
|
+ //微信登录失败回调
|
|
|
+ wechat_login_fail(str: string) {
|
|
|
+ console.log("微信登录失败回调", str);
|
|
|
+ oops.gui.toast("微信登录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //==================跟服务器交互======================
|
|
|
+ //微信登录
|
|
|
+ async wx_login(code: string) {
|
|
|
+ const param = {
|
|
|
+ "code": code,
|
|
|
+ "url": ProtocolEvent.WechatLogin
|
|
|
+ }
|
|
|
+
|
|
|
+ const data: CocosHandlerType = {
|
|
|
+ method: "request.post",
|
|
|
+ param: JSON.stringify(param)
|
|
|
+ }
|
|
|
+
|
|
|
+ let result = await this.sendMessageToAndroid(data);
|
|
|
+ console.log("微信登录结果", result);
|
|
|
+ if (result.data) {
|
|
|
+ smc.account.AccountModel.setWechatInfo(result.data);
|
|
|
+ //然后登录获取用户信息
|
|
|
+ this.getAccountInfo();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ //获取账号信息
|
|
|
+ getAccountInfo() {
|
|
|
+ const param = {
|
|
|
+ "url": ProtocolEvent.AccountInfo,
|
|
|
+ "callback": {
|
|
|
+ "onSuccess": "CocosHandler.inst.getAccountInfo_success",
|
|
|
+ "onFail": "CocosHandler.inst.getAccountInfo_fail"
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+ const data: CocosHandlerType = {
|
|
|
+ method: "request.post",
|
|
|
+ param: JSON.stringify(param)
|
|
|
}
|
|
|
+ this.sendMessageToAndroid(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取账号信息成功回调
|
|
|
+ getAccountInfo_success(str: string) {
|
|
|
+ console.log("获取账号信息成功回调", str);
|
|
|
+ //保存账号信息
|
|
|
+ let result = JSON.parse(str);
|
|
|
+ smc.account.AccountModel.setAccountInfo(result);
|
|
|
+ oops.message.dispatchEvent(GameEvent.UserLogin);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取账号信息失败回调
|
|
|
+ getAccountInfo_fail(code: number, str: string) {
|
|
|
+ console.log("获取账号信息失败回调", str);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ //领取每日奖励
|
|
|
+ getDailyReward(level: number) {
|
|
|
+ const param = {
|
|
|
+ "url": ProtocolEvent.GetDailyReward,
|
|
|
+ "param": {
|
|
|
+ "level": level
|
|
|
+ },
|
|
|
+ "callback": {
|
|
|
+ "onSuccess": "CocosHandler.inst.getDailyReward_success",
|
|
|
+ "onFail": "CocosHandler.inst.request_fail"
|
|
|
+ }
|
|
|
+ }
|
|
|
const data: CocosHandlerType = {
|
|
|
method: "request.post",
|
|
|
param: JSON.stringify(param)
|
|
|
}
|
|
|
+ this.sendMessageToAndroid(data);
|
|
|
+ }
|
|
|
|
|
|
+ //领取每日奖励成功回调
|
|
|
+ getDailyReward_success(str: string) {
|
|
|
+ console.log("领取每日奖励成功回调", str);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ request_fail(code: number, str: string) {
|
|
|
+ console.log("请求失败回调", code, str);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//=================================以下是广告方法====================
|
|
|
//每次启动都加载一次启屏广告
|
|
|
async ad_interstitial_start() {
|
|
|
@@ -157,14 +226,18 @@ export class CocosHandler {
|
|
|
|
|
|
|
|
|
//启屏广告关闭时回调
|
|
|
- ad_splash_close() {
|
|
|
+ async ad_splash_close() {
|
|
|
if (oops.gui.has(UIID.KindTips)) {
|
|
|
oops.gui.remove(UIID.KindTips);
|
|
|
}
|
|
|
if (oops.gui.has(UIID.Retention)) {
|
|
|
oops.gui.remove(UIID.Retention);
|
|
|
}
|
|
|
- oops.message.dispatchEvent(AndroidEvent.AgreePrivacy);
|
|
|
+ let result = await CocosHandler.inst.savePrivacyStatus(true);
|
|
|
+ if (result.code == 0) {
|
|
|
+ //广告结束后调用登录
|
|
|
+ this.getAccountInfo();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -212,93 +285,29 @@ export class CocosHandler {
|
|
|
console.log("广告显示失败回调");
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //===================安卓回调Cocos======================
|
|
|
- //微信登录成功回调
|
|
|
- wechat_login_success(str: string) {
|
|
|
- console.log("微信登录成功回调", str);
|
|
|
- //保存数据
|
|
|
- // oops.message.dispatchEvent(GameEvent.WechatLoginSuss);
|
|
|
-
|
|
|
-
|
|
|
- // 获取用户信息
|
|
|
- //然后就是和服务器通信
|
|
|
- }
|
|
|
-
|
|
|
- //微信登录失败回调
|
|
|
- wechat_login_fail(str: string) {
|
|
|
- console.log("微信登录失败回调", str);
|
|
|
- oops.gui.toast("微信登录失败");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //安卓直接调用广告回调,显示失败还是成功,成功提供什么奖励,失败又怎么做
|
|
|
- async ad_callback(ad_type: string, ad_status: string, ad_reward: string) {
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //==================跟服务器交互======================
|
|
|
- //微信登录
|
|
|
- async wx_login(code: string) {
|
|
|
+ //广告请求--激励视频广告
|
|
|
+ async ad_reward(id: number) {
|
|
|
const param = {
|
|
|
- "code": code,
|
|
|
- "url": ProtocolEvent.WechatLogin
|
|
|
+ "funcId": `${id}`,
|
|
|
+ "callback":
|
|
|
+ {
|
|
|
+ "onClose": "CocosHandler.inst.ad_reward_close"
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
const data: CocosHandlerType = {
|
|
|
- method: "request.post",
|
|
|
+ method: "ad.reward",
|
|
|
param: JSON.stringify(param)
|
|
|
}
|
|
|
-
|
|
|
let result = await this.sendMessageToAndroid(data);
|
|
|
- console.log("微信登录结果", result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
- //获取账号信息
|
|
|
- getAccountInfo() {
|
|
|
- const param = {
|
|
|
- "url": ProtocolEvent.AccountInfo,
|
|
|
- "param": {
|
|
|
- "authToken": "123456"
|
|
|
- },
|
|
|
- "callback": {
|
|
|
- "onSuccess": "CocosHandler.inst.getAccountInfo_success",
|
|
|
- "onFail": "CocosHandler.inst.getAccountInfo_fail"
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- const data: CocosHandlerType = {
|
|
|
- method: "request.post",
|
|
|
- param: JSON.stringify(param)
|
|
|
- }
|
|
|
- this.sendMessageToAndroid(data);
|
|
|
+ //激励视频广告关闭回调
|
|
|
+ ad_reward_close(str: string) {
|
|
|
+ console.log("激励视频广告关闭回调", str);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //获取账号信息成功回调
|
|
|
- getAccountInfo_success(str: string) {
|
|
|
- console.log("获取账号信息成功回调", str);
|
|
|
- }
|
|
|
-
|
|
|
- //获取账号信息失败回调
|
|
|
- getAccountInfo_fail(str: string) {
|
|
|
- console.log("获取账号信息失败回调", str);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
window['CocosHandler'] = CocosHandler;
|
|
|
|