From d7213a2599c0abcef0dc94db37c45da5dee497f2 Mon Sep 17 00:00:00 2001
From: 杨锴 <841720330@qq.com>
Date: 星期二, 19 十一月 2024 09:28:39 +0800
Subject: [PATCH] fix bug

---
 XQMuse/Root/Course/VC/CourseDetialVC.swift         |    2 
 XQMuse/Root/Network/ViewModels/UserViewModel.swift |   16 +++++++-
 XQMuse/Root/Course/VC/CourseDetialOfflineVC.swift  |    2 
 XQMuse/Root/Login/VC/UpdatePhoneVC.swift           |   38 +++++++++++++++----
 XQMuse/SceneDelegate.swift                         |   24 +++++++----
 XQMuse/Root/Login/LoginVC.swift                    |    4 +-
 XQMuse/Root/Network/Services.swift                 |   14 ++++--
 7 files changed, 72 insertions(+), 28 deletions(-)

diff --git a/XQMuse/Root/Course/VC/CourseDetialOfflineVC.swift b/XQMuse/Root/Course/VC/CourseDetialOfflineVC.swift
index 3df7d86..1701ec4 100644
--- a/XQMuse/Root/Course/VC/CourseDetialOfflineVC.swift
+++ b/XQMuse/Root/Course/VC/CourseDetialOfflineVC.swift
@@ -168,7 +168,7 @@
 
         let path = courseDetailModel!.courseType == .offline ? "/courseDetail/offLine":"/courseDetail/onLine"
         let string = String(format: "%@%@?courseId=%ld", ShareUrl,path,m.id)
-        ShareView.show(URL(string: string)!,title: "传递心灵温暖,一起感受疗愈力量",desc: m.description)
+        ShareView.show(URL(string: string)!,title: "传递心灵温暖,一起感受疗愈力量",desc: m.courseTitle)
     }
 
     override var preferredStatusBarStyle: UIStatusBarStyle{
diff --git a/XQMuse/Root/Course/VC/CourseDetialVC.swift b/XQMuse/Root/Course/VC/CourseDetialVC.swift
index b7c0d94..ff21e26 100644
--- a/XQMuse/Root/Course/VC/CourseDetialVC.swift
+++ b/XQMuse/Root/Course/VC/CourseDetialVC.swift
@@ -254,7 +254,7 @@
 
         let path = courseDetailModel!.courseType == .offline ? "/courseDetail/offLine":"/courseDetail/onLine"
         let string = String(format: "%@%@?courseId=%ld", ShareUrl,path,m.id)
-        ShareView.show(URL(string: string)!,title: "传递心灵温暖,一起感受疗愈力量",desc: m.description)
+        ShareView.show(URL(string: string)!,title: "传递心灵温暖,一起感受疗愈力量",desc: m.courseTitle)
     }
 
 				@objc func handleAction(_ btn:QMUIButton){
diff --git a/XQMuse/Root/Login/LoginVC.swift b/XQMuse/Root/Login/LoginVC.swift
index 6c7dcdd..6d45451 100644
--- a/XQMuse/Root/Login/LoginVC.swift
+++ b/XQMuse/Root/Login/LoginVC.swift
@@ -194,7 +194,7 @@
             alert(msg: "请阅读并同意《用户注册协议》和《用户隐私协议》");return
 								}
 
-								Services.loginBy(phone: viewModel.loginPhone.value, content: viewModel.loginContent.value, type: viewModel.loginType.value).subscribe(onNext: { data in
+								Services.loginBy(phone: viewModel.loginPhone.value, content: viewModel.loginContent.value, type: viewModel.loginType.value, device: UserViewModel.DeviceUUID).subscribe(onNext: { data in
 												if let model = data.data{
 																self.dismiss(animated: true)
 
@@ -287,7 +287,7 @@
     func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
         if let credential = authorization.credential as? ASAuthorizationAppleIDCredential{
 
-            Services.loginByApple(appleId: credential.user).subscribe(onNext: {data in
+            Services.loginByApple(appleId: credential.user,device: UserViewModel.DeviceUUID).subscribe(onNext: {data in
                 if var m = data.data{
                     if m.bindStatus == 2{
                         sceneDelegate?.loginSuccess()
diff --git a/XQMuse/Root/Login/VC/UpdatePhoneVC.swift b/XQMuse/Root/Login/VC/UpdatePhoneVC.swift
index ec92c2d..6ab3a5c 100644
--- a/XQMuse/Root/Login/VC/UpdatePhoneVC.swift
+++ b/XQMuse/Root/Login/VC/UpdatePhoneVC.swift
@@ -12,6 +12,7 @@
 
 class UpdatePhoneVC: BaseVC {
     private var credential:ASAuthorizationAppleIDCredential?
+    private var wechatInfoModel:WechatUserInfoModel?
     private var firstAccessToken:String? //后端问题,要把上次的token带过来
     @IBOutlet weak var tf_phone: QMUITextField!
     @IBOutlet weak var tf_code: QMUITextField!
@@ -19,9 +20,10 @@
     @IBOutlet weak var btn_isRead: UIButton!
 
 
-    init(credential:ASAuthorizationAppleIDCredential? = nil,firstAccessToken:String?) {
+    init(credential:ASAuthorizationAppleIDCredential? = nil,wechatInfoModel:WechatUserInfoModel? = nil,firstAccessToken:String?) {
         super.init(nibName: nil, bundle: nil)
         self.credential = credential
+        self.wechatInfoModel = wechatInfoModel
         self.firstAccessToken = firstAccessToken
     }
     
@@ -91,24 +93,44 @@
         guard tf_code.text!.count == 6 else {
             alertError(msg: "请输入6位验证码");return
         }
-        guard let credentialUser = credential?.user else {
-            alertError(msg: "Apple登录授权异常");return
+
+        var threePlantformLoginType:ThreePlantformLoginType!
+        var formatName:String!
+        var unionId:String!
+
+        if credential != nil{
+            threePlantformLoginType = .apple
+            guard let credentialUser = credential?.user else {
+                alertError(msg: "Apple登录授权异常");return
+            }
+
+            formatName = String(format: "%@%@%@", credential?.fullName?.familyName ?? "",credential?.fullName?.middleName ?? "", credential?.fullName?.middleName ?? "")
+
+            unionId = credential!.user
         }
 
-        let formatName = String(format: "%@%@%@", credential?.fullName?.familyName ?? "",credential?.fullName?.middleName ?? "", credential?.fullName?.middleName ?? "")
+        if wechatInfoModel != nil{
+            threePlantformLoginType = .wechat
+            guard  !(wechatInfoModel?.openid.isEmpty ?? true) else {
+                alertError(msg: "Apple登录授权异常");return
+            }
+            formatName = wechatInfoModel?.nickname ?? ""
+            unionId = wechatInfoModel!.openid
+        }
 
-        Services.confirmByApple(cellPhone: tf_phone.text!, captcha: tf_code.text!, loginType: .apple, wxOrAppleId: credentialUser,name: formatName, mail: credential!.email).subscribe(onNext: {data in
+
+        Services.confirmByApple(cellPhone: tf_phone.text!, captcha: tf_code.text!, loginType: threePlantformLoginType, wxOrAppleId: unionId,name: formatName, mail: credential!.email).subscribe(onNext: {data in
             if var model = data.data{
                 model.loginByAppleToken = String(data: self.credential!.identityToken!, encoding: .utf8)
-                model.accessToken = self.firstAccessToken ?? ""
+                model.accessToken = model.accessToken
                 model.appleId = self.credential!.user
-                sceneDelegate?.loginSuccess()
-                NotificationCenter.default.post(name: LoginDismiss_Noti, object: nil, userInfo: nil)
                 UserViewModel.saveLoginInfo(model)
 
                 Services.getUserInfo().subscribe(onNext: {data in
                     if let model = data.data{
                         UserViewModel.saveAvatarInfo(model)
+                        sceneDelegate?.loginSuccess()
+                        NotificationCenter.default.post(name: LoginDismiss_Noti, object: nil, userInfo: nil)
                     }
                 }).disposed(by: self.disposeBag)
             }
diff --git a/XQMuse/Root/Network/Services.swift b/XQMuse/Root/Network/Services.swift
index ef102bb..80b49f4 100644
--- a/XQMuse/Root/Network/Services.swift
+++ b/XQMuse/Root/Network/Services.swift
@@ -13,8 +13,8 @@
 import CoreLocation
 
 #if DEBUG
-let All_Url = "https://xq.xqzhihui.com/api"
-//let All_Url = "http://192.168.110.64:9000"
+//let All_Url = "https://xq.xqzhihui.com/api"
+let All_Url = "http://192.168.110.64:9000"
 //let All_Url = "https://mock.apipost.net/mock/31b303c60464000"
 #else
 let All_Url = "https://xq.xqzhihui.com/api"
@@ -31,7 +31,7 @@
 extension Services{
 
 				/// 密码登录
-				class func loginBy(phone:String,content:String,type:LoginType)->Observable<BaseResponse<LoginUserInfoModel>>{
+    class func loginBy(phone:String,content:String,type:LoginType,device:String)->Observable<BaseResponse<LoginUserInfoModel>>{
 								let params = ParamsAppender.build(url: All_Url)
 
 								switch type {
@@ -39,32 +39,36 @@
 																params.interface(url: "/auth/app/login")
 																				.append(key: "cellPhone", value: phone)
 																				.append(key: "password", value: content.jq_md5String())
+                    .append(key: "device",value:device)
 																				.append(key: "apipost_id", value: "246d780670e267")
 												case .code:
 																params.interface(url: "/auth/app/captchaLogin")
 																				.append(key: "cellPhone", value: phone)
 																				.append(key: "captcha",value:content)
+                    .append(key: "device",value:device)
 																				.append(key: "apipost_id", value: "246d780670e265")
 								}
         return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding(), progress: true)
 				}
 
 
-    class func loginByApple(appleId:String)->Observable<BaseResponse<LoginUserInfoModel>>{
+    class func loginByApple(appleId:String,device:String)->Observable<BaseResponse<LoginUserInfoModel>>{
         let params = ParamsAppender.build(url: All_Url)
         params.interface(url: "/auth/app/appleLogin")
             .append(key: "appleId", value: appleId)
+            .append(key: "device", value: device)
             .append(key: "apipost_id", value: "246d780670e264")
         return NetworkRequest.request(params: params, method: .post, progress: true)
     }
 
-    class func loginByWechat(headImgUrl:String,nickname:String,sex:Int,wxOpenId:String)->Observable<BaseResponse<LoginUserInfoModel>>{
+    class func loginByWechat(headImgUrl:String,nickname:String,sex:Int,wxOpenId:String,device:String)->Observable<BaseResponse<LoginUserInfoModel>>{
         let params = ParamsAppender.build(url: All_Url)
         params.interface(url: "/auth/app/wxLogin")
             .append(key: "headImgUrl", value: headImgUrl)
             .append(key: "nickname", value: nickname)
             .append(key: "sex", value: sex)
             .append(key: "wxOpenId", value: wxOpenId)
+            .append(key: "device", value: device)
             .append(key: "apipost_id", value: "246d7806b0e26c")
         return NetworkRequest.request(params: params, method: .post,encoding: JSONEncoding(), progress: true)
     }
diff --git a/XQMuse/Root/Network/ViewModels/UserViewModel.swift b/XQMuse/Root/Network/ViewModels/UserViewModel.swift
index 86f4104..5771818 100644
--- a/XQMuse/Root/Network/ViewModels/UserViewModel.swift
+++ b/XQMuse/Root/Network/ViewModels/UserViewModel.swift
@@ -36,8 +36,20 @@
 }
 
 class UserViewModel{
-				private static let userLoginInfo = UserDefaultsStore<LoginUserInfoModel>(uniqueIdentifier: "userLoginInfo")!
-				private static let userAvatarInfo = UserDefaultsStore<UserInfoModel>(uniqueIdentifier: "userAvatarInfo")!
+    private static let userLoginInfo = UserDefaultsStore<LoginUserInfoModel>(uniqueIdentifier: "userLoginInfo")!
+    private static let userAvatarInfo = UserDefaultsStore<UserInfoModel>(uniqueIdentifier: "userAvatarInfo")!
+
+    //用户UUID
+    static var DeviceUUID:String{
+        if let uuid = UserDefaults.standard.value(forKey: "device_UUID") as? String{
+            return uuid
+        }else{
+            let uuid = UUID().uuidString
+            UserDefaults.standard.set(uuid, forKey: "device_UUID")
+            UserDefaults.standard.synchronize()
+            return uuid
+        }
+    }
 
 				static func getToken()->String?{
 								return UserDefaults.standard.object(forKey: "_userToken") as? String
diff --git a/XQMuse/SceneDelegate.swift b/XQMuse/SceneDelegate.swift
index e8e2070..64ec8bb 100644
--- a/XQMuse/SceneDelegate.swift
+++ b/XQMuse/SceneDelegate.swift
@@ -103,17 +103,23 @@
                             WeChatTools.getUserInfo(access_token: m.access_token, openId: m.openid) { userInfoModel in
                                 if let u = userInfoModel{
                                     if UserViewModel.getAvatarInfo().wxOpenId.isEmpty{
-                                        Services.loginByWechat(headImgUrl: u.headimgurl, nickname: u.nickname, sex: u.sex, wxOpenId: u.openid).subscribe(onNext: {data in
+                                        Services.loginByWechat(headImgUrl: u.headimgurl, nickname: u.nickname, sex: u.sex, wxOpenId: u.openid, device: UserViewModel.DeviceUUID).subscribe(onNext: {data in
                                             if let model = data.data{
-                                                sceneDelegate?.loginSuccess()
-                                                JQ_currentViewController().dismiss(animated:true)
-                                                UserViewModel.saveLoginInfo(model)
 
-                                                Services.getUserInfo().subscribe(onNext: {data in
-                                                    if let model = data.data{
-                                                        UserViewModel.saveAvatarInfo(model)
-                                                    }
-                                                }).disposed(by: JQ_disposeBag)
+                                                if model.bindStatus == 2{
+                                                    sceneDelegate?.loginSuccess()
+                                                    JQ_currentViewController().dismiss(animated:true)
+                                                    UserViewModel.saveLoginInfo(model)
+
+                                                    Services.getUserInfo().subscribe(onNext: {data in
+                                                        if let model = data.data{
+                                                            UserViewModel.saveAvatarInfo(model)
+                                                        }
+                                                    }).disposed(by: JQ_disposeBag)
+                                                }else{
+                                                    let vc = UpdatePhoneVC(wechatInfoModel: u,firstAccessToken: model.accessToken)
+                                                    JQ_currentViewController().jq_push(vc: vc)
+                                                }
                                             }
                                         }).disposed(by: JQ_disposeBag)
                                     }else{

--
Gitblit v1.7.1