|
|
@@ -4,147 +4,24 @@ 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';
|
|
|
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> {
|
|
|
@@ -241,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();
|
|
|
@@ -268,7 +153,8 @@ export struct UserCenter {
|
|
|
// 微信支付成功回调
|
|
|
ToastUtil.showToast('支付成功!');
|
|
|
// 可在此处刷新会员状态或其他支付成功后的业务逻辑
|
|
|
- this.fetchVipPlans(); // 刷新会员套餐信息
|
|
|
+ // this.fetchVipPlans(); // 刷新会员套餐信息
|
|
|
+ void this.fetchUserInfo(this.userToken);
|
|
|
} else {
|
|
|
// 其他类型的成功回调
|
|
|
ToastUtil.showToast('操作成功!');
|
|
|
@@ -288,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) {
|
|
|
@@ -423,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() {
|
|
|
@@ -431,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() {
|
|
|
@@ -474,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)
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 用户信息卡片
|
|
|
@@ -540,6 +333,7 @@ export struct UserCenter {
|
|
|
.width(32)
|
|
|
.height(32)
|
|
|
.margin({ bottom: 8 })
|
|
|
+ .fillColor(this.themeColor)
|
|
|
Text(feature.title)
|
|
|
.fontSize(16)
|
|
|
.fontWeight(FontWeight.Medium)
|
|
|
@@ -576,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%')
|
|
|
}
|
|
|
|
|
|
// 会员套餐选择
|
|
|
@@ -654,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');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ]
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
@@ -684,6 +528,7 @@ export struct UserCenter {
|
|
|
return
|
|
|
}
|
|
|
// 跳转到收藏页面
|
|
|
+ ToastUtil.showToast('敬请期待')
|
|
|
})
|
|
|
Line().width('90%').height(0.5).backgroundColor(0xFFEFEFEF)
|
|
|
this.menuItem($r('app.media.icon_history'), '播放历史', () => {
|
|
|
@@ -692,10 +537,14 @@ export struct UserCenter {
|
|
|
return
|
|
|
}
|
|
|
// 跳转到历史记录页面
|
|
|
+ ToastUtil.showToast('敬请期待')
|
|
|
})
|
|
|
Line().width('90%').height(0.5).backgroundColor(0xFFEFEFEF)
|
|
|
- this.menuItem($r('app.media.setting'), '设置', () => {
|
|
|
+ this.menuItem($r('app.media.setting_red'), '设置', () => {
|
|
|
// 跳转到设置页面
|
|
|
+ router.pushUrl({
|
|
|
+ url: 'pages/SettingPage'
|
|
|
+ });
|
|
|
})
|
|
|
}
|
|
|
.backgroundColor(Color.White)
|
|
|
@@ -926,10 +775,12 @@ export struct UserCenter {
|
|
|
|
|
|
async doAliPay(plan: VipPlanApi) {
|
|
|
const appName = PreferencesUtil.getStringSync('appName', 'TTMusic');
|
|
|
- OrderInfoUtil.getOrderInfo(Number(plan.price), appName).then((orderInfo) => {
|
|
|
+ OrderInfoUtil.getOrderInfo(Number(plan.price), appName, this.userId, plan.id).then((orderInfo) => {
|
|
|
+ console.log('Heanup: alipay orderInfo = '+json.stringify(orderInfo))
|
|
|
new Pay().pay(orderInfo, true).then(async (result) => {
|
|
|
if (result.get('resultStatus') === '9000') {
|
|
|
ToastUtil.showToast('支付成功!');
|
|
|
+ void this.fetchUserInfo(this.userToken);
|
|
|
// 可在此处刷新会员状态
|
|
|
} else {
|
|
|
ToastUtil.showToast('取消支付!');
|
|
|
@@ -942,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);
|
|
|
}
|
|
|
}
|