Commit 6d93e3ec5293439a0a84bbc5644d31e541ae83c0
1 parent
ea59aec8
0.0.5
Showing
5 changed files
with
52 additions
and
29 deletions
CNLivePayCostModule.podspec
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | Pod::Spec.new do |s| | 9 | Pod::Spec.new do |s| |
| 10 | s.name = 'CNLivePayCostModule' | 10 | s.name = 'CNLivePayCostModule' |
| 11 | - s.version = '0.0.4' | 11 | + s.version = '0.0.5' |
| 12 | s.summary = 'A short description of CNLivePayCostModule.' | 12 | s.summary = 'A short description of CNLivePayCostModule.' |
| 13 | 13 | ||
| 14 | # This description is used to generate tags and improve search results. | 14 | # This description is used to generate tags and improve search results. |
CNLivePayCostModule/Classes/Core/CNLivePayCostModule.h
| @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN | @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN | ||
| 39 | /// @param resultBlock 支付结果 | 39 | /// @param resultBlock 支付结果 |
| 40 | +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict | 40 | +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict |
| 41 | PayType:(CNLivePayCostPayType)payType | 41 | PayType:(CNLivePayCostPayType)payType |
| 42 | - ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock; | 42 | + ResultBlock:(void(^)(NSInteger resultCode))resultBlock; |
| 43 | 43 | ||
| 44 | @end | 44 | @end |
| 45 | 45 |
CNLivePayCostModule/Classes/Core/CNLivePayCostModule.m
| @@ -208,7 +208,7 @@ | @@ -208,7 +208,7 @@ | ||
| 208 | /// @param resultBlock 支付结果 | 208 | /// @param resultBlock 支付结果 |
| 209 | +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict | 209 | +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict |
| 210 | PayType:(CNLivePayCostPayType)payType | 210 | PayType:(CNLivePayCostPayType)payType |
| 211 | - ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock | 211 | + ResultBlock:(void(^)(NSInteger resultCode))resultBlock |
| 212 | { | 212 | { |
| 213 | NSString * orderId = [paramDict stringValueForKey:@"orderId" default:@""]; | 213 | NSString * orderId = [paramDict stringValueForKey:@"orderId" default:@""]; |
| 214 | NSString * body = [paramDict stringValueForKey:@"body" default:@""]; | 214 | NSString * body = [paramDict stringValueForKey:@"body" default:@""]; |
| @@ -220,10 +220,8 @@ | @@ -220,10 +220,8 @@ | ||
| 220 | 220 | ||
| 221 | NSString * p = [NSString stringWithFormat:@"%d",(NSInteger)([price floatValue]*100)]; | 221 | NSString * p = [NSString stringWithFormat:@"%d",(NSInteger)([price floatValue]*100)]; |
| 222 | 222 | ||
| 223 | - [CNLivePayCostNetwork requestWithUMSPayForPrePayWithOrderId:orderId Body:body Price:p CouponFee:couponFee BalanceFee:balanceFee NotifyUrl:notifyUrl Type:payType ThreePayType:CNLivePayCostThreePayTypeShop FrmId:@"debug" PassWord:password CompleterBlcok:^(NSInteger statue) { | ||
| 224 | - if (resultBlock) { | ||
| 225 | - if (statue == 0) resultBlock(statue == 0?CNLivePayCostTypeResultSucc:CNLivePayCostTypeResultFail); | ||
| 226 | - } | 223 | + [CNLivePayCostNetwork requestWithUMSPayForPrePayWithOrderId:orderId Body:body Price:p CouponFee:couponFee BalanceFee:balanceFee NotifyUrl:notifyUrl Type:payType ThreePayType:CNLivePayCostThreePayTypeShop FrmId:@"ios" PassWord:password CompleterBlcok:^(NSInteger statue) { |
| 224 | + if (resultBlock) resultBlock(statue); | ||
| 227 | }]; | 225 | }]; |
| 228 | } | 226 | } |
| 229 | @end | 227 | @end |
CNLivePayCostModule/Classes/Core/CNLivePayCostNetwork.m
| @@ -55,8 +55,15 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | @@ -55,8 +55,15 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | ||
| 55 | PassWord:(NSString *)password | 55 | PassWord:(NSString *)password |
| 56 | CompleterBlcok:(void(^)(NSInteger statue))completerBlock | 56 | CompleterBlcok:(void(^)(NSInteger statue))completerBlock |
| 57 | { | 57 | { |
| 58 | + NSString * notifyUrls = threeType == CNLivePayCostThreePayTypeTicke ? CNJSFYNotifyUrl: (type == CNLivePayCostPayTypeWeChatPay ? CNWeChatPayUrl : type == CNLivePayCostPayTypeAliPay ? CNAliPayUrl : CNUnionPayUrl); | ||
| 59 | + | ||
| 60 | + //上海电商 & 电商 需要特殊的回调地址 | ||
| 61 | + if (!CNLiveStringIsEmpty(notify_url) | ||
| 62 | + && (threeType == CNLivePayCostThreePayTypeSHSop || threeType == CNLivePayCostThreePayTypeShop)) notifyUrls = notify_url; | ||
| 63 | + | ||
| 58 | if (type == CNLivePayCostPayTypeWeChatPay) { | 64 | if (type == CNLivePayCostPayTypeWeChatPay) { |
| 59 | - NSString * path = [NSString stringWithFormat:@"pages/pays/pay/pay?appId=%@&body=%@&out_trade_no=%@&user_id=%@&total_fee=%@¬ify_url=%@&type=1&&frmId=ios&&page_url=%@&&coupon_fee=0&&balance_fee=0",AppId,body,orderId,CNUserShareModel.uid?CNUserShareModel.uid:@"",price,notify_url,notify_url]; | 65 | + |
| 66 | + NSString * path = [NSString stringWithFormat:@"pages/pays/pay/pay?appId=%@&body=%@&out_trade_no=%@&user_id=%@&total_fee=%@¬ify_url=%@&type=1&&frmId=ios&&page_url=%@&&coupon_fee=0&&balance_fee=0",AppId,body,orderId,CNUserShareModel.uid?CNUserShareModel.uid:@"",price,notifyUrls,notify_url]; | ||
| 60 | NSLog(@"===>%@",path); | 67 | NSLog(@"===>%@",path); |
| 61 | WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; | 68 | WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; |
| 62 | launchMiniProgramReq.userName = @"gh_061b347b32c1"; //拉起的小程序的username | 69 | launchMiniProgramReq.userName = @"gh_061b347b32c1"; //拉起的小程序的username |
| @@ -67,12 +74,6 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | @@ -67,12 +74,6 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | ||
| 67 | }]; | 74 | }]; |
| 68 | }else if (type == CNLivePayCostPayTypeWjjPay) { | 75 | }else if (type == CNLivePayCostPayTypeWjjPay) { |
| 69 | 76 | ||
| 70 | - NSString * notifyUrls = threeType == CNLivePayCostThreePayTypeTicke ? CNJSFYNotifyUrl: (type == CNLivePayCostPayTypeWeChatPay ? CNWeChatPayUrl : type == CNLivePayCostPayTypeAliPay ? CNAliPayUrl : CNUnionPayUrl); | ||
| 71 | - | ||
| 72 | - //上海电商需要特殊的回调地址 | ||
| 73 | - if (!CNLiveStringIsEmpty(notify_url) | ||
| 74 | - && threeType == CNLivePayCostThreePayTypeSHSop) notifyUrls = notify_url; | ||
| 75 | - | ||
| 76 | NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body; | 77 | NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body; |
| 77 | 78 | ||
| 78 | NSDictionary * paramDict = @{ | 79 | NSDictionary * paramDict = @{ |
| @@ -80,7 +81,7 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | @@ -80,7 +81,7 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | ||
| 80 | @"user_id":CNUserShareModel.uid?CNUserShareModel.uid:@"", | 81 | @"user_id":CNUserShareModel.uid?CNUserShareModel.uid:@"", |
| 81 | @"out_trade_no":orderId, | 82 | @"out_trade_no":orderId, |
| 82 | @"body":desc, | 83 | @"body":desc, |
| 83 | - @"coupon_fee":@"0", | 84 | + @"coupon_fee":coupon_fee, |
| 84 | @"balance_fee":price, | 85 | @"balance_fee":price, |
| 85 | @"notify_url":notifyUrls, | 86 | @"notify_url":notifyUrls, |
| 86 | @"page_url":@"", | 87 | @"page_url":@"", |
| @@ -98,11 +99,13 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | @@ -98,11 +99,13 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | ||
| 98 | if (completerBlock) completerBlock(0); | 99 | if (completerBlock) completerBlock(0); |
| 99 | }else{ | 100 | }else{ |
| 100 | [QMUITips showError:[errorMessage isNotBlank]?errorMessage:@"支付失败" inView:AppKeyWindow hideAfterDelay:1.5]; | 101 | [QMUITips showError:[errorMessage isNotBlank]?errorMessage:@"支付失败" inView:AppKeyWindow hideAfterDelay:1.5]; |
| 101 | - if (completerBlock) { | ||
| 102 | - if (errorCode == 100011) completerBlock(2); | ||
| 103 | - if (errorCode == 100010) completerBlock(1); | ||
| 104 | - if (errorCode != 100010 && errorCode != 100011) completerBlock(3); | ||
| 105 | - } | 102 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 103 | + if (completerBlock) { | ||
| 104 | + if (errorCode == 100011) completerBlock(2); | ||
| 105 | + if (errorCode == 100010) completerBlock(1); | ||
| 106 | + if (errorCode != 100010 && errorCode != 100011) completerBlock(3); | ||
| 107 | + } | ||
| 108 | + }); | ||
| 106 | } | 109 | } |
| 107 | }]; | 110 | }]; |
| 108 | 111 | ||
| @@ -112,12 +115,6 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | @@ -112,12 +115,6 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN | ||
| 112 | if (type == CNLivePayCostPayTypeUnionPay) index = @"9"; | 115 | if (type == CNLivePayCostPayTypeUnionPay) index = @"9"; |
| 113 | if (type == CNLivePayCostPayTypeWjjPay) index = @"4"; | 116 | if (type == CNLivePayCostPayTypeWjjPay) index = @"4"; |
| 114 | 117 | ||
| 115 | - NSString * notifyUrls = threeType == CNLivePayCostThreePayTypeTicke ? CNJSFYNotifyUrl: (type == CNLivePayCostPayTypeWeChatPay ? CNWeChatPayUrl : type == CNLivePayCostPayTypeAliPay ? CNAliPayUrl : CNUnionPayUrl); | ||
| 116 | - | ||
| 117 | - //上海电商需要特殊的回调地址 | ||
| 118 | - if (!CNLiveStringIsEmpty(notify_url) | ||
| 119 | - && threeType == CNLivePayCostThreePayTypeSHSop) notifyUrls = notify_url; | ||
| 120 | - | ||
| 121 | NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body; | 118 | NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body; |
| 122 | 119 | ||
| 123 | NSDictionary * paramDict = @{ | 120 | NSDictionary * paramDict = @{ |
Example/CNLivePayCostModule/CNLIVEViewController.m
| @@ -38,10 +38,12 @@ | @@ -38,10 +38,12 @@ | ||
| 38 | [batchBtn setTitle:@"电商支付" forState: UIControlStateHighlighted]; | 38 | [batchBtn setTitle:@"电商支付" forState: UIControlStateHighlighted]; |
| 39 | [batchBtn addTarget:self action:@selector(batchRequestAction) forControlEvents:UIControlEventTouchUpInside]; | 39 | [batchBtn addTarget:self action:@selector(batchRequestAction) forControlEvents:UIControlEventTouchUpInside]; |
| 40 | [self.view addSubview:batchBtn]; | 40 | [self.view addSubview:batchBtn]; |
| 41 | + | ||
| 42 | + | ||
| 43 | + | ||
| 41 | } | 44 | } |
| 42 | -(void)requestAction | 45 | -(void)requestAction |
| 43 | { | 46 | { |
| 44 | -// [CNLivePayCostNetwork requestWithUMSPayForPrePayWithOrderId:[self generateTradeNO] Body:@"测试" Price:@"1" CouponFee:@"0" BalanceFee:@"0" NotifyUrl:@"http://unifypay.cnlive.com/test/notify_url" Type:CNLivePayCostPayTypeWeChatPay FrmId:@"debug"]; | ||
| 45 | NSDictionary * paramDict = @{ | 47 | NSDictionary * paramDict = @{ |
| 46 | @"orderId":[self generateTradeNO], | 48 | @"orderId":[self generateTradeNO], |
| 47 | @"userId":@"10458139", | 49 | @"userId":@"10458139", |
| @@ -70,14 +72,40 @@ | @@ -70,14 +72,40 @@ | ||
| 70 | @"notifyUrl":@"http://unifypay.cnlive.com/test/notify_url", | 72 | @"notifyUrl":@"http://unifypay.cnlive.com/test/notify_url", |
| 71 | @"password":@"123456" | 73 | @"password":@"123456" |
| 72 | }; | 74 | }; |
| 73 | - [CNLivePayCostModule showShopPayViwWithParamDict:paramDict PayType:CNLivePayCostPayTypeWeChatPay ResultBlock:^(CNLivePayCostTypeResult resultType) { | ||
| 74 | - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:resultType == CNLivePayCostTypeResultSucc?@"支付成功":@"支付失败" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil]; | 75 | + [CNLivePayCostModule showShopPayViwWithParamDict:paramDict PayType:CNLivePayCostPayTypeWeChatPay ResultBlock:^(NSInteger resultCode) { |
| 76 | + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:resultCode == 0?@"支付成功":@"支付失败" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil]; | ||
| 75 | [alert show]; | 77 | [alert show]; |
| 76 | }]; | 78 | }]; |
| 77 | } | 79 | } |
| 78 | -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event | 80 | -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event |
| 79 | { | 81 | { |
| 80 | [super touchesBegan:touches withEvent:event]; | 82 | [super touchesBegan:touches withEvent:event]; |
| 83 | + | ||
| 84 | + // appId+渠道+年月日+毫秒数后10位+2位数的随机数 | ||
| 85 | + NSString *randomOrderId = @""; | ||
| 86 | + //年月日 | ||
| 87 | + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | ||
| 88 | + [formatter setDateFormat:@"yyyyMMdd"]; | ||
| 89 | + NSDate *currentDate = [NSDate date]; | ||
| 90 | + NSString *currentDateString = [formatter stringFromDate:currentDate]; | ||
| 91 | + | ||
| 92 | + NSDateFormatter *formatters = [[NSDateFormatter alloc] init]; | ||
| 93 | + [formatters setDateStyle:NSDateFormatterMediumStyle]; | ||
| 94 | + [formatters setTimeStyle:NSDateFormatterShortStyle]; | ||
| 95 | + [formatters setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; | ||
| 96 | + NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"]; | ||
| 97 | + [formatters setTimeZone:timeZone]; | ||
| 98 | + NSDate *datenow = [NSDate date];//现在时间 | ||
| 99 | + NSInteger timeSp = [[NSNumber numberWithDouble:[datenow timeIntervalSince1970]] integerValue]; | ||
| 100 | + //取毫秒时间戳 | ||
| 101 | + NSString *timestamp13 = [NSString stringWithFormat:@"%ld", (long)[NSString stringWithFormat:@"%ld",(long)timeSp]]; | ||
| 102 | + | ||
| 103 | + //两位随机数 | ||
| 104 | + int x = arc4random() % 10; | ||
| 105 | + //拼接 | ||
| 106 | + randomOrderId = [NSString stringWithFormat:@"%@%@%@%d",AppId,currentDateString,[timestamp13 substringFromIndex:timestamp13.length - 4],x]; | ||
| 107 | + | ||
| 108 | + NSLog(@"%@",randomOrderId); | ||
| 81 | // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) { | 109 | // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) { |
| 82 | // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"alipays://"]]; | 110 | // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"alipays://"]]; |
| 83 | // } | 111 | // } |