省钱达人

DRUMbindWeChat.m 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // DRUMbindWeChat.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRUMbindWeChat.h"
  9. @implementation DRUMbindWeChat
  10. static DRUMbindWeChat *umbindWeChat = nil;
  11. +(instancetype)sharedInstance{
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. umbindWeChat = [[DRUMbindWeChat alloc]init];
  15. });
  16. return umbindWeChat;
  17. }
  18. -(void)bindWeChatSuccess:(void(^)(UMSocialUserInfoResponse *response))succ fail:(void(^)(NSError *error))fail{
  19. [self loginWithPlatformSuccess:^(UMSocialUserInfoResponse *response) {
  20. //处理绑定逻辑
  21. NSString *url=[NSString stringWithFormat:@"%@/api/v2/users/bindWeChat",BaseURL];
  22. NSDictionary *dic=@{
  23. @"openid":response.openid,
  24. @"unionid":response.unionId,
  25. @"nickname":response.name,
  26. @"headimgurl":response.iconurl
  27. };
  28. [DRHttp post:url params:dic success:^(id json) {
  29. [SVProgressHUD showSuccessWithStatus:@"绑定成功"];
  30. [SVProgressHUD dismissWithDelay:1.0f];
  31. } failure:^(NSError *error) {
  32. [MBProgressHUD showMessage:@"绑定失败"];
  33. [SVProgressHUD dismiss];
  34. }];
  35. if (succ) {
  36. succ(response);
  37. }
  38. } fail:^(NSError *error) {
  39. [MBProgressHUD showMessage:@"微信请求失败"];
  40. [SVProgressHUD dismiss];
  41. if (fail) {
  42. fail(error);
  43. }
  44. }];
  45. }
  46. - (void)loginWithPlatformSuccess:(void(^)(UMSocialUserInfoResponse *response))response fail:(void(^)(NSError *error))fail{
  47. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
  48. if (error) {
  49. fail(error);
  50. } else{
  51. UMSocialUserInfoResponse *resp = result;
  52. // 授权信息
  53. NSLog(@"Wechat uid: %@", resp.uid);
  54. NSLog(@"Wechat openid: %@", resp.openid);
  55. NSLog(@"Wechat unionid: %@", resp.unionId);
  56. NSLog(@"Wechat accessToken: %@", resp.accessToken);
  57. NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
  58. NSLog(@"Wechat expiration: %@", resp.expiration);
  59. // 用户信息
  60. NSLog(@"Wechat name: %@", resp.name);
  61. NSLog(@"Wechat iconurl: %@", resp.iconurl);
  62. NSLog(@"Wechat gender: %@", resp.unionGender);
  63. // 第三方平台SDK源数据
  64. NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
  65. response(resp);
  66. }
  67. }];
  68. }
  69. - (void)loginWeChatSuccess:(void(^)(UMSocialUserInfoResponse *response))succ fail:(void(^)(NSError *error))fail{
  70. [self loginWithPlatformSuccess:^(UMSocialUserInfoResponse *response) {
  71. //处理登录逻辑
  72. if (succ) {
  73. succ(response);
  74. }
  75. } fail:^(NSError *error) {
  76. [MBProgressHUD showMessage:@"微信请求失败"];
  77. [SVProgressHUD dismiss];
  78. if (fail) {
  79. fail(error);
  80. }
  81. }];
  82. }
  83. @end