|
@@ -0,0 +1,199 @@
|
|
|
+//
|
|
|
+// ThirdPartyManager.m
|
|
|
+// H+
|
|
|
+//
|
|
|
+// Created by alex on 2017/12/5.
|
|
|
+// Copyright © 2017年 vinDesel. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "ThirdPartyManager.h"
|
|
|
+#import "HttpRequestManger.h"
|
|
|
+//#import "OrderPaySuccessNewViewController.h"
|
|
|
+//#import "BindPhoneViewController.h"
|
|
|
+//#import "AuthKit.h"
|
|
|
+
|
|
|
+@interface ThirdPartyManager()
|
|
|
+@property (copy, nonatomic) void(^receiveMessage)(NSInteger count);
|
|
|
+@property (strong, nonatomic) HttpRequestManger *sessionManager;
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation ThirdPartyManager
|
|
|
+- (HttpRequestManger*) sessionManager{
|
|
|
+ if (!_sessionManager) {
|
|
|
+ _sessionManager = [[HttpRequestManger alloc]init];
|
|
|
+ }
|
|
|
+ return _sessionManager;
|
|
|
+}
|
|
|
+
|
|
|
++ (ThirdPartyManager*)sharedManager{
|
|
|
+ static ThirdPartyManager *manager;
|
|
|
+ static dispatch_once_t onceToken;
|
|
|
+ dispatch_once(&onceToken, ^{
|
|
|
+ manager = [[self alloc]init];
|
|
|
+ });
|
|
|
+ return manager;
|
|
|
+}
|
|
|
+
|
|
|
+//- (void) registerQIYUCallback:(void(^)(NSInteger count)) callback{
|
|
|
+// [[QYSDK sharedSDK].conversationManager setDelegate:self];
|
|
|
+// self.receiveMessage = callback;
|
|
|
+//}
|
|
|
+
|
|
|
+- (void)sendWXAuthRequest{
|
|
|
+ SendAuthReq *req = [[SendAuthReq alloc] init];
|
|
|
+ req.scope = @"snsapi_userinfo";
|
|
|
+ req.openID = WEIXIN_APPKEY;
|
|
|
+ [WXApi sendAuthReq:req viewController:[DKGlobal sharedInstance].currentViewController delegate:self];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)doWXPay:(NSDictionary*)params {
|
|
|
+ if ([WXApi isWXAppInstalled]) {
|
|
|
+ PayReq *request = [[PayReq alloc] init];
|
|
|
+ request.partnerId = [params objectForKeySafely:@"partnerid"];
|
|
|
+ request.prepayId = [params objectForKeySafely:@"prepayid"];
|
|
|
+ request.package = [params objectForKeySafely:@"package"];
|
|
|
+ request.nonceStr = [params objectForKeySafely:@"noncestr"];
|
|
|
+ request.timeStamp = [[params objectForKeySafely:@"timestamp"] intValue];
|
|
|
+ request.sign = [params objectForKeySafely:@"sign"];
|
|
|
+ [WXApi sendReq:request];
|
|
|
+ }else{
|
|
|
+ [ToastView showToast:@"未安装微信"];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)doAliPay:(NSString*)payinfo
|
|
|
+{
|
|
|
+ [[AlipaySDK defaultService] payOrder:payinfo fromScheme:alipayScheme callback:^(NSDictionary *resultDic) {
|
|
|
+ NSInteger code = [[resultDic objectForKeySafely:@"resultStatus"] integerValue];
|
|
|
+ if (code == 9000) {
|
|
|
+ [[NSNotificationCenter defaultCenter]postNotificationName:@"OnPaymentSuccessNotification" object:nil];
|
|
|
+ }else{
|
|
|
+ [ToastView showToast:[resultDic objectForKeySafely:@"memo"]];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+- (BOOL) WXOpenUrl:(NSURL*)url
|
|
|
+{
|
|
|
+ return [WXApi handleOpenURL:url delegate:self];
|
|
|
+}
|
|
|
+
|
|
|
+- (void) AliPayOpenUrl:(NSURL*)url{
|
|
|
+ [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
|
|
|
+ NSInteger code = [[resultDic objectForKeySafely:@"resultStatus"] integerValue];
|
|
|
+ if (code == 9000) {
|
|
|
+ [[NSNotificationCenter defaultCenter]postNotificationName:@"OnPaymentSuccessNotification" object:nil];
|
|
|
+ }else{
|
|
|
+ [ToastView showToast:[resultDic objectForKeySafely:@"memo"]];
|
|
|
+ [self postToHouTaiErrorAccount:[DKGlobal sharedInstance].phone PayMethod:@"1" Code:[NSString stringWithFormat:@"%ld",(long)code] Message:[NSString stringWithFormat:@"%@",[resultDic objectForKeySafely:@"result"]]];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)onResp:(BaseResp *)resp {
|
|
|
+ if([resp isKindOfClass:[PayResp class]]){
|
|
|
+ switch (resp.errCode) {
|
|
|
+ case WXSuccess:{
|
|
|
+ [[NSNotificationCenter defaultCenter]postNotificationName:@"OnPaymentSuccessNotification" object:nil];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:{
|
|
|
+ [ToastView showToast:@"微信支付未完成"];
|
|
|
+ [self postToHouTaiErrorAccount:[DKGlobal sharedInstance].phone PayMethod:@"0" Code:[NSString stringWithFormat:@"%d",resp.errCode] Message:resp.errStr];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// else if ([resp isKindOfClass:[SendAuthResp class]]) {
|
|
|
+// SendAuthResp *authResp = (SendAuthResp *)resp;
|
|
|
+// if (authResp.errCode == WXSuccess) {
|
|
|
+// NSDictionary *paramsForToken = @{@"appid":wxappid,
|
|
|
+// @"secret":wxsecret,
|
|
|
+// @"code":authResp.code?authResp.code:@"",
|
|
|
+// @"grant_type":@"authorization_code"};
|
|
|
+// [ProgressHUD show];
|
|
|
+// [[HttpRequestManger sharedManager]sendGetHttpRequestWithUrl:wxaccesstoken params:paramsForToken progress:nil success:^(id response) {
|
|
|
+// NSString *access_token = [response objectForKeySafely:@"access_token"];
|
|
|
+// NSString *openid = [response objectForKeySafely:@"openid"];
|
|
|
+// NSDictionary *paramsForInfo = @{@"access_token":access_token?access_token:@"",
|
|
|
+// @"openid":openid?openid:@""};
|
|
|
+// [[HttpRequestManger sharedManager]sendGetHttpRequestWithUrl:wxuserinfo params:paramsForInfo progress:nil success:^(id response) {
|
|
|
+// NSString *unionid = [response objectForKeySafely:@"unionid"];
|
|
|
+// NSString *nickname = [response objectForKeySafely:@"nickname"];
|
|
|
+// NSString *headimgurl = [response objectForKeySafely:@"headimgurl"];
|
|
|
+// [[HttpRequestManger sharedManager] sendGetHttpRequestWithUrl:user_get_sign params:nil progress:nil success:^(id response) {
|
|
|
+// NSString *sign = [response objectForKeySafely:@"data"];
|
|
|
+// NSDictionary *paramsForLogin = @{@"unionid":unionid?unionid:@"",
|
|
|
+// @"sign":sign?sign:@""};
|
|
|
+// [[HttpRequestManger sharedManager]sendPostHttpRequestWithUrl:user_wx_login params:paramsForLogin bodyBlock:nil progress:nil success:^(NSDictionary *response) {
|
|
|
+// [ProgressHUD hide];
|
|
|
+// NSDictionary *data = [response objectForKeySafely:@"data"];
|
|
|
+// NSString *token = [data objectForKeySafely:@"token"];
|
|
|
+// if (token.length > 0) {
|
|
|
+// [[AuthKit sharedInstance] persistAccount:data];
|
|
|
+// [[Utility sharedInstance].rootNavController popToRootViewControllerAnimated:YES];
|
|
|
+// }else{
|
|
|
+// [ToastView showToast:@"授权登录失败"];
|
|
|
+// }
|
|
|
+// } failure:^(NSError *error) {
|
|
|
+// [ProgressHUD hide];
|
|
|
+// if (error.code == 1) {
|
|
|
+// BindPhoneViewController *controller = [[BindPhoneViewController alloc]initWithNibName:@"BindPhoneViewController" bundle:nil];
|
|
|
+// controller.unionId = unionid;
|
|
|
+// controller.nickName = nickname;
|
|
|
+// controller.avatar = headimgurl;
|
|
|
+// controller.hidesBottomBarWhenPushed = YES;
|
|
|
+// [[Utility sharedInstance].rootNavController pushViewController:controller animated:YES];
|
|
|
+// }else{
|
|
|
+// [ToastView showToast:@"授权登录失败"];
|
|
|
+// }
|
|
|
+// }];
|
|
|
+// } failure:^(NSError *error) {
|
|
|
+// [ProgressHUD hide];
|
|
|
+// [ToastView showToast:@"授权登录失败"];
|
|
|
+// }];
|
|
|
+// } failure:^(NSError *error) {
|
|
|
+// [ProgressHUD hide];
|
|
|
+// [ToastView showToast:@"授权登录失败"];
|
|
|
+// }];
|
|
|
+// } failure:^(NSError *error) {
|
|
|
+// [ProgressHUD hide];
|
|
|
+// [ToastView showToast:@"授权登录失败"];
|
|
|
+// }];
|
|
|
+// }else{
|
|
|
+// [ToastView showToast:@"取消授权登录"];
|
|
|
+// }
|
|
|
+// }else if([resp isKindOfClass:[SendMessageToWXResp class]]){
|
|
|
+// if (resp.errCode == WXSuccess) {
|
|
|
+// [ToastView showToast:@"分享成功"];
|
|
|
+// }
|
|
|
+// }
|
|
|
+}
|
|
|
+
|
|
|
+//- (void)onReceiveMessage:(QYMessageInfo *)message{
|
|
|
+// QYConversationManager *manager = [[QYSDK sharedSDK] conversationManager];
|
|
|
+// if (self.receiveMessage) {
|
|
|
+// self.receiveMessage(manager.allUnreadCount);
|
|
|
+// }
|
|
|
+//}
|
|
|
+- (void)postToHouTaiErrorAccount:(NSString *)account PayMethod:(NSString *)payMethod Code:(NSString *)code Message:(NSString *)msg
|
|
|
+{
|
|
|
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
|
+ params[@"account"] = account;
|
|
|
+ params[@"payMethod"] = payMethod;
|
|
|
+ params[@"code"] = code;
|
|
|
+ params[@"msg"] = msg;
|
|
|
+ [self.sessionManager sendPostHttpRequestWithUrl:errorToPost params:params bodyBlock:nil progress:nil success:^(NSDictionary *response) {
|
|
|
+ DebugLog(@"发送错误成功");
|
|
|
+ } failure:^(NSError *error) {
|
|
|
+ DebugLog(@"发送错误失败");
|
|
|
+ }];
|
|
|
+}
|
|
|
+- (void)dealloc {
|
|
|
+ if (_sessionManager) {
|
|
|
+ [_sessionManager cancelAllTask];
|
|
|
+ }
|
|
|
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
+ DebugLog(@"%@没有造成循环引用", [self class]);
|
|
|
+}
|
|
|
+
|
|
|
+@end
|