开发版本-developer——01 first commit

This commit is contained in:
wbzhan
2019-07-08 18:24:03 +08:00
parent 5a10dfa182
commit 8693efe121
386 changed files with 7069 additions and 1951 deletions
@@ -0,0 +1,106 @@
//
// MtopAuthProtocol.h
// OpenMtopExt
//
// Created by 亿刀 on 16/7/11.
// Copyright © 2016年 亿刀. All rights reserved.
//
#import <Foundation/Foundation.h>
/*!
* 授权标记
*/
typedef enum {
/* 只走AutoAuth,失败什么都不做! */
AuthOptionAutoAuthOnly = 1,
/* 先走AutoAuth,失败再拉授权页面 */
AuthOptionAutoAuthAndManualAuth,
} AuthOption;
/*!
* 授权成功回调
* @param isSuccessful YES表示授权成功(auto auth或者manual auth)NO表示授权失败(只可能发生在authOptionAutoauthOnly
* @param authResult 授权成功的情况下返回的授权结果(包含授权态)
*/
typedef void (^AUTH_COMPLETION_HANDLER) (BOOL isSuccessful, NSDictionary* authResult);
/*!
* 授权取消回调
* @param flags 用户手动取消授权页面
*/
typedef void (^AUTH_CANCELATION_HANDLER)();
@protocol MtopAuthProtocol <NSObject>
@required
/*!
* 获取单例
*/
+ (id)sharedInstantce;
/*!
* 判断当前用户是否有授权会话
* @return
* YES 本地有会话且本地判断会话未过期,但服务端可能判定会话无效
* NO 本地无会话或本地判断会话已过期
*/
- (BOOL)isValidAuth;
/*
* 触发授权操作
* @param authOption 授权选项 参看 <code>authOption</code>
* @param completionHandler 授权成功后回调
* @param cancelationHandler 授权用户取消后回调
*/
- (void)authWithAuthOption:(AuthOption)authOption
completionHandler:(AUTH_COMPLETION_HANDLER)completionHandler
cancelationHandler:(AUTH_CANCELATION_HANDLER)cancelationHandler;
/*
* 基本同上,一般业务方不要使用此方法,需要使用此方法,请联系@寻弦
* @param extraInfoDict 额外参数
*/
- (void)authWithAuthOption:(AuthOption)authOption
extraInfo:(NSDictionary *)extraInfoDict
completionHandler:(AUTH_COMPLETION_HANDLER)completionHandler
cancelationHandler:(AUTH_CANCELATION_HANDLER)cancelationHandler;
/*!
* 获取当前授权会话信息
* @return
* 会话信息
* sid -> session id (NSString*)
* userId -> 用户id (NSString*)
* ecode -> ecode (NSString*)
* nick -> 用户nick (NSString*)
* authToken -> 授权令牌 (NSString*)
* ssoToken -> sso令牌 (NSString*)
* topSession -> top授权 (NSString*)
* cookie -> cookie (NSString*)
* ......
*/
- (NSDictionary *)currentSession;
/*!
* 返回当前authCenter是否已经在处理授权行为
* @return YES 已经有在处理中的授权行为
* NO 没有正在处理的授权行为
*/
- (BOOL)isProcessingAuth;
/*!
* 标识本地auth已经失效
*/
- (void)markInvalidAuth;
@end
@@ -0,0 +1,22 @@
//
// MtopError.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/15.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MtopError : NSObject
// 错误码
@property(strong, nonatomic) NSString *code;
// 错误提示信息
@property(strong, nonatomic) NSString *msg;
// 原始的错误
@property(strong, nonatomic) NSError *rawError;
@end
@@ -0,0 +1,21 @@
//
// MtopErrorDefine.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/7/1.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#ifndef MtopErrorDefine_h
#define MtopErrorDefine_h
#endif /* MtopErrorDefine_h */
#pragma mark - error code
#define k_MTOP_LOCAL_ERROR_CODE_NO_LOGIN_MODEL @"MTOP_LOCAK_ERROR_NO_LOGIN_MODEL"
#define k_MTOP_LOCAL_ERROR_MSG_NO_LOGIN_MODEL @"没有找到登录模块"
#define k_MTOP_LOCAL_ERROR_CODE_NO_AUTH_MODEL @"MTOP_LOCAK_ERROR_NO_AUTH_MODEL"
#define k_MTOP_LOCAL_ERROR_MSG_NO_AUTH_MODEL @"没有找到授权模块"
@@ -0,0 +1,110 @@
//
// MtopExtRequest.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/13.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class MtopExtRequest;
@class MtopExtResponse;
typedef void (^MtopExtRequestStarted)(MtopExtRequest* request);
typedef void (^MtopExtRequestFailed)(MtopExtResponse* response);
typedef void (^MtopExtRequestSucceed)(MtopExtResponse* response);
typedef enum {
/* 标记用的,请不要用 */
MtopSessionExpiredOptionDummy = -1,
/* Session失效时,什么都不做 */
MtopSessionExpiredOptionNone = 0,
/* Session失效时,只做Auto Login */
MtopSessionExpiredOptionAutoLogin = 1,
/* Session失效时,先Auto Login,如果Auto Login失败,唤起登录界面 */
MtopSessionExpiredOptionAutoLoginAndManualLogin = 2
} MtopSessionExpiredOption;
typedef enum {
/* 标记用的,请不要用 */
MtopAuthExpiredOptionDummy = -1,
/* Session失效时,什么都不做 */
MtopAuthExpiredOptionNone = 0,
/* Session失效时,只做Auto Login */
MtopAuthExpiredOptionAutoAuth = 1,
/* Session失效时,先Auto Login,如果Auto Login失败,唤起登录界面 */
MtopAuthExpiredOptionAutAuthAndManualAuth = 2
} MtopAuthExpiredOption;
@interface MtopExtRequest : NSObject
@property(assign, nonatomic) BOOL needLogin;
@property(assign, nonatomic) BOOL needAuth;
@property(assign, nonatomic) BOOL needWUA;
@property(assign, nonatomic) MtopSessionExpiredOption sessionExpiredOption;
@property(assign, nonatomic) MtopAuthExpiredOption authExpiredOption;
@property (nonatomic, unsafe_unretained) NSTimeInterval timeOutSeconds;
@property(copy, atomic) MtopExtRequestStarted startedBlock;
@property(copy, atomic) MtopExtRequestFailed failedBlock;
@property(copy, atomic) MtopExtRequestSucceed succeedBlock;
@property (nonatomic, strong, readonly) NSString *apiName;
@property (nonatomic, strong, readonly) NSString *apiVersion;
@property (nonatomic, strong, readonly) NSString *requestID;
@property (nonatomic, strong, readonly) NSDictionary *requestHeaders;
@property (nonatomic, strong) NSString *customHost;
@property(assign, atomic, readonly) BOOL isCanceled;
@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, strong, readonly) NSString *bizID;
- (id)initWithApiName:(nullable NSString *)apiName apiVersion:(nullable NSString *)apiVersion bizID:(nullable NSString *)bizID;
- (void)addBizParameter:(id)value forKey:(NSString *)key;
- (void)addBizParameters:(NSDictionary *)kvs;
- (void)removeBizParameter:(NSString *)key;
- (void)useHttpPost;
- (BOOL)isUseHttpPost;
- (void)cancel;
- (NSDictionary *)getBizParameters;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,44 @@
//
// MtopExtResponse.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/15.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MtopExtRequest;
@class MtopError;
@interface MtopExtResponse : NSObject
/* http 状态码 */
@property(assign, nonatomic, readonly) int httpStartusCode;
/* 错误信息 */
@property(strong, nonatomic, readonly) MtopError *error;
/* http响应头 */
@property(strong, nonatomic, readonly) NSDictionary *responseHeaders;
/* 二进制响应 */
@property(strong, nonatomic, readonly) NSData *responseData;
/* 原始的http响应body */
@property(strong, nonatomic, readonly) NSString *responseString;
/* json响应,从http body 解析 */
@property(strong, nonatomic, readonly) NSDictionary *responseJsons;
/* 响应对应的API Request */
@property(strong, nonatomic, readonly) MtopExtRequest *request;
/* 底层发出去的URL */
@property(strong, nonatomic, readonly) NSURL *requestURL;
@property(assign, nonatomic) BOOL isLoginCancel;
@property(assign, nonatomic) BOOL isAuthCancel;
@end
@@ -0,0 +1,125 @@
//
// LoginProtocol.h
// mtopext
//
// 接入mtop登录模块需要实现的接口
//
// Created by 亿刀/禚来强 on 17/11/14.
// Copyright (c) 2016 Taobao. All rights reserved.
//
#import <Foundation/Foundation.h>
/*!
* 手淘 session 字段
*/
#define SESSION_KEY_SID @"sid"
#define SESSION_KEY_USER_ID @"userId"
#define SESSION_KEY_NICK @"nick"
#define SESSION_KEY_ECODE @"ecode"
#define SESSION_KEY_LOGIN_TOKEN @"loginToken"
#define SESSION_KEY_SSO_TOKEN @"ssoToken"
#define SESSION_KEY_COOKIE @"cookie"
#define SESSION_KEY_SID_INVALID_TIME @"sidInvalidTime"
#define SESSION_KEY_LOGIN_TIME @"loginTime"
#define SESSION_KEY_COOKIE_SSO_DOMAINS @"cookiesSSODomains"
/*!
* 登录标记
*/
typedef enum {
/* 只走AutoLogin,失败什么都不做! */
LoginOptionAutoLoginOnly = 1,
/* 先走AutoLogin,失败再拉登录页面 */
LoginOptionAutoLoginAndManualLogin,
} LoginOption;
/*!
* 登录成功回调
* @param isSuccessful YES表示登录成功(auto login或者manual login)NO表示登录失败(只可能发生在LoginOptionAutoLoginOnly
* @param loginResult 登录成功的情况下返回的登录结果(包含登录态)
*/
typedef void (^LOGIN_COMPLETION_HANDLER) (BOOL isSuccessful, NSDictionary* loginResult);
/*!
* 登录取消回调
* @param flags 用户手动取消登录页面
*/
typedef void (^LOGIN_CANCELATION_HANDLER)();
@protocol MtopLoginProtocol <NSObject>
@required
/*!
* 获取单例
*/
+ (id)sharedInstantce;
/*!
* 判断当前用户是否有登录会话
* @return
* YES 本地有会话且本地判断会话未过期,但服务端可能判定会话无效
* NO 本地无会话或本地判断会话已过期
*/
- (BOOL)isValidLogin;
/*
* 触发登录操作
* @param loginOption 登录选项 参看 <code>LoginOption</code>
* @param completionHandler 登录成功后回调
* @param cancelationHandler 登录用户取消后回调
*/
- (void)loginWithLoginOption:(LoginOption)loginOption
completionHandler:(LOGIN_COMPLETION_HANDLER)completionHandler
cancelationHandler:(LOGIN_CANCELATION_HANDLER)cancelationHandler;
/*
* 基本同上,一般业务方不要使用此方法,需要使用此方法,请联系@寻弦
* @param extraInfoDict 额外参数
*/
- (void)loginWithLoginOption:(LoginOption)loginOption
extraInfo:(NSDictionary *)extraInfoDict
completionHandler:(LOGIN_COMPLETION_HANDLER)completionHandler
cancelationHandler:(LOGIN_CANCELATION_HANDLER)cancelationHandler;
/*!
* 获取当前登录会话信息
* @return
* 会话信息
* sid -> session id (NSString*)
* userId -> 用户id (NSString*)
* ecode -> ecode (NSString*)
* nick -> 用户nick (NSString*)
* loginToken -> 登录令牌 (NSString*)
* ssoToken -> sso令牌 (NSString*)
* topSession -> top授权 (NSString*)
* cookie -> cookie (NSString*)
* ......
*/
- (NSDictionary *)currentSession;
//@optional
/*!
* 返回当前LoginCenter是否已经在处理登录行为
* @return YES 已经有在处理中的登录行为
* NO 没有正在处理的登录行为
*/
- (BOOL)isProcessingLogin;
//@optional
/*!
* 标识本地session已经失效
*/
- (void)markInvalidLogin;
/*!
* 登出
*/
- (void)logout;
@end
@@ -0,0 +1,30 @@
//
// MtopService.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/15.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MtopExtRequest;
@protocol MtopLoginProtocol;
@protocol MtopAuthProtocol;
NS_ASSUME_NONNULL_BEGIN
@interface MtopService : NSObject
+ (instancetype)shareInstance;
- (void)installCustomLoginModule:(id<MtopLoginProtocol>)loginHandler;
- (void)installCustomAuthModule:(id<MtopAuthProtocol>)authHandler;
- (void)async_call:(MtopExtRequest *)request;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// mtopext.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/13.
// Copyright (c) 2016年 亿刀/禚来强. All rights reserved.
//
#import <OpenMtopExt/MtopExtRequest.h>
#import <OpenMtopExt/MtopService.h>
#import <OpenMtopExt/MtopLoginProtocol.h>
#import <OpenMtopExt/MtopExtResponse.h>
#import <OpenMtopExt/TBSDKConfiguration.h>
#import <OpenMtopExt/MtopErrorDefine.h>
#import <OpenMtopExt/MtopLoginProtocol.h>
#import <OpenMtopExt/MtopError.h>
@@ -0,0 +1,53 @@
//
// TBSDKConfiguration.h
// mtopext
//
// Created by 亿刀/禚来强 on 16/6/15.
// Copyright © 2016年 亿刀/禚来强. All rights reserved.
//
#import <Foundation/Foundation.h>
@class TBSDKAccountInfo;
typedef enum {
/**< 枚举,预发环境 */
TBSDKEnvironmentDebug = 1,
/**< 枚举,日常环境 */
TBSDKEnvironmentDaily,
/**< 枚举,正式环境 */
TBSDKEnvironmentRelease
} TBSDKEnvironment;
@interface TBSDKConfiguration : NSObject
/* 设置环境 */
@property (nonatomic, unsafe_unretained) TBSDKEnvironment environment;
/* 无线埋点的 ttid */
@property (nonatomic, strong) NSString *wapTTID;
/* 自定义域名 */
@property (nonatomic, strong) NSString *customHost;
/* 加签码 */
@property (nonatomic, strong) NSString *authCode;
/* 应用程序的 appKey */
@property (nonatomic, strong, readonly) NSString *appKey;
/* 设备标示 */
@property(strong, nonatomic, readonly) NSString *utdid;
/* 服务器时间 */
@property(strong, nonatomic, readonly) NSDate *serverDate;
/* 获取单例对象 */
+ (id)shareInstance;
@end