// // DRUMbindWeChat.m // YouHuiProject // // Created by jcymac on 2018/5/25. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRUMbindWeChat.h" @implementation DRUMbindWeChat static DRUMbindWeChat *umbindWeChat = nil; +(instancetype)sharedInstance{ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ umbindWeChat = [[DRUMbindWeChat alloc]init]; }); return umbindWeChat; } -(void)bindWeChatSuccess:(void(^)(UMSocialUserInfoResponse *response))succ fail:(void(^)(NSError *error))fail{ [self loginWithPlatformSuccess:^(UMSocialUserInfoResponse *response) { //处理绑定逻辑 NSString *url=[NSString stringWithFormat:@"%@/api/v2/users/bindWeChat",BaseURL]; NSDictionary *dic=@{ @"openid":response.openid, @"unionid":response.unionId, @"nickname":response.name, @"headimgurl":response.iconurl }; [DRHttp post:url params:dic success:^(id json) { [SVProgressHUD showSuccessWithStatus:@"绑定成功"]; [SVProgressHUD dismissWithDelay:1.0f]; } failure:^(NSError *error) { [MBProgressHUD showMessage:@"绑定失败"]; [SVProgressHUD dismiss]; }]; if (succ) { succ(response); } } fail:^(NSError *error) { [MBProgressHUD showMessage:@"微信请求失败"]; [SVProgressHUD dismiss]; if (fail) { fail(error); } }]; } - (void)loginWithPlatformSuccess:(void(^)(UMSocialUserInfoResponse *response))response fail:(void(^)(NSError *error))fail{ [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) { if (error) { fail(error); } else{ UMSocialUserInfoResponse *resp = result; // 授权信息 NSLog(@"Wechat uid: %@", resp.uid); NSLog(@"Wechat openid: %@", resp.openid); NSLog(@"Wechat unionid: %@", resp.unionId); NSLog(@"Wechat accessToken: %@", resp.accessToken); NSLog(@"Wechat refreshToken: %@", resp.refreshToken); NSLog(@"Wechat expiration: %@", resp.expiration); // 用户信息 NSLog(@"Wechat name: %@", resp.name); NSLog(@"Wechat iconurl: %@", resp.iconurl); NSLog(@"Wechat gender: %@", resp.unionGender); // 第三方平台SDK源数据 NSLog(@"Wechat originalResponse: %@", resp.originalResponse); response(resp); } }]; } - (void)loginWeChatSuccess:(void(^)(UMSocialUserInfoResponse *response))succ fail:(void(^)(NSError *error))fail{ [self loginWithPlatformSuccess:^(UMSocialUserInfoResponse *response) { //处理登录逻辑 if (succ) { succ(response); } } fail:^(NSError *error) { [MBProgressHUD showMessage:@"微信请求失败"]; [SVProgressHUD dismiss]; if (fail) { fail(error); } }]; } @end