Forráskód Böngészése

登录接口更新完成

南鑫林 5 éve
szülő
commit
e9a9efc4fb

+ 9 - 1
RainbowPlanet/RainbowPlanet/Macro/Common.swift

@@ -310,6 +310,14 @@ func getImageHeight(imgStr:String) -> CGFloat {
     return heightFloat/2
 }
 
+
+/// 获取缩略图
+///
+/// - Parameters:
+///   - imgStr: 图片地址
+///   - width: 宽度
+///   - height: 高度
+/// - Returns: 返回图片地址
 func getImageUrlStr(imgStr:String,width:CGFloat,height:CGFloat) -> String {
     if imgStr.contains("*") {
         let imgStr1 = imgStr + "?x-oss-process=image/resize,m_fill,w_\(Int(width*2)),h_\(Int(height*2))"
@@ -323,7 +331,7 @@ func getImageUrlStr(imgStr:String,width:CGFloat,height:CGFloat) -> String {
 
             return String(imgStr1)
         }else {
-            let imgStr1 = imgStr + "?x-oss-process=image/resize,m_fill,w_\(Int(560 * kScaleWidth)),h_\(Int(560 * 280 * kScaleWidth))"
+            let imgStr1 = imgStr + "?x-oss-process=image/resize,m_fill,w_\(Int(280 * 2 * kScaleWidth)),h_\(Int(280 * 2 * kScaleWidth))"
             NXLLog(imgStr1)
             return String(imgStr1)
         }

+ 12 - 0
RainbowPlanet/RainbowPlanet/Macro/EnumMacro.swift

@@ -212,3 +212,15 @@ enum RedemptionAreaBannerType : Int {
     case activity = 3
     case commodity = 4
 }
+
+
+/// 登录类型
+///
+/// - mobile: 手机登录
+/// - weixin: 微信登录
+/// - qq: qq登录
+enum LoginType : Int {
+    case mobile = 1
+    case weixin = 2
+    case qq = 3
+}

+ 58 - 13
RainbowPlanet/RainbowPlanet/Model/UserModel/UserModel.swift

@@ -21,16 +21,16 @@ public class UserModel : NSObject, NSCoding, Mappable{
     var gender : Int?
     var isPassword : Int?
     var mobile : String?
-    var openId : String?
     var token : String?
     var tokenTtl : Int?
     var uid : Int?
-    var unionId : String?
     var username : String?
     var isFollowSuggestTopic : Int?
     var isNewMember : Int?
     var inviteUid : Int?
     var inviteCode : String?
+    var bindWeixinUserModel : BindThirdPartyUserModel?
+    var bindQQUserModel : BindThirdPartyUserModel?
 
 
 	class func newInstance(map: Map) -> Mappable?{
@@ -45,16 +45,16 @@ public class UserModel : NSObject, NSCoding, Mappable{
         gender <- map["gender"]
         isPassword <- map["is_password"]
         mobile <- map["mobile"]
-        openId <- map["open_id"]
         token <- map["token"]
         tokenTtl <- map["token_ttl"]
         uid <- map["uid"]
-        unionId <- map["union_id"]
         isFollowSuggestTopic <- map["is_follow_suggest_topic"]
         isNewMember <- map["is_new_member"]
         inviteUid <- map["invite_uid"]
         inviteCode <- map["invite_code"]
         username <- map["username"]
+        bindWeixinUserModel <- map["bind_weixin"]
+        bindQQUserModel <- map["bind_qq"]
 		
 	}
 
@@ -69,16 +69,16 @@ public class UserModel : NSObject, NSCoding, Mappable{
         gender = aDecoder.decodeObject(forKey: "gender") as? Int
         isPassword = aDecoder.decodeObject(forKey: "is_password") as? Int
         mobile = aDecoder.decodeObject(forKey: "mobile") as? String
-        openId = aDecoder.decodeObject(forKey: "open_id") as? String
         token = aDecoder.decodeObject(forKey: "token") as? String
         tokenTtl = aDecoder.decodeObject(forKey: "token_ttl") as? Int
         uid = aDecoder.decodeObject(forKey: "uid") as? Int
-        unionId = aDecoder.decodeObject(forKey: "union_id") as? String
         username = aDecoder.decodeObject(forKey: "username") as? String
         isFollowSuggestTopic = aDecoder.decodeObject(forKey: "is_follow_suggest_topic") as? Int
         isNewMember = aDecoder.decodeObject(forKey: "is_new_member") as? Int
         inviteUid = aDecoder.decodeObject(forKey: "invite_uid") as? Int
         inviteCode = aDecoder.decodeObject(forKey: "invite_code") as? String
+        bindWeixinUserModel = aDecoder.decodeObject(forKey: "bind_weixin") as? BindThirdPartyUserModel
+        bindQQUserModel = aDecoder.decodeObject(forKey: "bind_qq") as? BindThirdPartyUserModel
 
 	}
 
@@ -103,9 +103,6 @@ public class UserModel : NSObject, NSCoding, Mappable{
         if mobile != nil{
             aCoder.encode(mobile, forKey: "mobile")
         }
-        if openId != nil{
-            aCoder.encode(openId, forKey: "open_id")
-        }
         if token != nil{
             aCoder.encode(token, forKey: "token")
         }
@@ -115,9 +112,6 @@ public class UserModel : NSObject, NSCoding, Mappable{
         if uid != nil{
             aCoder.encode(uid, forKey: "uid")
         }
-        if unionId != nil{
-            aCoder.encode(unionId, forKey: "union_id")
-        }
         if username != nil{
             aCoder.encode(username, forKey: "username")
         }
@@ -134,6 +128,12 @@ public class UserModel : NSObject, NSCoding, Mappable{
         if inviteCode != nil{
             aCoder.encode(inviteCode, forKey: "invite_code")
         }
+        if bindWeixinUserModel != nil{
+            aCoder.encode(bindWeixinUserModel, forKey: "bind_weixin")
+        }
+        if bindQQUserModel != nil{
+            aCoder.encode(bindQQUserModel, forKey: "bind_qq")
+        }
 
 	}
 
@@ -194,9 +194,54 @@ public class UserModel : NSObject, NSCoding, Mappable{
             return false
         }
     }
+
+}
+
+class BindThirdPartyUserModel : NSObject, NSCoding, Mappable{
     
+    var openId : String?
+    var unionId : String?
+    
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return BindThirdPartyUserModel()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        openId <- map["open_id"]
+        unionId <- map["union_id"]
+        
+    }
+    
+    /**
+     * NSCoding required initializer.
+     * Fills the data from the passed decoder
+     */
+    @objc required init(coder aDecoder: NSCoder)
+    {
+        openId = aDecoder.decodeObject(forKey: "open_id") as? String
+        unionId = aDecoder.decodeObject(forKey: "union_id") as? String
+        
+    }
+    
+    /**
+     * NSCoding required method.
+     * Encodes mode properties into the decoder
+     */
+    @objc func encode(with aCoder: NSCoder)
+    {
+        if openId != nil{
+            aCoder.encode(openId, forKey: "open_id")
+        }
+        if unionId != nil{
+            aCoder.encode(unionId, forKey: "union_id")
+        }
+        
+    }
     
-
 }
 
 

+ 2 - 2
RainbowPlanet/RainbowPlanet/Modules/MineModule/AccountSecurity/View/AccountSecurityTableViewCell.swift

@@ -127,10 +127,10 @@ class AccountSecurityTableViewCell: UITableViewCell {
                 break
             case 1:
                 accountSecurityLabel.isHidden = true
-                if userModel?.unionId == nil || userModel?.unionId == "" {
+                if userModel?.bindWeixinUserModel?.unionId == nil || userModel?.bindWeixinUserModel?.unionId == "" {
                     detailsLabel.text = "未绑定"
                 }else {
-                    detailsLabel.text = "解除绑定"
+                    detailsLabel.text = "绑定"
                 }
                 break
             default:

+ 5 - 5
RainbowPlanet/RainbowPlanet/Modules/MineModule/AccountSecurity/ViewController/AccountSecurityViewController.swift

@@ -91,17 +91,17 @@ class AccountSecurityViewController: BaseViewController {
     ///
     /// - Parameter userModel: 用户
     func setWeiXin(userModel:UserModel?) {
-        if userModel?.unionId == nil ||  userModel?.unionId == "" { //绑定微信
+        if userModel?.bindWeixinUserModel?.unionId == nil ||  userModel?.bindWeixinUserModel?.unionId == "" { //绑定微信
             UMManager.shared.loginGetUserInfo(platformType: UMSocialPlatformType.wechatSession) { (wxLoginModel) -> (Void) in
-                SwiftMoyaNetWorkServiceUser.shared().userIsBindWeixinBindApi(umLoginModel: wxLoginModel, completion: { [weak self] (data) -> (Void) in
+                SwiftMoyaNetWorkServiceUser.shared().userIsBindWeixinBindApi(loginType:.weixin,umLoginModel: wxLoginModel, completion: { [weak self] (data) -> (Void) in
                     self?.accountSecurityView.tableView.reloadData()
                     
                 })
             }
         }else { //解绑微信
-            SwiftMoyaNetWorkServiceUser.shared().userUnbindWeixinApi(completion: { [weak self] (data) -> (Void) in
-                self?.accountSecurityView.tableView.reloadData()
-            })
+//            SwiftMoyaNetWorkServiceUser.shared().userUnbindWeixinApi(completion: { [weak self] (data) -> (Void) in
+//                self?.accountSecurityView.tableView.reloadData()
+//            })
         }
     }
     

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/RegisterLoginModule/BindPhoneNumber/ViewController/BindPhoneNumberViewController.swift

@@ -51,7 +51,7 @@ class BindPhoneNumberViewController: BaseViewController {
         }
         bindPhoneNumberView.loginBlock = {
             [weak self] (phoneNumber,sms,invitationCode) in
-            SwiftMoyaNetWorkServiceUser.shared().userBindMobileApi(mobile: phoneNumber, smsCode: sms, unionId: self?.userModel?.unionId ?? "", openId: self?.userModel?.openId ?? "", invitationCode: invitationCode, completion: { [weak self] (data) -> (Void) in
+            SwiftMoyaNetWorkServiceUser.shared().userBindMobileApi(mobile: phoneNumber, smsCode: sms, unionId: self?.userModel?.bindWeixinUserModel?.unionId ?? "", openId: self?.userModel?.bindWeixinUserModel?.unionId ?? "", invitationCode: invitationCode, completion: { [weak self] (data) -> (Void) in
                 if self?.bindPhoneNumberVCType == .weixinlogin { //跳转性别
                     // 设置友盟别名
                     UMManager.shared.addAlias()

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/RegisterLoginModule/RegisterLogin/ViewController/RegisterLoginViewController.swift

@@ -42,7 +42,7 @@ class RegisterLoginViewController: BaseViewController {
             UMManager.shared.loginGetUserInfo(platformType: UMSocialPlatformType.wechatSession) { (userModel) -> (Void) in
                 let wxLoginModel = userModel
 
-                SwiftMoyaNetWorkServiceUser.shared().userWeiXinRegisterApi(open_id: wxLoginModel.open_id, union_id: wxLoginModel.union_id, avatar: wxLoginModel.avatar, username: wxLoginModel.username, gender: wxLoginModel.gender, completion: { (userModel) -> (Void) in
+                SwiftMoyaNetWorkServiceUser.shared().userWeiXinRegisterApi(loginType:.weixin,open_id: wxLoginModel.open_id, union_id: wxLoginModel.union_id, avatar: wxLoginModel.avatar, username: wxLoginModel.username, gender: wxLoginModel.gender, completion: { (userModel) -> (Void) in
                     let userModel =  userModel as! UserModel
                     if (userModel.mobile != nil && userModel.mobile != "" ) {
 

+ 18 - 10
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceUser/SwiftMoyaNetWorkServiceUser.swift

@@ -31,13 +31,14 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
     ///   - username: 昵称
     ///   - gender: 性别 1男 2女
     ///   - completion: 回调
-    func userWeiXinRegisterApi(open_id:String,union_id:String,avatar:String,username:String,gender:Int,completion: @escaping successCallBack) {
+    func userWeiXinRegisterApi(loginType:LoginType = .weixin,open_id:String,union_id:String,avatar:String,username:String,gender:Int,completion: @escaping successCallBack) {
         var parameters = Dictionary<String,Any>()
         parameters.updateValue(open_id, forKey: "open_id")
         parameters.updateValue(union_id, forKey: "union_id")
         parameters.updateValue(avatar, forKey: "avatar")
         parameters.updateValue(username, forKey: "username")
         parameters.updateValue(gender, forKey: "gender")
+        parameters.updateValue(loginType.rawValue, forKey: "login_type")
         
         SwiftMoyaNetWorkManager.shared.requestObject(UserModel.self,target: MultiTarget(SwiftMoyaServiceUserApi.userWeiXinRegister(parameters: parameters))) { (userModel) in
             let userModel = userModel as! UserModel
@@ -169,7 +170,7 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
     /// - Parameters:
     ///   - umLoginModel: UMLoginModel
     ///   - completion: 回调
-    func userIsBindWeixinBindApi(umLoginModel:UMLoginModel,completion: @escaping successCallBack) {
+    func userIsBindWeixinBindApi(loginType:LoginType = .weixin,umLoginModel:UMLoginModel,completion: @escaping successCallBack) {
         var parameters = Dictionary<String,Any>()
         parameters.updateValue(umLoginModel.union_id, forKey: "union_id")
         parameters.updateValue(umLoginModel.open_id, forKey: "open_id")
@@ -180,19 +181,25 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
             if rootModel.code == 0 {
                 
 
-                self?.userBindWeixinApi(mobile: UserModel.shared().getModel()?.mobile ?? "", umLoginModel: umLoginModel, completion: completion)
+                self?.userBindWeixinApi(loginType:loginType, mobile: UserModel.shared().getModel()?.mobile ?? "", umLoginModel: umLoginModel, completion: completion)
 
             }else if rootModel.code == 1 {
-                
 
-                AlertSheetView.alert(title: rootModel.msg ?? "此微信号被其他账号绑定,是否要将此微信号绑定至本账号,并解绑另一起账号?", cancelTitle: "取消", sureTitle: "确认", cancelBlock: { (popupView, index, string) in
+                var nameStr : String = "微信"
+                if loginType == .weixin {
+                    nameStr = "微信"
+                }else if loginType == .qq {
+                    nameStr = "QQ"
+                }
+
+                AlertSheetView.alert(title: rootModel.msg ?? "此\(nameStr)号被其他账号绑定,是否要将此\(nameStr)号绑定至本账号,并解绑另一起账号?", cancelTitle: "取消", sureTitle: "确认", cancelBlock: { (popupView, index, string) in
                     
                 }, confirmBlock: { (popupView, index, string) in
-                    AlertSheetView.alert(title: "确认后,原账号将无法以此微信登录,请确保原账号有其他登录方式,否则原账号将无法登录", cancelTitle: "取消", sureTitle: "确认", cancelBlock: { (popupView, index, string) in
+                    AlertSheetView.alert(title: "确认后,原账号将无法以此\(nameStr)登录,请确保原账号有其他登录方式,否则原账号将无法登录", cancelTitle: "取消", sureTitle: "确认", cancelBlock: { (popupView, index, string) in
                         
                     }, confirmBlock: {
                         [weak self] (popupView, index, string) in
-                        self?.userBindWeixinApi(mobile: UserModel.shared().getModel()?.mobile ?? "", umLoginModel: umLoginModel, completion: completion)
+                        self?.userBindWeixinApi(loginType:loginType,mobile: UserModel.shared().getModel()?.mobile ?? "", umLoginModel: umLoginModel, completion: completion)
 
                     })
                 })
@@ -212,7 +219,7 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
     ///   - mobile: 手机号
     ///   - umLoginModel: 微信模型
     ///   - completion: 回调
-    func userBindWeixinApi(mobile:String,umLoginModel:UMLoginModel,completion: @escaping successCallBack) {
+    func userBindWeixinApi(loginType:LoginType = .weixin,mobile:String,umLoginModel:UMLoginModel,completion: @escaping successCallBack) {
         
         if isMobileVerification(mobile: mobile) {
             var parameters = Dictionary<String,Any>()
@@ -222,6 +229,7 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
             parameters.updateValue(umLoginModel.avatar, forKey: "avatar")
             parameters.updateValue(umLoginModel.username, forKey: "username")
             parameters.updateValue(umLoginModel.gender, forKey: "gender")
+            parameters.updateValue(umLoginModel.gender, forKey: "gender")
             
             
             SwiftMoyaNetWorkManager.shared.requestObject(UserModel.self,target: MultiTarget(SwiftMoyaServiceUserApi.userBindWeixin(parameters: parameters))) { (userModel) in
@@ -246,8 +254,8 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
     func userUnbindWeixinApi(completion: @escaping successCallBack) {
         var parameters = Dictionary<String,Any>()
         let userModel = UserModel.shared().getModel()
-        parameters.updateValue(userModel!.unionId! as Any, forKey: "union_id")
-        parameters.updateValue(userModel!.openId! as Any, forKey: "open_id")
+        parameters.updateValue(userModel?.bindWeixinUserModel?.unionId as Any, forKey: "union_id")
+        parameters.updateValue(userModel?.bindWeixinUserModel?.unionId as Any, forKey: "open_id")
         if userModel?.mobile == nil ||  userModel?.mobile == "" {
             SwiftProgressHUD.shared().showText("暂时不可以解绑,请先绑定手机号")
         }else {