| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // HJWeiXinAPIManager.m
- // HappyJob
- //
- // Created by Bob on 2019/4/1.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJWeiXinAPIManager.h"
- @implementation HJWeiXinAPIManager
- + (instancetype)sharedManager {
-
- static dispatch_once_t onceToken;
- static HJWeiXinAPIManager *instance;
- dispatch_once(&onceToken, ^{
-
- instance = [[HJWeiXinAPIManager alloc] init];
- });
- return instance;
- }
- - (void)wxSendAuthReqWithViewController:(UIViewController *)viewController {
-
- SendAuthReq *req = [[SendAuthReq alloc] init];
- req.state = @"wx_oauth_authorization_state";//用于保持请求和回调的状态,授权请求或原样带回
- req.scope = @"snsapi_userinfo";//授权作用域:获取用户个人信息
- //判断用户是否已安装微信App
- if ([WXApi isWXAppInstalled])
- {//安装
- [WXApi sendReq:req];
- }
- else
- {//未安装
- [WXApi sendAuthReq:req viewController:viewController delegate:self];
- }
- }
- #pragma mark - WXApiDelegate
- - (void)onResp:(BaseResp *)resp {
- // 判断是否为授权登录类
- if ([resp isKindOfClass:[SendAuthResp class]])
- {
- SendAuthResp *sendAuthResp = (SendAuthResp *)resp;
- if ([sendAuthResp.state isEqualToString:@"wx_oauth_authorization_state"])
- {
- // 微信授权成功
- if (sendAuthResp.errCode == 0)
- {
- if ([self.delegate respondsToSelector:@selector(wxSendAuthResponseDidSuccess:)])
- {
- [self.delegate wxSendAuthResponseDidSuccess:sendAuthResp];
- }
- }
- else
- {
- if ([self.delegate respondsToSelector:@selector(wxSendAuthResponseDidFailed:)])
- {
- [self.delegate wxSendAuthResponseDidFailed:sendAuthResp];
- }
- }
- }
- else
- {
- if ([self.delegate respondsToSelector:@selector(wxSendAuthResponseDidFailed:)])
- {
- [self.delegate wxSendAuthResponseDidFailed:sendAuthResp];
- }
- }
- }
- }
- @end
|