| 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";//授权作用域:获取用户个人信息
-
- if ([WXApi isWXAppInstalled]) {//判断用户是否已安装微信App
- [WXApi sendReq:req];
- } else {
- [WXApi sendAuthReq:req viewController:viewController delegate:self];
- }
-
- // if ([WXApi isWXAppInstalled]) {//判断用户是否已安装微信App
- // SendAuthReq *req = [[SendAuthReq alloc] init];
- // req.state = @"wx_oauth_authorization_state";//用于保持请求和回调的状态,授权请求或原样带回
- // req.scope = @"snsapi_userinfo";//授权作用域:获取用户个人信息
- //
- // if ([WXApi sendReq:req]) {
- // NSLog(@"发起微信授权请求成功");
- // } else {
- // NSLog(@"发起微信授权请求失败");
- // }
- //
- // } else {
- // // 提示:未安装微信应用跳转到AppStore下载
- // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/wechat/id414478124"]];
- //
- // }
- }
- #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]]) {
- // PayResp *payResp = (PayResp *)resp;
- // [self.delegate wxPayResponse:payResp];
- // //支付返回结果,实际支付结果需要去微信服务器端查询
- // NSString *strMsg;
- // switch (resp.errCode) {
- // case WXSuccess:
- // strMsg = @"支付结果:成功!";
- // NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
- // break;
- // default:
- // strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
- // NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
- // break;
- // }
- // }
- }
- @end
|