Bläddra i källkod

调整会员页面

chendeben 1 år sedan
förälder
incheckning
c5c856b3e6
2 ändrade filer med 508 tillägg och 321 borttagningar
  1. 383 0
      entry/src/main/ets/common/util/UserUtil.ets
  2. 125 321
      entry/src/main/ets/pages/UserCenter.ets

+ 383 - 0
entry/src/main/ets/common/util/UserUtil.ets

@@ -0,0 +1,383 @@
+import { cryptoFramework } from "@kit.CryptoArchitectureKit";
+import { LogUtil, PreferencesUtil, StrUtil, ToastUtil } from "@pura/harmony-utils";
+import { CommonConstants } from "../constants/CommonConstants";
+import { http } from "@kit.NetworkKit";
+import { bundleManager } from "@kit.AbilityKit";
+import { BusinessError } from '@kit.BasicServicesKit';
+import { hilog } from "@kit.PerformanceAnalysisKit";
+
+// 用户相关接口定义
+export interface WechatUserInfo {
+  openid?: string;
+  nickname?: string;
+  sex?: number;
+  language?: string;
+  city?: string;
+  province?: string;
+  country?: string;
+  headimgurl?: string;
+  privilege?: string[];
+  unionid?: string;
+}
+
+export interface Subscription {
+  plan_id: string;
+  plan_name: string;
+  plan_description: string;
+  price: string;
+  start_date: string;
+  end_date: string;
+  status: string;
+  auto_renew: string;
+  features: string[];
+}
+
+export interface SubscriptionInfo {
+  has_active_subscription: boolean;
+  subscriptions: Subscription[];
+}
+
+export interface responseData {
+  token_info?: object;
+  user_info: WechatUserInfo;
+}
+
+export interface WechatUserInfoData {
+  token_info?: object;
+  user_info: WechatUserInfo;
+  system_info?: SystemInfo;
+  subscription_info?: SubscriptionInfo;
+}
+
+export interface WechatUserInfoApiResponse {
+  code: number;
+  msg: string;
+  data: WechatUserInfoData;
+}
+
+export interface HuaweiUserInfo {
+  openid: string;
+  unionid?: string;
+  nickname: string;
+  headimgurl: string;
+}
+
+export interface SystemInfo {
+  user_id: number | string;
+  token: string;
+}
+
+export interface HuaweiUserInfoApiData {
+  user_info: HuaweiUserInfo;
+  system_info?: SystemInfo;
+  subscription_info?: SubscriptionInfo;
+}
+
+export interface HuaweiUserInfoApiResponse {
+  code: number;
+  msg: string;
+  data: HuaweiUserInfoApiData;
+}
+
+export interface VipFeature {
+  icon: Resource;
+  title: string;
+  description: string;
+  isVipOnly: boolean;
+}
+
+export interface VipPlanApi {
+  id: string;
+  name: string;
+  description: string;
+  price: string;
+  duration: string;
+  features: string;
+  sort_order: string;
+  status: string;
+  created_at: string;
+  updated_at: string;
+}
+
+export interface VipPlanListApiData {
+  plans: VipPlanApi[];
+}
+
+export interface VipPlanListApiResponse {
+  code: number;
+  msg: string;
+  data: VipPlanListApiData;
+}
+
+export interface WeChatPrepayId {
+  prepay_id: string;
+}
+
+export interface UserInfoApiData {
+  user_info: WechatUserInfo;
+  system_info: SystemInfo;
+  subscription_info: SubscriptionInfo;
+}
+
+export interface UserInfoApiResponse {
+  code: number;
+  msg: string;
+  data: UserInfoApiData;
+}
+
+export default class UserUtil {
+  // 微信是否安装
+  static async isHasWX(): Promise<boolean> {
+    try {
+      let link = 'weixin://';
+      let data = bundleManager.canOpenLink(link);
+      if (data) {
+        return true;
+      } else {
+        ToastUtil.showToast('微信未安装');
+        return false;
+      }
+    } catch (err) {
+      let message = (err as BusinessError).message;
+      console.error('canOpenLink failed: %{public}s', message);
+      return false;
+    }
+  }
+
+  // 创建微信订单
+  static async createWeChatOrder(app_id: string, mch_id: string, description: string, amount: number, out_trade_no_pre: string, uid: number, plan_id: string): Promise<string> {
+    let requestUrl = CommonConstants.WX_PAY_API
+      + '?app_id=' + encodeURIComponent(app_id.trim())
+      + '&mch_id=' + encodeURIComponent(mch_id.trim())
+      + '&description=' + encodeURIComponent(description.trim())
+      + '&amount=' + encodeURIComponent(amount)
+      + '&uid=' + encodeURIComponent(uid)
+      + '&plan_id=' + encodeURIComponent(plan_id)
+      + '&out_trade_no_pre=' + encodeURIComponent(out_trade_no_pre);
+    const httpRequest: http.HttpRequest = http.createHttp();
+    const options: http.HttpRequestOptions = {
+      method: http.RequestMethod.GET,
+      readTimeout: 6000,
+      connectTimeout: 6000,
+    };
+    try {
+      const response: http.HttpResponse = await httpRequest.request(requestUrl, options);
+      if (response.responseCode === 200) {
+        let responseData: WeChatPrepayId;
+        if (typeof response.result === 'string') {
+          responseData = JSON.parse(response.result) as WeChatPrepayId;
+        } else if (response.result instanceof Object) {
+          responseData = response.result as WeChatPrepayId;
+        } else {
+          throw new Error('Unexpected response format');
+        }
+        const prepayId: string = responseData.prepay_id;
+        return prepayId;
+      } else {
+        ToastUtil.showToast('微信下单失败');
+        return '';
+      }
+    } catch (error) {
+      ToastUtil.showToast('微信下单异常');
+      return '';
+    }
+  }
+
+  // 构造签名串
+  static constructSignatureString(appId: string, timestamp: string, nonceStr: string, prepayId: string): string {
+    return `${appId}\n${timestamp}\n${nonceStr}\n${prepayId}\n`;
+  }
+
+  // 微信支付签名
+  static async rsaSign2048( message: string): Promise<Uint8Array> {
+
+    try {
+      let keyGen = cryptoFramework.createAsyKeyGenerator("RSA2048")
+      let key = keyGen.convertPemKeySync(null, CommonConstants.WX_PAY_RSA_PRIVATE_KEY)
+
+      let sign = cryptoFramework.createSign('RSA2048|PKCS1|SHA256');
+      let msgBlob: cryptoFramework.DataBlob = {data: StrUtil.strToUint8Array(message)}
+      sign.initSync(key.priKey)
+      let signature = await sign.sign(msgBlob)
+      return signature.data
+    } catch (error) {
+      console.error(error, `onecold error code: ${error.code}`)
+      return new Uint8Array()
+    }
+  }
+
+  // 通过code换取用户信息
+  static async getUserInfoByCode(code: string): Promise<UserInfoApiData |WechatUserInfoData| null> {
+    try {
+      const url = `https://pay.ss5.xyz/wechat/user_info?code=${encodeURIComponent(code)}`;
+      const httpRequest = http.createHttp();
+      const options: http.HttpRequestOptions = {
+        method: http.RequestMethod.GET,
+        readTimeout: 3000,
+        connectTimeout: 3000,
+      };
+      const response: http.HttpResponse = await httpRequest.request(url, options);
+      if (response.responseCode === 200) {
+        let res = response.result as string;
+        LogUtil.debug("getUserInfoByCode res =" + res)
+        let json: WechatUserInfoApiResponse = JSON.parse(res) as WechatUserInfoApiResponse;
+        if (json.code === 0 && json.data && json.data.user_info) {
+          const userId = json.data.system_info?.user_id ? Number(json.data.system_info?.user_id) : 0;
+          hilog.info(0x0000, 'UserUtil', `getUserInfoByCode: userId set to ${userId}`);
+          const userName = json.data.user_info.nickname || '微信用户';
+          const userAvatarUrl = json.data.user_info.headimgurl && json.data.user_info.headimgurl.length > 0 ? json.data.user_info.headimgurl : '';
+          // 解析订阅信息
+          const subInfo = json.data.subscription_info;
+          let hasActiveSubscription = false;
+          let subscriptionName = '';
+          let subscriptionEndDate = '';
+          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
+            hasActiveSubscription = true;
+            subscriptionName = subInfo.subscriptions[0].plan_name;
+            subscriptionEndDate = subInfo.subscriptions[0].end_date;
+          }
+          // 保存登录状态和用户信息
+          PreferencesUtil.putSync('isLogin', true);
+          PreferencesUtil.putSync('userId', userId);
+          PreferencesUtil.putSync('userName', userName);
+          PreferencesUtil.putSync('userAvatarUrl', userAvatarUrl);
+          PreferencesUtil.putSync('subscriptionName', subscriptionName);
+          PreferencesUtil.putSync('subscriptionEndDate', subscriptionEndDate);
+          PreferencesUtil.putSync('hasActiveSubscription', hasActiveSubscription);
+          PreferencesUtil.putSync('userToken', json.data.system_info?.token || '');
+          ToastUtil.showToast('微信登录成功');
+          return json.data;
+        } else {
+          ToastUtil.showToast('用户信息解析失败');
+          return null;
+        }
+      } else {
+        ToastUtil.showToast('获取用户信息失败');
+        return null;
+      }
+    } catch (e) {
+      ToastUtil.showToast('登录失败' + (e && e.message ? (': ' + e.message) : ''));
+      return null;
+    }
+  }
+
+  // 通过华为账号信息换取用户信息和会员状态
+  static async getUserInfoByHuawei(openID: string, unionID: string, nickname: string, avatarUri: string): Promise<HuaweiUserInfoApiData | null> {
+    try {
+      const url = `https://pay.ss5.xyz/user/huawei?openID=${encodeURIComponent(openID)}&unionID=${encodeURIComponent(unionID)}&nickname=${encodeURIComponent(nickname)}&avatarUri=${encodeURIComponent(avatarUri)}`;
+      const httpRequest = http.createHttp();
+      const options: http.HttpRequestOptions = {
+        method: http.RequestMethod.GET,
+        readTimeout: 3000,
+        connectTimeout: 3000,
+      };
+      const response: http.HttpResponse = await httpRequest.request(url, options);
+      if (response.responseCode === 200) {
+        let res = response.result as string;
+        LogUtil.debug("getUserInfoByHuawei res =" + res)
+        let json: HuaweiUserInfoApiResponse = JSON.parse(res) as HuaweiUserInfoApiResponse;
+        if (json.code === 0 && json.data && json.data.user_info) {
+          const userId = json.data.system_info?.user_id ? Number(json.data.system_info?.user_id) : 0;
+          hilog.info(0x0000, 'UserUtil', `getUserInfoByHuawei: userId set to ${userId}`);
+          const userName = json.data.user_info.nickname || '华为用户';
+          const userAvatarUrl = json.data.user_info.headimgurl || '';
+          // 处理会员信息
+          const subInfo = json.data.subscription_info;
+          let hasActiveSubscription = false;
+          let subscriptionName = '';
+          let subscriptionEndDate = '';
+          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
+            hasActiveSubscription = true;
+            subscriptionName = subInfo.subscriptions[0].plan_name;
+            subscriptionEndDate = subInfo.subscriptions[0].end_date;
+          }
+          // 保存登录状态
+          PreferencesUtil.putSync('isLogin', true);
+          PreferencesUtil.putSync('userId', userId);
+          PreferencesUtil.putSync('userName', userName);
+          PreferencesUtil.putSync('userAvatarUrl', userAvatarUrl);
+          PreferencesUtil.putSync('subscriptionName', subscriptionName);
+          PreferencesUtil.putSync('subscriptionEndDate', subscriptionEndDate);
+          PreferencesUtil.putSync('hasActiveSubscription', hasActiveSubscription);
+          PreferencesUtil.putSync('userToken', json.data.system_info?.token || '');
+          ToastUtil.showToast('华为登录成功');
+          return json.data;
+        } else {
+          ToastUtil.showToast('用户信息解析失败');
+          return null;
+        }
+      } else {
+        ToastUtil.showToast('获取用户信息失败');
+        return null;
+      }
+    } catch (e) {
+      ToastUtil.showToast('登录失败' + (e && e.message ? (': ' + e.message) : ''));
+      return null;
+    }
+  }
+
+  // 刷新用户信息
+  static async fetchUserInfo(token: string): Promise<UserInfoApiData | null> {
+    try {
+      const url = `https://pay.ss5.xyz/user/info?token=${encodeURIComponent(token)}`;
+      const httpRequest = http.createHttp();
+      const options: http.HttpRequestOptions = {
+        method: http.RequestMethod.GET,
+        readTimeout: 3000,
+        connectTimeout: 3000,
+      };
+      const response: http.HttpResponse = await httpRequest.request(url, options);
+      if (response.responseCode === 200) {
+        let res = response.result as string;
+        LogUtil.debug("fetchUserInfo res =" + res);
+        let json: UserInfoApiResponse = JSON.parse(res) as UserInfoApiResponse;
+        if (json.code === 0 && json.data) {
+          const userInfo = json.data.user_info;
+          const systemInfo = json.data.system_info;
+          const subInfo = json.data.subscription_info;
+          let hasActiveSubscription = false;
+          let subscriptionName = '';
+          let subscriptionEndDate = '';
+          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
+            hasActiveSubscription = true;
+            subscriptionName = subInfo.subscriptions[0].plan_name;
+            subscriptionEndDate = subInfo.subscriptions[0].end_date;
+          }
+          // ToastUtil.showToast('用户信息已更新');
+          return json.data;
+        } else {
+          ToastUtil.showToast('刷新用户信息失败');
+          return null;
+        }
+      } else {
+        ToastUtil.showToast('获取用户信息失败');
+        return null;
+      }
+    } catch (e) {
+      ToastUtil.showToast('获取用户信息异常' + (e && e.message ? (': ' + e.message) : ''));
+      hilog.error(0x0000, 'UserUtil', `fetchUserInfo error: ${e.message}`);
+      return null;
+    }
+  }
+
+  // 华为登录错误处理
+  static dealHuaweiLoginError(error: BusinessError): void {
+    if (error.code === 1001) {
+      ToastUtil.showToast('未登录华为账号');
+    } else if (error.code === 1002) {
+      ToastUtil.showToast('网络异常');
+    } else if (error.code === 1003) {
+      ToastUtil.showToast('内部错误');
+    } else if (error.code === 1004) {
+      ToastUtil.showToast('用户取消授权');
+    } else if (error.code === 1005) {
+      ToastUtil.showToast('系统服务异常');
+    } else if (error.code === 1006) {
+      ToastUtil.showToast('请求被拒绝');
+    } else if (error.code === 1007) {
+      ToastUtil.showToast('无权限');
+    } else {
+      ToastUtil.showToast('登录失败');
+    }
+  }
+}

+ 125 - 321
entry/src/main/ets/pages/UserCenter.ets

@@ -4,14 +4,14 @@ import { resourceManager } from '@kit.LocalizationKit';
 import { BreakpointTypeEnum } from '../common/util/BreakpointSystem';
 import * as wxopensdk from '@tencent/wechat_open_sdk';
 import { OnWXResp, WXApi, WXEventHandler } from '../common/util/WXApiWrap';
-import { bundleManager, common, UIAbility } from '@kit.AbilityKit';
+import { bundleManager, common, ConfigurationConstant, UIAbility } from '@kit.AbilityKit';
 import { ErrCode } from '@tencent/wechat_open_sdk';
 import { http } from '@kit.NetworkKit';
 import { authentication } from '@kit.AccountKit';
 import { hilog } from '@kit.PerformanceAnalysisKit';
 import { BusinessError } from '@kit.BasicServicesKit';
 import { util } from '@kit.ArkTS';
-import { DialogHelper } from '@pura/harmony-dialog';
+import { AnimationHelper, DialogHelper } from '@pura/harmony-dialog';
 import { Pay } from '@cashier_alipay/cashiersdk';
 import { OrderInfoUtil } from '../alipay/OrderInfoUtil';
 import { RandomUtil, Base64Util } from '@pura/harmony-utils';
@@ -19,133 +19,9 @@ import { CommonConstants } from '../common/constants/CommonConstants';
 import { PayReq } from '@tencent/wechat_open_sdk';
 import { cryptoFramework } from '@kit.CryptoArchitectureKit';
 import json from '@ohos.util.json';
+import UserUtil, { VipFeature, VipPlanApi, VipPlanListApiResponse, WeChatPrepayId } from '../common/util/UserUtil';
 
 
-interface WechatUserInfo {
-  openid?: string;
-  nickname?: string;
-  sex?: number;
-  language?: string;
-  city?: string;
-  province?: string;
-  country?: string;
-  headimgurl?: string;
-  privilege?: string[];
-  unionid?: string;
-}
-
-interface Subscription {
-  plan_id: string;
-  plan_name: string;
-  plan_description: string;
-  price: string;
-  start_date: string;
-  end_date: string;
-  status: string;
-  auto_renew: string;
-  features: string[];
-}
-
-interface SubscriptionInfo {
-  has_active_subscription: boolean;
-  subscriptions: Subscription[];
-}
-
-interface responseData {
-  token_info?: object;
-  user_info: WechatUserInfo;
-}
-
-interface WechatUserInfoData {
-  token_info?: object;
-  user_info: WechatUserInfo;
-  system_info?: SystemInfo;
-  subscription_info?: SubscriptionInfo;
-}
-
-interface WechatUserInfoApiResponse {
-  code: number;
-  msg: string;
-  data: WechatUserInfoData;
-}
-
-interface HuaweiUserInfo {
-  openid: string;
-  unionid?: string;
-  nickname: string;
-  headimgurl: string;
-}
-
-interface SystemInfo {
-  user_id: number | string;
-  token: string;
-}
-
-interface HuaweiUserInfoApiData {
-  user_info: HuaweiUserInfo;
-  system_info?: SystemInfo;
-  subscription_info?: SubscriptionInfo;
-}
-
-interface HuaweiUserInfoApiResponse {
-  code: number;
-  msg: string;
-  data: HuaweiUserInfoApiData;
-}
-
-interface VipFeature {
-  icon: Resource;
-  title: string;
-  description: string;
-  isVipOnly: boolean;
-}
-
-interface VipPlanApi {
-  id: string;
-  name: string;
-  description: string;
-  price: string;
-  duration: string;
-  features: string;
-  sort_order: string;
-  status: string;
-  created_at: string;
-  updated_at: string;
-}
-
-interface VipPlanListApiData {
-  plans: VipPlanApi[];
-}
-
-interface VipPlanListApiResponse {
-  code: number;
-  msg: string;
-  data: VipPlanListApiData;
-}
-
-interface WeChatPrepayId {
-  prepay_id: string;
-}
-
-// user/info 接口的返回结构
-interface UserInfoApiData {
-  user_info: WechatUserInfo; // 可以复用 WechatUserInfo
-  system_info: SystemInfo;
-  subscription_info: SubscriptionInfo;
-}
-
-interface UserInfoApiResponse {
-  code: number;
-  msg: string;
-  data: UserInfoApiData;
-}
-
-// 自定义主题颜色
-
-// 支持传入主题,默认使用myTheme
-export interface UserCenterParams {
-  theme?: CustomTheme;
-}
 
 // 微信支付相关工具方法
 async function isHasWX(): Promise<boolean> {
@@ -242,15 +118,23 @@ export struct UserCenter {
   private wxEventHandler = WXEventHandler
   @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
   @State vipFeatures: VipFeature[] = [
-    { icon: $r('app.media.small_music'), title: '无损音质', description: '支持FLAC、WAV等无损格式', isVipOnly: true },
-    { icon: $r('app.media.small_music'), title: '歌词显示', description: '支持LRC歌词同步显示', isVipOnly: false },
-    { icon: $r('app.media.small_music'), title: '智能歌单', description: 'AI智能推荐歌单', isVipOnly: true },
-    { icon: $r('app.media.small_music'), title: '主题定制', description: '自定义播放器主题', isVipOnly: true }
+    { icon: $r('app.media.wusunyinzhi'), title: '无损音质', description: '专享无损音乐支持,让每个音符都完美呈现', isVipOnly: true },
+    // { icon: $r('app.media.lrc'), title: '歌词下载', description: '支持歌词API在线下载LRC歌词,实现完美同步', isVipOnly: true },
+    // { icon: $r('app.media.cover'), title: '封面API', description: '支持设置自动下载封面', isVipOnly: true },
+    { icon: $r('app.media.theme'), title: '主题定制', description: '自定义播放器主题,打造独一无二的个性风格', isVipOnly: true },
+    { icon: $r('app.media.car'), title: 'HiCAR播放', description: '专为驾车体验优化的音乐播放模式', isVipOnly: true },
+    { icon: $r('app.media.music_wave'), title: '参数均衡', description: '精准定制音效,带来极致听觉体验', isVipOnly: true },
   ];
   @State vipPlans: VipPlanApi[] = [];
   @State selectedPayPlan: VipPlanApi | null = null;
   @State payType: number = 0; // 0: 微信, 1: 支付宝
   @StorageProp('themeColor') themeColor: string = '#FF4081';
+  @State isDarkMode: boolean = false
+  @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
+    ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
+  onColorModeChange() {
+    this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK
+  }
 
   constructor() {
     super();
@@ -290,131 +174,21 @@ export struct UserCenter {
 
   // 通过code换取用户信息
   async getUserInfoByCode(code: string) {
-    try {
-      const url = `https://pay.ss5.xyz/wechat/user_info?code=${encodeURIComponent(code)}`;
-      const httpRequest = http.createHttp();
-      const options: http.HttpRequestOptions = {
-        method: http.RequestMethod.GET,
-        readTimeout: 3000,
-        connectTimeout: 3000,
-      };
-      const response: http.HttpResponse = await httpRequest.request(url, options);
-      if (response.responseCode === 200) {
-        let res = response.result as string;
-        LogUtil.debug("getUserInfoByCode res =" + res)
-        let json: WechatUserInfoApiResponse = JSON.parse(res) as WechatUserInfoApiResponse;
-        if (json.code === 0 && json.data && json.data.user_info) {
-          let userInfo: WechatUserInfo = json.data.user_info;
-          this.isLogin = true;
-          this.userId = json.data.system_info?.user_id ? Number(json.data.system_info?.user_id) : 0;
-          hilog.info(0x0000, 'UserCenter', `getUserInfoByCode: this.userId set to ${this.userId}`);
-          this.userName = userInfo.nickname || '微信用户';
-          if (userInfo.headimgurl && userInfo.headimgurl.length > 0) {
-            this.userAvatarUrl = userInfo.headimgurl;
-            this.userAvatar = $r('app.media.icon_person2');
-          } else {
-            this.userAvatarUrl = '';
-            this.userAvatar = $r('app.media.icon_person2');
-          }
-          // 解析订阅信息
-          const subInfo = json.data.subscription_info;
-          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
-            this.hasActiveSubscription = true;
-            this.subscriptionName = subInfo.subscriptions[0].plan_name;
-            this.subscriptionEndDate = subInfo.subscriptions[0].end_date;
-          } else {
-            this.hasActiveSubscription = false;
-            this.subscriptionName = '';
-            this.subscriptionEndDate = '';
-          }
-          // 保存登录状态和用户信息
-          PreferencesUtil.putSync('isLogin', true);
-          PreferencesUtil.putSync('userId', this.userId);
-          PreferencesUtil.putSync('userName', this.userName);
-          PreferencesUtil.putSync('userAvatarUrl', this.userAvatarUrl);
-          PreferencesUtil.putSync('subscriptionName', this.subscriptionName);
-          PreferencesUtil.putSync('subscriptionEndDate', this.subscriptionEndDate);
-          PreferencesUtil.putSync('hasActiveSubscription', this.hasActiveSubscription);
-          PreferencesUtil.putSync('userToken', json.data.system_info?.token || '');
-          ToastUtil.showToast('微信登录成功');
-        } else {
-          ToastUtil.showToast('用户信息解析失败');
-        }
-      } else {
-        ToastUtil.showToast('获取用户信息失败');
-      }
-    } catch (e) {
-      ToastUtil.showToast('登录失败' + (e && e.message ? (': ' + e.message) : ''));
-    }
+    await UserUtil.getUserInfoByCode(code).then(()=>{
+      this.showUserInfo()
+    });
   }
 
   // 通过华为账号信息换取用户信息和会员状态
   async getUserInfoByHuawei(openID: string, unionID: string, nickname: string, avatarUri: string) {
-    try {
-      const url = `https://pay.ss5.xyz/user/huawei?openID=${encodeURIComponent(openID)}&unionID=${encodeURIComponent(unionID)}&nickname=${encodeURIComponent(nickname)}&avatarUri=${encodeURIComponent(avatarUri)}`;
-      const httpRequest = http.createHttp();
-      const options: http.HttpRequestOptions = {
-        method: http.RequestMethod.GET,
-        readTimeout: 3000,
-        connectTimeout: 3000,
-      };
-      const response: http.HttpResponse = await httpRequest.request(url, options);
-      if (response.responseCode === 200) {
-        let res = response.result as string;
-        LogUtil.debug("getUserInfoByHuawei res =" + res)
-        let json: HuaweiUserInfoApiResponse = JSON.parse(res) as HuaweiUserInfoApiResponse;
-        if (json.code === 0 && json.data && json.data.user_info) {
-          // 登录成功处理
-          this.isLogin = true;
-          this.userId = json.data.system_info?.user_id ? Number(json.data.system_info?.user_id) : 0;
-          hilog.info(0x0000, 'UserCenter', `getUserInfoByHuawei: this.userId set to ${this.userId}`);
-          this.userName = json.data.user_info.nickname || '华为用户';
-          this.userAvatarUrl = json.data.user_info.headimgurl || '';
-          // 处理会员信息
-          const subInfo = json.data.subscription_info;
-          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
-            this.hasActiveSubscription = true;
-            this.subscriptionName = subInfo.subscriptions[0].plan_name;
-            this.subscriptionEndDate = subInfo.subscriptions[0].end_date;
-          } else {
-            this.hasActiveSubscription = false;
-            this.subscriptionName = '';
-            this.subscriptionEndDate = '';
-          }
-          // 保存登录状态
-          PreferencesUtil.putSync('isLogin', true);
-          PreferencesUtil.putSync('userId', this.userId);
-          PreferencesUtil.putSync('userName', this.userName);
-          PreferencesUtil.putSync('userAvatarUrl', this.userAvatarUrl);
-          PreferencesUtil.putSync('subscriptionName', this.subscriptionName);
-          PreferencesUtil.putSync('subscriptionEndDate', this.subscriptionEndDate);
-          PreferencesUtil.putSync('hasActiveSubscription', this.hasActiveSubscription);
-          PreferencesUtil.putSync('userToken', json.data.system_info?.token || '');
-          ToastUtil.showToast('华为登录成功');
-        } else {
-          ToastUtil.showToast('用户信息解析失败');
-        }
-      } else {
-        ToastUtil.showToast('获取用户信息失败');
-      }
-    } catch (e) {
-      ToastUtil.showToast('登录失败' + (e && e.message ? (': ' + e.message) : ''));
-    }
+    await UserUtil.getUserInfoByHuawei(openID, unionID, nickname, avatarUri);
   }
 
   aboutToAppear(): void {
     let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
     AppStorage.setOrCreate('themeColor', themeColor);
     this.themeColor = themeColor;
-    // 自动恢复本地登录状态
-    this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
-    this.userId = PreferencesUtil.getNumberSync('userId', 0);
-    this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
-    this.userAvatarUrl = PreferencesUtil.getStringSync('userAvatarUrl', '');
-    this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
-    this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
-    this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
-    this.userToken = PreferencesUtil.getStringSync('userToken', '');
+    this.showUserInfo()
     this.wxEventHandler.registerOnWXRespCallback(this.onWXResp)
     this.fetchVipPlans();
     if (this.isLogin && this.userToken) {
@@ -425,6 +199,17 @@ export struct UserCenter {
   aboutToDisappear() {
     this.wxEventHandler.unregisterOnWXRespCallback(this.onWXResp)
   }
+  showUserInfo(){
+    // 自动恢复本地登录状态
+    this.isLogin = PreferencesUtil.getBooleanSync('isLogin', false);
+    this.userId = PreferencesUtil.getNumberSync('userId', 0);
+    this.userName = PreferencesUtil.getStringSync('userName', '未登录用户');
+    this.userAvatarUrl = PreferencesUtil.getStringSync('userAvatarUrl', '');
+    this.subscriptionName = PreferencesUtil.getStringSync('subscriptionName', '');
+    this.subscriptionEndDate = PreferencesUtil.getStringSync('subscriptionEndDate', '');
+    this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
+    this.userToken = PreferencesUtil.getStringSync('userToken', '');
+  }
 
   build() {
     Column() {
@@ -433,14 +218,14 @@ export struct UserCenter {
         // 顶部安全区
         Blank()
           .height(this.isPhoneLan() ? 0 : px2vp(AppUtil.getStatusBarHeight()))
-          .backgroundColor(this.themeColor)
+          .backgroundColor(this.isDarkMode?$r('app.color.title_bar_bg'):this.themeColor)
           .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
         // 自定义标题栏(Stack实现绝对居中)
         Stack() {
           // 居中标题
           Text('用户中心')
-            .fontSize(20)
-            .fontColor($r('app.color.text_color'))
+            .fontSize(18)
+            .fontColor(Color.White)
             .align(Alignment.Center)
           // 左右按钮
           Row() {
@@ -476,10 +261,16 @@ export struct UserCenter {
       .scrollBar(BarState.Off)
       .edgeEffect(EdgeEffect.Spring)
       .layoutWeight(1)
+      .padding({
+        bottom:45
+      })
     }
     .backgroundColor(0xFFF6F7FA)
     .width('100%')
     .height('100%')
+    .layoutWeight(1)
+
+
   }
 
   // 用户信息卡片
@@ -542,6 +333,7 @@ export struct UserCenter {
                 .width(32)
                 .height(32)
                 .margin({ bottom: 8 })
+                .fillColor(this.themeColor)
               Text(feature.title)
                 .fontSize(16)
                 .fontWeight(FontWeight.Medium)
@@ -578,41 +370,72 @@ export struct UserCenter {
   @Builder
   payDialogContentBuilder(): void {
     Column() {
-      Text('请选择支付方式')
-        .fontSize(18)
-        .fontWeight(FontWeight.Bold)
-        .margin({ bottom: 16 })
       Row() {
-        Button('微信支付')
-          .fontColor(Color.White)
-          .backgroundColor('#FF4081')
-          .height(48)
-          .layoutWeight(1)
-          .onClick(() => {
-            this.payType = 0;
-            DialogHelper.closeDialog('payDialog');
-            if (this.selectedPayPlan) {
-              void this.doPay(this.selectedPayPlan);
+        Image($r('app.media.wx_logo'))
+          .width(22)
+          .height(22)
+          .alignSelf(ItemAlign.Center)
+          .margin({ left: 25 })
+        Text('微信支付')
+          .margin({ left: 10, right: 20 })
+          .fontSize(15)
+          .fontColor(Color.Gray)
+          .fontWeight(480)
+        Blank()
+        Checkbox()
+          .select(this.payType === 0)
+          .selectedColor(this.themeColor)
+          .onChange((checked: boolean) => {
+            if (checked) {
+              this.payType = 0
             }
           })
-        Blank().width(16)
-        Button('支付宝')
-          .fontColor(Color.White)
-          .backgroundColor('#FF4081')
-          .height(48)
-          .layoutWeight(1)
-          .onClick(() => {
-            this.payType = 1;
-            DialogHelper.closeDialog('payDialog');
-            if (this.selectedPayPlan) {
-              void this.doPay(this.selectedPayPlan);
+          .shape(CheckBoxShape.CIRCLE)
+          .margin({ left: 20, top: 8, bottom: 8, right: 20 })
+          .width(22)
+          .height(22)
+      }
+      .onClick(() => {
+        this.payType = 0
+      })
+      .width('100%')
+      .height(50)
+
+      Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+
+      Row() {
+        Image($r('app.media.alipay'))
+          .width(22)
+          .height(22)
+          .alignSelf(ItemAlign.Center)
+          .margin({ left: 25 })
+        Text('支付宝')
+          .margin({ left: 10, right: 20 })
+          .fontSize(15)
+          .fontColor(Color.Gray)
+          .fontWeight(480)
+        Blank()
+        Checkbox()
+          .select(this.payType === 1)
+          .selectedColor(this.themeColor)
+          .onChange((checked: boolean) => {
+            if (checked) {
+              this.payType = 1
             }
           })
+          .shape(CheckBoxShape.CIRCLE)
+          .margin({ left: 20, top: 8, bottom: 8, right: 20 })
+          .width(22)
+          .height(22)
       }
-      .margin({ top: 8, bottom: 8 })
+      .onClick(() => {
+        this.payType = 1
+      })
+      .width('100%')
+      .height(50)
     }
     .padding(24)
-    .width('80%')
+    .width('100%')
   }
 
   // 会员套餐选择
@@ -656,13 +479,32 @@ export struct UserCenter {
               }
               this.selectedPayPlan = plan;
               DialogHelper.showCustomContentDialog({
+                // backgroundColor:$r('app.color.xpopup_bg'),
                 dialogId: 'payDialog',
                 title: '请选择支付方式',
+                backgroundColor: Color.Grey,
+                transition: AnimationHelper.transitionInUp(555),
                 autoCancel: true,
                 contentBuilder: () => {
                   this.payDialogContentBuilder();
                 },
-                buttons: []
+                buttons: [
+                  {
+                    value:"取消",
+                    // background: $r('app.color.button_click'),
+                  },
+                  {
+                    value: '确认支付',
+                    // background: $r('app.color.button_click'),
+                    // background:this.themeColor,
+                    action:()=>{
+                      if (this.selectedPayPlan) {
+                        void this.doPay(this.selectedPayPlan);
+                      }
+                      DialogHelper.closeDialog('payDialog');
+                    }
+                  },
+                ]
               });
             })
         }
@@ -686,6 +528,7 @@ export struct UserCenter {
           return
         }
         // 跳转到收藏页面
+        ToastUtil.showToast('敬请期待')
       })
       Line().width('90%').height(0.5).backgroundColor(0xFFEFEFEF)
       this.menuItem($r('app.media.icon_history'), '播放历史', () => {
@@ -694,10 +537,14 @@ export struct UserCenter {
           return
         }
         // 跳转到历史记录页面
+        ToastUtil.showToast('敬请期待')
       })
       Line().width('90%').height(0.5).backgroundColor(0xFFEFEFEF)
       this.menuItem($r('app.media.setting_red'), '设置', () => {
         // 跳转到设置页面
+        router.pushUrl({
+          url: 'pages/SettingPage'
+        });
       })
     }
     .backgroundColor(Color.White)
@@ -946,49 +793,6 @@ export struct UserCenter {
 
   // 每次进入页面时刷新用户数据
   async fetchUserInfo(token: string) {
-    try {
-      const url = `https://pay.ss5.xyz/user/info?token=${encodeURIComponent(token)}`;
-      const httpRequest = http.createHttp();
-      const options: http.HttpRequestOptions = {
-        method: http.RequestMethod.GET,
-        readTimeout: 3000,
-        connectTimeout: 3000,
-      };
-      const response: http.HttpResponse = await httpRequest.request(url, options);
-      if (response.responseCode === 200) {
-        let res = response.result as string;
-        LogUtil.debug("fetchUserInfo res =" + res);
-        let json: UserInfoApiResponse = JSON.parse(res) as UserInfoApiResponse;
-
-        if (json.code === 0 && json.data) {
-          const userInfo = json.data.user_info;
-          const systemInfo = json.data.system_info;
-          const subInfo = json.data.subscription_info;
-
-          this.isLogin = true;
-          this.userId = systemInfo.user_id ? Number(systemInfo.user_id) : 0;
-          this.userName = userInfo.nickname || '用户';
-          this.userAvatarUrl = userInfo.headimgurl || '';
-
-          if (subInfo && subInfo.has_active_subscription && subInfo.subscriptions && subInfo.subscriptions.length > 0) {
-            this.hasActiveSubscription = true;
-            this.subscriptionName = subInfo.subscriptions[0].plan_name;
-            this.subscriptionEndDate = subInfo.subscriptions[0].end_date;
-          } else {
-            this.hasActiveSubscription = false;
-            this.subscriptionName = '';
-            this.subscriptionEndDate = '';
-          }
-          ToastUtil.showToast('用户信息已更新');
-        } else {
-          ToastUtil.showToast('刷新用户信息失败');
-        }
-      } else {
-        ToastUtil.showToast('获取用户信息失败');
-      }
-    } catch (e) {
-      ToastUtil.showToast('获取用户信息异常' + (e && e.message ? (': ' + e.message) : ''));
-      hilog.error(0x0000, 'UserCenter', `fetchUserInfo error: ${e.message}`);
-    }
+    await UserUtil.fetchUserInfo(token);
   }
 }