小说绘上架版本
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// TFWeChatPermissionsManager.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/5.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TFWeChatPermissionsType) {
|
||||
TFWeChatPermissionsTypeLogin,
|
||||
TFWeChatPermissionsTypeBinding
|
||||
};
|
||||
|
||||
@protocol TFWeChatPermissionsDelegate <NSObject>
|
||||
@optional
|
||||
// 登录成功
|
||||
- (void)wechatResponseSuccess:(TFUserInfoManager *)userData;
|
||||
|
||||
// 登录失败
|
||||
- (void)wechatResponseFail:(NSString *)error;
|
||||
@end
|
||||
|
||||
@interface TFWeChatPermissionsManager : NSObject
|
||||
|
||||
@property (nonatomic, weak) id <TFWeChatPermissionsDelegate> delegate;
|
||||
|
||||
interface_singleton
|
||||
|
||||
- (void)weChatPermissionsType:(TFWeChatPermissionsType)type;
|
||||
|
||||
+ (BOOL)isInstallWechat;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// TFWeChatPermissionsManager.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/5.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFWeChatPermissionsManager.h"
|
||||
#import <ShareSDK/ShareSDK.h>
|
||||
#import "AppDelegate.h"
|
||||
#import "TFURLProtocol.h"
|
||||
|
||||
@interface TFWeChatPermissionsManager ()
|
||||
|
||||
@property (nonatomic ,assign) TFWeChatPermissionsType permissionsType;
|
||||
@end
|
||||
|
||||
@implementation TFWeChatPermissionsManager
|
||||
|
||||
implementation_singleton(TFWeChatPermissionsManager)
|
||||
|
||||
- (void)weChatPermissionsType:(TFWeChatPermissionsType)type
|
||||
{
|
||||
// 注册网络请求监听。
|
||||
[TFURLProtocol startMonitor];
|
||||
|
||||
WS(weakSelf)
|
||||
[ShareSDK authorize:SSDKPlatformTypeWechat settings:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
|
||||
|
||||
if (state == SSDKResponseStateSuccess) {
|
||||
|
||||
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
NSString *code = delegate.wechatCode ?: @"";
|
||||
|
||||
if (code.length > 0) {
|
||||
if (type == TFWeChatPermissionsTypeLogin) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusLoading promptTitle:TFLocalizedString(@"微信登录中")];
|
||||
}
|
||||
|
||||
if (type == TFWeChatPermissionsTypeBinding) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusLoading promptTitle:TFLocalizedString(@"正在获取微信信息")];
|
||||
}
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"微信登录失败")];
|
||||
return;
|
||||
}
|
||||
|
||||
if (code && code.length > 0) {
|
||||
|
||||
NSDictionary *params = @{
|
||||
@"code" : code
|
||||
};
|
||||
|
||||
if (type == TFWeChatPermissionsTypeLogin) {
|
||||
|
||||
[TFNetworkTools POST:WeChat_Login parameters:params model:TFUserInfoManager.class success:^(BOOL isSuccess, TFUserInfoManager *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
[TFURLProtocol stopMonitor];
|
||||
if (isSuccess) {
|
||||
[weakSelf wechatRequestSuccess:t_model];
|
||||
return;
|
||||
}
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFURLProtocol stopMonitor];
|
||||
[weakSelf wechatRequestFail:TFLocalizedString(@"微信登录失败")];
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == TFWeChatPermissionsTypeBinding) {
|
||||
[TFNetworkTools POST:WeChat_Binding parameters:params model:TFUserInfoManager.class success:^(BOOL isSuccess, TFUserInfoManager *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
[TFURLProtocol stopMonitor];
|
||||
if (isSuccess) {
|
||||
[weakSelf wechatRequestSuccess:t_model];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFURLProtocol stopMonitor];
|
||||
[weakSelf wechatRequestFail:TFLocalizedString(@"微信绑定失败")];
|
||||
}];
|
||||
return;
|
||||
}
|
||||
} else if (state == SSDKResponseStateCancel) {
|
||||
TFLog(@"授权取消");
|
||||
} else if (state == SSDKResponseStateFail) {
|
||||
TFLog(@"=== 授权错误%@",error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
[ShareSDK getUserInfo:SSDKPlatformTypeWechat onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
|
||||
if (state == SSDKResponseStateSuccess) {
|
||||
|
||||
TFLog(@"uid=%@",user.uid);
|
||||
TFLog(@"%@",user.credential);
|
||||
TFLog(@"token=%@",user.credential.token);
|
||||
TFLog(@"nickname=%@",user.nickname);
|
||||
} else {
|
||||
TFLog(@"%@",error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
+ (BOOL)isInstallWechat
|
||||
{
|
||||
return YES;//[WXApi isWXAppInstalled];
|
||||
}
|
||||
|
||||
- (void)wechatRequestSuccess:(TFUserInfoManager *)userData
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(wechatResponseSuccess:)]) {
|
||||
[self.delegate wechatResponseSuccess:userData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)wechatRequestFail:(NSString *)error
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(wechatResponseFail:)]) {
|
||||
[self.delegate wechatResponseFail:error ? : @""];
|
||||
}
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user