From f942b6e016805d35c36301bf534fbbb367be4a34 Mon Sep 17 00:00:00 2001 From: 无故事王国 <841720330@qq.com> Date: 星期一, 09 十月 2023 14:20:47 +0800 Subject: [PATCH] 完善 --- WanPai/Model/CommonModels.swift | 5 ++ WanPai/Config/Enums.swift | 3 - WanPai/SceneDelegate.swift | 31 ++++++++++++--- WanPai/Root/Login/VC/BindPhoneVC.xib | 2 WanPai/Root/Login/VC/LoginVC.swift | 14 ++++--- WanPai/Network/Services.swift | 12 +++++ WanPai/Root/Login/VC/BindPhoneVC.swift | 45 +++++++++++++++++----- 7 files changed, 84 insertions(+), 28 deletions(-) diff --git a/WanPai/Config/Enums.swift b/WanPai/Config/Enums.swift index c6d0052..9d3755b 100644 --- a/WanPai/Config/Enums.swift +++ b/WanPai/Config/Enums.swift @@ -50,7 +50,6 @@ case register = 2 case updatePwd = 3 case forgotPwd = 4 - case bindPhone = 5 var titleStr:String{ switch self { @@ -62,8 +61,6 @@ return "修改密码" case .forgotPwd: return "忘记密码" - case .bindPhone: - return "绑定手机号" } } } diff --git a/WanPai/Model/CommonModels.swift b/WanPai/Model/CommonModels.swift index 6df7ab1..e76c9c4 100644 --- a/WanPai/Model/CommonModels.swift +++ b/WanPai/Model/CommonModels.swift @@ -797,3 +797,8 @@ var end_time:TimeInterval = 0 //结束时间 } +struct LoginModel:HandyJSON{ + var token = "" + var isBind = 0 +} + diff --git a/WanPai/Network/Services.swift b/WanPai/Network/Services.swift index 742eaf3..78943ec 100644 --- a/WanPai/Network/Services.swift +++ b/WanPai/Network/Services.swift @@ -120,12 +120,22 @@ return NetworkRequest.request(params: params, method: .post, progress: true) } - class func wxLogin(openId:String,nickname:String,headimgurl:String)->Observable<BaseResponse<SimpleModel>>{ + class func wxLogin(openId:String,nickname:String,headimgurl:String,sex:Int)->Observable<BaseResponse<LoginModel>>{ let params = ParamsAppender.build(url: All_Url) .interface(url: "/account/base/appUser/loginWeChat") .append(key: "openId", value: openId) .append(key: "nickname", value: nickname) .append(key: "headimgurl", value: headimgurl) + .append(key: "sex", value: sex) + return NetworkRequest.request(params: params, method: .post, progress: true) + } + + class func wxPhoneBind(phone:String,code:String,openId:String)->Observable<BaseResponse<SimpleModel>>{ + let params = ParamsAppender.build(url: All_Url) + .interface(url: "/account/base/appUser/bind") + .append(key: "phone", value: phone) + .append(key: "openId", value: openId) + .append(key: "code", value: code) return NetworkRequest.request(params: params, method: .post, progress: true) } diff --git a/WanPai/Root/Login/VC/BindPhoneVC.swift b/WanPai/Root/Login/VC/BindPhoneVC.swift index 5a1e389..71c1509 100644 --- a/WanPai/Root/Login/VC/BindPhoneVC.swift +++ b/WanPai/Root/Login/VC/BindPhoneVC.swift @@ -1,9 +1,9 @@ -// -// BindPhoneVC.swift -// WanPai -// -// Created by 无故事王国 on 2023/10/9. -// + // + // BindPhoneVC.swift + // WanPai + // + // Created by 无故事王国 on 2023/10/9. + // import UIKit import QMUIKit @@ -14,18 +14,30 @@ @IBOutlet weak var tf_phone: QMUITextField! @IBOutlet weak var tf_code: QMUITextField! @IBOutlet weak var btn_code: UIButton! + private var wxUserInfoModel:WechatUserInfoModel! + private var token:String! - override func viewDidLoad() { - super.viewDidLoad() + override func viewDidLoad() { + super.viewDidLoad() title = "绑定手机号" - } + } + + init(wxUserInfoModel:WechatUserInfoModel,token:String) { + super.init(nibName: nil, bundle: nil) + self.wxUserInfoModel = wxUserInfoModel + self.token = token + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } @IBAction func getCodeAction(_ sender: UIButton) { guard tf_phone.text!.jq_isPhone else { alert(msg: "请输入正确的手机号码");return } - Services.getSMSCode(phone: tf_phone.text!, type: .bindPhone).subscribe(onNext: {result in + Services.getSMSCode(phone: tf_phone.text!, type: .login).subscribe(onNext: {result in sender.jq_openCountDown() }) { error in alertError(msg: error.localizedDescription) @@ -41,6 +53,17 @@ alert(msg: "请输入验证码");return } + Services.wxPhoneBind(phone: tf_phone.text!, code: tf_code.text!, openId: wxUserInfoModel.openid).subscribe(onNext: {[weak self] data in + guard let weakSelf = self else { return } + if data.code == 200{ + alertSuccess(msg: "绑定成功") + UserViewModel.saveToken(weakSelf.token) + app.registerAndLoginSuccess() + }else{ + alert(msg: data.msg) + } + }) { error in + alertError(msg: error.localizedDescription) + }.disposed(by: disposeBag) } - } diff --git a/WanPai/Root/Login/VC/BindPhoneVC.xib b/WanPai/Root/Login/VC/BindPhoneVC.xib index 60eb847..cfd0a30 100644 --- a/WanPai/Root/Login/VC/BindPhoneVC.xib +++ b/WanPai/Root/Login/VC/BindPhoneVC.xib @@ -72,7 +72,7 @@ <textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="请输入验证码" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uLi-4i-BeV" customClass="QMUITextField"> <rect key="frame" x="74" y="0.0" width="98" height="40"/> <fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/> - <textInputTraits key="textInputTraits" spellCheckingType="no" keyboardType="numberPad" enablesReturnKeyAutomatically="YES" secureTextEntry="YES" smartQuotesType="no"/> + <textInputTraits key="textInputTraits" spellCheckingType="no" keyboardType="numberPad" enablesReturnKeyAutomatically="YES" smartQuotesType="no"/> <userDefinedRuntimeAttributes> <userDefinedRuntimeAttribute type="number" keyPath="maximumTextLength"> <integer key="value" value="6"/> diff --git a/WanPai/Root/Login/VC/LoginVC.swift b/WanPai/Root/Login/VC/LoginVC.swift index 9a6cc9f..bda8dc4 100644 --- a/WanPai/Root/Login/VC/LoginVC.swift +++ b/WanPai/Root/Login/VC/LoginVC.swift @@ -115,8 +115,12 @@ @IBAction func getCodeAction(_ sender: UIButton) { guard !tf_phone.text!.isEmpty else {alertError(msg: tf_phone.placeholder!);return} guard tf_phone.text!.jq_isPhone else {alertError(msg: "请输入正确的手机号");return} - Services.getSMSCode(phone: tf_phone.text!, type: .login).subscribe(onNext: {result in - sender.jq_openCountDown() + Services.getSMSCode(phone: tf_phone.text!, type: .login).subscribe(onNext: {data in + if data.code == 200{ + sender.jq_openCountDown() + }else{ + alertError(msg: data.msg) + } }) { error in alertError(msg: error.localizedDescription) }.disposed(by: disposeBag) @@ -161,10 +165,8 @@ @IBAction func wechatLoginAcion(_ sender: QMUIButton) { guard btn_reader.isSelected else {alert(msg: "请先仔细阅读并同意协议");return} - let vc = BindPhoneVC() - vc.modalPresentationStyle = .fullScreen - push(vc: vc) -// WeChatTools.sendAuthRequest() + showHUD() + WeChatTools.sendAuthRequest() } diff --git a/WanPai/SceneDelegate.swift b/WanPai/SceneDelegate.swift index 2c61928..fb1f744 100644 --- a/WanPai/SceneDelegate.swift +++ b/WanPai/SceneDelegate.swift @@ -46,12 +46,31 @@ func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { if let code = URLContexts.first?.url.jq_params?["code"]{ - let resp = SendAuthResp() - resp.code = code - WeChatTools.getAccessToken(resp) { model in - if let m = model{ - WeChatTools.getUserInfo(access_token: m.access_token, openId: m.openid) { userInfoModel in - + DispatchQueue.main.async { + hiddenHUD() + let resp = SendAuthResp() + resp.code = code + WeChatTools.getAccessToken(resp) { model in + if let m = model{ + WeChatTools.getUserInfo(access_token: m.access_token, openId: m.openid) { userInfoModel in + if let u = userInfoModel{ + Services.wxLogin(openId: u.openid, nickname: u.nickname, headimgurl: u.headimgurl, sex: u.sex).subscribe(onNext: { data in + if let m = data.data{ + if m.isBind == 0{ + let vc = BindPhoneVC(wxUserInfoModel: u,token: m.token) + JQ_currentViewController().jq_push(vc: vc) + }else{ + UserViewModel.saveToken(m.token) + app.registerAndLoginSuccess() + } + } + }) { error in + alertError(msg: error.localizedDescription) + }.disposed(by: JQ_disposeBag) + }else{ + alertError(msg: "获取信息失败") + } + } } } } -- Gitblit v1.7.1