|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-31 10:45:44
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-04-07 15:35:51
|
|
|
+ * @LastEditTime: 2025-04-08 16:33:08
|
|
|
* @Description: CocosHandler 处理类负责与安卓交互
|
|
|
*/
|
|
|
import { native } from 'cc';
|
|
|
@@ -12,6 +12,7 @@ import { smc } from '../SingletonModuleComp';
|
|
|
import { Account } from '../../account/Account';
|
|
|
import { oops } from 'db://oops-framework/core/Oops';
|
|
|
import { GameEvent } from '../config/GameEvent';
|
|
|
+import { ProtocolEvent } from './ProtocolEvent';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
type CocosHandlerType = {
|
|
|
@@ -41,7 +42,7 @@ export class CocosHandler {
|
|
|
//微信登录
|
|
|
async wechat_login() {
|
|
|
const param = {
|
|
|
- "appId": "wx1234567890",
|
|
|
+ "appId": "wx1234567890", //这个ID没申请下来
|
|
|
"callback":
|
|
|
{
|
|
|
"onSuccess": "CocosHandler.inst.wechat_login_success",
|
|
|
@@ -55,6 +56,7 @@ export class CocosHandler {
|
|
|
}
|
|
|
|
|
|
let result = await this.sendMessageToAndroid(data);
|
|
|
+ console.log("微信登录结果>>>>>>>>>>", result);
|
|
|
// smc.account.AccountModel.
|
|
|
return result;
|
|
|
}
|
|
|
@@ -62,10 +64,11 @@ export class CocosHandler {
|
|
|
//获取隐私授权状态
|
|
|
async getPrivacyStatus() {
|
|
|
const data: CocosHandlerType = {
|
|
|
- method: "system.privacy.get",
|
|
|
+ method: "privacy.grant.get",
|
|
|
}
|
|
|
let result = await this.sendMessageToAndroid(data);
|
|
|
- return result;
|
|
|
+ console.log("安卓返回隐私授权状态", result);
|
|
|
+ return JSON.parse(result);
|
|
|
}
|
|
|
|
|
|
//保存隐私授权状态
|
|
|
@@ -78,7 +81,8 @@ export class CocosHandler {
|
|
|
param: JSON.stringify(param)
|
|
|
}
|
|
|
let result = await this.sendMessageToAndroid(data);
|
|
|
- return result;
|
|
|
+ console.log("安卓返回隐私授权状态", result);
|
|
|
+ return JSON.parse(result);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -130,6 +134,9 @@ export class CocosHandler {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //=================================以下是广告方法====================
|
|
|
+
|
|
|
+
|
|
|
//广告请求--插屏广告
|
|
|
async ad_interstitial() {
|
|
|
const param = {
|
|
|
@@ -163,8 +170,8 @@ export class CocosHandler {
|
|
|
}
|
|
|
|
|
|
//广告加载失败回调
|
|
|
- ad_interstitial_load_failed() {
|
|
|
- console.log("广告加载失败回调");
|
|
|
+ ad_interstitial_load_failed(msg: string) {
|
|
|
+ console.log("广告加载失败回调", msg);
|
|
|
}
|
|
|
|
|
|
//广告显示失败回调
|
|
|
@@ -172,6 +179,8 @@ export class CocosHandler {
|
|
|
console.log("广告显示失败回调");
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -181,7 +190,11 @@ export class CocosHandler {
|
|
|
wechat_login_success(str: string) {
|
|
|
console.log("微信登录成功回调", str);
|
|
|
//保存数据
|
|
|
- oops.message.dispatchEvent(GameEvent.WechatLoginSuss);
|
|
|
+ // oops.message.dispatchEvent(GameEvent.WechatLoginSuss);
|
|
|
+
|
|
|
+
|
|
|
+ // 获取用户信息
|
|
|
+ //然后就是和服务器通信
|
|
|
}
|
|
|
|
|
|
//微信登录失败回调
|
|
|
@@ -190,12 +203,35 @@ export class CocosHandler {
|
|
|
oops.gui.toast("微信登录失败");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//安卓直接调用广告回调,显示失败还是成功,成功提供什么奖励,失败又怎么做
|
|
|
async ad_callback(ad_type: string, ad_status: string, ad_reward: string) {
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //==================跟服务器交互======================
|
|
|
+ //微信登录
|
|
|
+ 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);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
window['CocosHandler'] = CocosHandler;
|
|
|
|