| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // 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];
- }
- }
- }
- //支付的
- if ([resp isKindOfClass:[PayResp class]])
- {
- if (resp.errCode == 0)
- {//成功
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiWeChatPaySucceed object:nil];
- }
- else if (resp.errCode == -1)
- {//错误
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiWeChatPayFailed object:nil];
- }
- else
- {//用户取消
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiWeChatPayCancel object:nil];
- }
- }
- }
- @end
|