Commit 6d93e3ec5293439a0a84bbc5644d31e541ae83c0

Authored by liushiyu
1 parent ea59aec8

0.0.5

CNLivePayCostModule.podspec
... ... @@ -8,7 +8,7 @@
8 8  
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLivePayCostModule'
11   - s.version = '0.0.4'
  11 + s.version = '0.0.5'
12 12 s.summary = 'A short description of CNLivePayCostModule.'
13 13  
14 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 39 /// @param resultBlock 支付结果
40 40 +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict
41 41 PayType:(CNLivePayCostPayType)payType
42   - ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock;
  42 + ResultBlock:(void(^)(NSInteger resultCode))resultBlock;
43 43  
44 44 @end
45 45  
... ...
CNLivePayCostModule/Classes/Core/CNLivePayCostModule.m
... ... @@ -208,7 +208,7 @@
208 208 /// @param resultBlock 支付结果
209 209 +(void)showShopPayViwWithParamDict:(NSDictionary *)paramDict
210 210 PayType:(CNLivePayCostPayType)payType
211   - ResultBlock:(void(^)(CNLivePayCostTypeResult resultType))resultBlock
  211 + ResultBlock:(void(^)(NSInteger resultCode))resultBlock
212 212 {
213 213 NSString * orderId = [paramDict stringValueForKey:@"orderId" default:@""];
214 214 NSString * body = [paramDict stringValueForKey:@"body" default:@""];
... ... @@ -220,10 +220,8 @@
220 220  
221 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 227 @end
... ...
CNLivePayCostModule/Classes/Core/CNLivePayCostNetwork.m
... ... @@ -55,8 +55,15 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN
55 55 PassWord:(NSString *)password
56 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 64 if (type == CNLivePayCostPayTypeWeChatPay) {
59   - NSString * path = [NSString stringWithFormat:@"pages/pays/pay/pay?appId=%@&body=%@&out_trade_no=%@&user_id=%@&total_fee=%@&notify_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=%@&notify_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 67 NSLog(@"===>%@",path);
61 68 WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
62 69 launchMiniProgramReq.userName = @"gh_061b347b32c1"; //拉起的小程序的username
... ... @@ -67,12 +74,6 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN
67 74 }];
68 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 77 NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body;
77 78  
78 79 NSDictionary * paramDict = @{
... ... @@ -80,7 +81,7 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN
80 81 @"user_id":CNUserShareModel.uid?CNUserShareModel.uid:@"",
81 82 @"out_trade_no":orderId,
82 83 @"body":desc,
83   - @"coupon_fee":@"0",
  84 + @"coupon_fee":coupon_fee,
84 85 @"balance_fee":price,
85 86 @"notify_url":notifyUrls,
86 87 @"page_url":@"",
... ... @@ -98,11 +99,13 @@ static NSString *const CNLiveWillBecomeActivePaycostForSHShopNotification = @"CN
98 99 if (completerBlock) completerBlock(0);
99 100 }else{
100 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 115 if (type == CNLivePayCostPayTypeUnionPay) index = @"9";
113 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 118 NSString * desc = threeType == CNLivePayCostThreePayTypeScren?@"扫码支付":body;
122 119  
123 120 NSDictionary * paramDict = @{
... ...
Example/CNLivePayCostModule/CNLIVEViewController.m
... ... @@ -38,10 +38,12 @@
38 38 [batchBtn setTitle:@"电商支付" forState: UIControlStateHighlighted];
39 39 [batchBtn addTarget:self action:@selector(batchRequestAction) forControlEvents:UIControlEventTouchUpInside];
40 40 [self.view addSubview:batchBtn];
  41 +
  42 +
  43 +
41 44 }
42 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 47 NSDictionary * paramDict = @{
46 48 @"orderId":[self generateTradeNO],
47 49 @"userId":@"10458139",
... ... @@ -70,14 +72,40 @@
70 72 @"notifyUrl":@"http://unifypay.cnlive.com/test/notify_url",
71 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 77 [alert show];
76 78 }];
77 79 }
78 80 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
79 81 {
80 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 109 // if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]]) {
82 110 // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"alipays://"]];
83 111 // }
... ...