feat: 接入微信隐私授权API和用户信息获取
- WxSDK 新增隐私授权检查和用户信息获取方法 - StorageManager 新增用户信息本地缓存方法 - PageHome 进入时检查隐私授权状态 - PageWriteLevels 分享时获取用户头像昵称并上传服务端 - ApiConfig 新增用户信息 API 端点 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { _decorator, Node, Button } from 'cc';
|
||||
import { BaseView } from 'db://assets/scripts/core/BaseView';
|
||||
import { ViewManager } from 'db://assets/scripts/core/ViewManager';
|
||||
import { WxSDK } from 'db://assets/scripts/utils/WxSDK';
|
||||
import { WxSDK, checkPrivacySetting, requirePrivacyAuthorize } from 'db://assets/scripts/utils/WxSDK';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -23,6 +23,8 @@ export class PageHome extends BaseView {
|
||||
console.log('[PageHome] onViewLoad');
|
||||
this._initButtons();
|
||||
this._initWxShare();
|
||||
// 检查隐私授权
|
||||
this._checkPrivacyAuthorization();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +38,28 @@ export class PageHome extends BaseView {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查隐私授权状态
|
||||
*/
|
||||
private async _checkPrivacyAuthorization(): Promise<void> {
|
||||
if (!WxSDK.isWechat()) {
|
||||
console.log('[PageHome] 非微信环境,跳过隐私授权检查');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { needAuthorization } = await checkPrivacySetting();
|
||||
if (needAuthorization) {
|
||||
console.log('[PageHome] 用户未授权隐私,引导授权');
|
||||
await requirePrivacyAuthorize();
|
||||
} else {
|
||||
console.log('[PageHome] 用户已授权隐私');
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[PageHome] 隐私授权检查异常:', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化按钮事件
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user