CNLivePayCostModule.m
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// CNLivePayCostModule.m
// CNLivePayCostModule
//
// Created by open on 2022/5/12.
//
#import "CNLivePayCostModule.h"
#import "CNLivePayCostContentView.h"
#import "CNLivePayCostModel.h"
@interface CNLivePayCostModule ()
@end
@implementation CNLivePayCostModule
/// 启动设置
+(void)finishLaunchingWithPayPluginSettings
{
[UMSPPPayPluginSettings sharedInstance].umspEnviroment = UMSP_PROD;
//注册微信支付
[UMSPPPayUnifyPayPlugin registerApp:WeiChatAppId_Share universalLink:[NSString stringWithFormat:@"%@/",API_Host]];
}
/// 拉起网家家支付功能
/// @param paramDict 参数 (详细见.m中参数解释)
/// @param payCostType 支付来源路径
/// @param formVC 支付界面控制器
/// @param resultBlock 支付结果
+(void)showDefaultPayViwWithParamDict:(NSDictionary *)paramDict
PayCostType:(CNLivePayCostType)payCostType
FromVC:(UIViewController *)formVC
ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock
{
[CNLivePayCostModel sharePayCostModel].protocol = [NSClassFromString(@"CNLivePayCostProtocolImpl") new];
CNLivePayCostModel * payModel = [[CNLivePayCostModel alloc] init];
//扫码支付
if (payCostType == CNLivePayCostTypeSweep) {
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
payModel.expand = [@{@"fromType":@"1",@"toType":@"3",@"sourceType":@"order"} mj_JSONString];
payModel.payType = payCostType;
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.toId = [paramDict stringValueForKey:@"darenId" default:@""];
payModel.shopName = [paramDict stringValueForKey:@"shopName" default:@""];
payModel.face = [paramDict stringValueForKey:@"face" default:@""];
payModel.remark = [paramDict stringValueForKey:@"remark" default:@""];
if ([[paramDict allKeys] containsObject:@"paymentType"] && [paramDict dictionaryForKey:@"paymentType"] != nil) {
payModel.isHiddenAlipay = ![[paramDict dictionaryForKey:@"paymentType"] boolForKey:@"ali"];
payModel.isHiddenWechat = ![[paramDict dictionaryForKey:@"paymentType"] boolForKey:@"wechat"];
payModel.isHiddenUnionpay = ![[paramDict dictionaryForKey:@"paymentType"] boolForKey:@"union"];
payModel.isHiddenWjjpay = ![[paramDict dictionaryForKey:@"paymentType"] boolForKey:@"wjj"];
}
}
//门票支付
if (payCostType == CNLivePayCostTypeTicke) {
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.expand = [@{@"fromType":@"1",@"toType":@"6",@"sourceType":@"jsfy_order"} mj_JSONString];
payModel.toId = [paramDict stringValueForKey:@"toId" default:@""];
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
payModel.isHiddenWjjpay = YES;
payModel.shopName = [paramDict stringValueForKey:@"shopName" default:@""];
payModel.descStr = [paramDict stringValueForKey:@"descStr" default:@""];
payModel.payType = payCostType;
}
//订单支付
if (payCostType == CNLivePayCostTypeOrder) {
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.userId = [paramDict stringValueForKey:@"userId" default:@""];
payModel.expand = [@{@"fromType":@"1",@"toType":@"3",@"sourceType":@"order"} mj_JSONString];
payModel.descStr = [paramDict stringValueForKey:@"descStr" default:@""];
payModel.notifyUrl = [paramDict stringValueForKey:@"notifyUrl" default:@""];
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
if ([[paramDict stringValueForKey:@"orderType" default:@""] isEqualToString:@"3"]) payModel.isHiddenWjjpay =YES;
payModel.payType = payCostType;
}
//群组支付
if (payCostType == CNLivePayCostTypeGroup) {
payModel.orderId = [paramDict stringValueForKey:@"groupId" default:@""];
payModel.expand = [@{@"fromType":@"1",@"toType":@"2",@"sourceType":@"group_payment"} mj_JSONString];
payModel.descStr = [paramDict stringValueForKey:@"descStr" default:@""];
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
payModel.fundsId = [paramDict stringValueForKey:@"fundsId" default:@""];
payModel.payType = payCostType;
}
//上海电商支付
if (payCostType == CNLivePayCostTypeSHShop) {
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.toId = @"daren_10528143";//@"daren_10499273";
payModel.userId = [paramDict stringValueForKey:@"userId" default:@""];
payModel.notifyUrl = [paramDict stringValueForKey:@"notifyUrl" default:@""];
payModel.descStr = [paramDict stringValueForKey:@"descStr" default:@""];
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
payModel.attach = @{@"plat":@"i"};;
payModel.isHiddenWjjpay = NO;
payModel.expand = [@{@"fromType":@"1",@"toType":@"3",@"sourceType":@"global_order",@"orderType":@"8"} mj_JSONString];
payModel.payType = payCostType;
}
//社区支付
if (payCostType == CNLivePayCostTypeCommunt) {
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.isHiddenWjjpay = YES;
payModel.price = [paramDict floatValueForKey:@"price" default:1];
payModel.descStr = [paramDict stringValueForKey:@"body" default:@"网家家"];
payModel.attach = @{@"plat":@"i"};
payModel.notifyUrl = [paramDict stringValueForKey:@"notifyUrl" default:@""];
}
//网页支付
if (payCostType == CNLivePayCostTypeHtml) {
payModel.orderId = [paramDict stringValueForKey:@"orderId" default:@""];
payModel.toId = [paramDict stringValueForKey:@"toId" default:@""];
payModel.expand = [paramDict stringValueForKey:@"expand" default:@""];
payModel.shopName = [paramDict stringValueForKey:@"toName" default:@""];
payModel.isHiddenWjjpay = ![paramDict boolValueForKey:@"wjj" default:NO];
payModel.isHiddenAlipay = ![paramDict boolValueForKey:@"ali" default:NO];
payModel.isHiddenWechat = ![paramDict boolValueForKey:@"wechat" default:NO];
payModel.isHiddenUnionpay = [paramDict boolValueForKey:@"union" default:NO];
payModel.price = [paramDict floatValueForKey:@"price" default:0.00];
payModel.descStr = [paramDict stringValueForKey:@"title" default:@"网家家"];
NSDictionary * tempDict = [payModel.expand mj_JSONObject];
NSString * productId = @"";
if ([tempDict containsObjectForKey:@"prdId"]) productId = [tempDict stringValueForKey:@"prdId" default:@""];
NSDictionary * attach = @{
@"sid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
@"plat":@"i",
@"prdId":productId?productId:@""
};
payModel.attach = attach;
payModel.notifyUrl = [paramDict stringValueForKey:@"notify_url" default:@""];
payModel.payType = payCostType;
}
if ([[CNUserInfoManager manager].userInfoModel.unionUserStatus isEqualToString:@"3"]) payModel.isHiddenWjjpay = YES;
CNLivePayCostContentView * payCostView = [[CNLivePayCostContentView alloc] initWithFrame:AppKeyWindow.bounds PayModel:payModel FromVC:formVC CompleterBlock:^(CNLivePayCostTypeResult resultType) {
if (resultBlock) resultBlock(resultType);
}];
[AppKeyWindow addSubview:payCostView];
[payCostView show];
if (payCostType == CNLivePayCostTypeCommunt) {
//社区支付结果回调
[[NSNotificationCenter defaultCenter] addObserver:payCostView selector:@selector(resultPayAction:) name:@"kIMAMSG_CommunityPaySuccessNotification" object:nil];
}else if (payCostType == CNLivePayCostTypeSweep) {
//二维码识别结果回调
[[NSNotificationCenter defaultCenter] addObserver:payCostView selector:@selector(resultPayAction:) name:@"CNLiveContentSweepPaymentNotification" object:nil];
}else{
//支付成功通知回调
[[NSNotificationCenter defaultCenter] addObserver:payCostView selector:@selector(resultPayAction:) name:@"kIMAMSG_ScanPaySuccessNotification" object:nil];
}
}
/// 拉起苹果支付功能
/// @param paramDict 参数
/// @param formVC 支付界面控制器
/// @param resultBlock 支付结果
+(void)showApplePayViwWithParamDict:(NSDictionary *)paramDict
FromVC:(UIViewController *)formVC
ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock
{
[CNLivePayCostModel sharePayCostModel].protocol = [NSClassFromString(@"CNLivePayCostProtocolImpl") new];
NSString * notify_url = [paramDict stringValueForKey:@"notify_url" default:@""];
NSString * total_fee = [paramDict stringValueForKey:@"total_fee" default:@""];
NSString * body = [paramDict stringValueForKey:@"body" default:@""];
NSString * productId = [paramDict stringValueForKey:@"prdId" default:@""];
int moneyInt = [total_fee intValue];
if (((int)moneyInt/100)<=0) {
[QMUITips showWithText:@"付款金额不正确" inView:formVC.view hideAfterDelay:1.5f];
return;
}
NSString *appleProductId = [NSString stringWithFormat:@"%@%d",CNLiveWjjApplePayAVProductIdBase,(int)moneyInt/100];
CNLivePayArg *arg = [[CNLivePayArg alloc] init];
arg.account = @"";
arg.type = CNLivePayTypeInAppPurchase;
arg.out_trade_no = [CNLivePayCostModel payCost_getRandomOrderId];
arg.total_fee = moneyInt;
arg.notify_url = notify_url;
arg.user_id = CNUserShareModel.uid?CNUserShareModel.uid:@"";
arg.attach = @{
@"sid":CNUserShareModel.uid?CNUserShareModel.uid:@"",
@"plat":@"i",
@"prdId":productId?productId:@""
};
arg.body = [body isNotBlank]?body:[NSString stringWithFormat:@"您购买了付费服务"];
[QMUITips showLoadingInView:formVC.view];
[[CNLivePaySDK sharedCNLivePayManager] pay:arg isDebug:TestEnvironment productId:appleProductId completion:^(CNLivePayResult *cnlivePayResult) {
dispatch_async(dispatch_get_main_queue(), ^{
[QMUITips hideAllTipsInView:formVC.view];
if ([cnlivePayResult.channelBackCode isEqualToString:@"0"]) {
if (resultBlock) resultBlock(CNLivePayCostTypeResultSucc);
} else {
[QMUITips showWithText:cnlivePayResult.backDescription inView:formVC.view hideAfterDelay:1.5f];
}
});
}];
}
/// 拉起电商支付功能
/// @param paramDict 参数
/// @param payType 支付界面控制器
/// @param resultBlock 支付结果
+(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict
PayType:(CNLivePayCostPayType)payType
ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock
{
NSString * orderId = [paramDict stringValueForKey:@"orderId" default:@""];
NSString * body = [paramDict stringValueForKey:@"body" default:@""];
NSString * price = [paramDict stringValueForKey:@"price" default:@"0.00"];
NSString * couponFee = [paramDict stringValueForKey:@"coupon_fee" default:@"0.00"];
NSString * balanceFee = [paramDict stringValueForKey:@"balance_fee" default:@"0.00"];
NSString * notifyUrl = [paramDict stringValueForKey:@"notifyUrl" default:@""];
NSString * password = [paramDict stringValueForKey:@"password" default:@""];
NSString * p = [NSString stringWithFormat:@"%d",(NSInteger)([price floatValue]*100)];
[CNLivePayCostNetwork requestWithUMSPayForPrePayWithOrderId:orderId Body:body Price:p CouponFee:couponFee BalanceFee:balanceFee NotifyUrl:notifyUrl Type:payType ThreePayType:CNLivePayCostThreePayTypeShop FrmId:@"debug" PassWord:password CompleterBlcok:^(NSInteger statue) {
if (resultBlock) {
if (statue == 0) resultBlock(statue == 0?CNLivePayCostTypeResultSucc:CNLivePayCostTypeResultFail);
}
}];
}
@end