Commit d15437f29c790ae91ee492ab9484ee67db2b6d75

Authored by 王军波
1 parent c7912647

修改

CNLivePaySDKDemo.xcodeproj/project.pbxproj
... ... @@ -8,10 +8,6 @@
8 8  
9 9 /* Begin PBXBuildFile section */
10 10 D2362F8D1EB3299300823BF5 /* PayMoneyTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2362F8C1EB3299300823BF5 /* PayMoneyTableViewCell.m */; };
11   - D2362FBD1EB8267F00823BF5 /* CNLivePaySDK.m in Sources */ = {isa = PBXBuildFile; fileRef = D2362FBA1EB8267F00823BF5 /* CNLivePaySDK.m */; };
12   - D2362FBE1EB8267F00823BF5 /* CNLivePayArg.m in Sources */ = {isa = PBXBuildFile; fileRef = D2362FBC1EB8267F00823BF5 /* CNLivePayArg.m */; };
13   - D2362FC41EB8269E00823BF5 /* CNLivePayNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D2362FC11EB8269E00823BF5 /* CNLivePayNetworkManager.m */; };
14   - D2362FC51EB8269E00823BF5 /* CNLivePayURLRequestSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = D2362FC31EB8269E00823BF5 /* CNLivePayURLRequestSerialization.m */; };
15 11 D2362FDF1EB827B500823BF5 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D2362FDE1EB827B500823BF5 /* libc++.tbd */; };
16 12 D2362FE11EB827C000823BF5 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D2362FE01EB827C000823BF5 /* libz.tbd */; };
17 13 D2362FE31EB827C700823BF5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2362FE21EB827C700823BF5 /* SystemConfiguration.framework */; };
... ... @@ -29,7 +25,7 @@
29 25 D236300D1EB8817400823BF5 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D23630081EB8817400823BF5 /* libWeChatSDK.a */; };
30 26 D236300E1EB8817400823BF5 /* README.txt in Resources */ = {isa = PBXBuildFile; fileRef = D23630091EB8817400823BF5 /* README.txt */; };
31 27 D265E5321ECAFA88006AE8B6 /* PayTypeTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D265E5311ECAFA88006AE8B6 /* PayTypeTableViewCell.m */; };
32   - D27934AD1EC1A3940028F26F /* CNLivePayResult.m in Sources */ = {isa = PBXBuildFile; fileRef = D27934AC1EC1A3940028F26F /* CNLivePayResult.m */; };
  28 + D2868FE01EE8F6260037DECF /* CNLivePaySDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2868FDF1EE8F6260037DECF /* CNLivePaySDK.framework */; };
33 29 D28B45AE1EB1CC1000ED24B5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D28B45AD1EB1CC1000ED24B5 /* main.m */; };
34 30 D28B45B11EB1CC1000ED24B5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D28B45B01EB1CC1000ED24B5 /* AppDelegate.m */; };
35 31 D28B45B41EB1CC1000ED24B5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D28B45B31EB1CC1000ED24B5 /* ViewController.m */; };
... ... @@ -41,14 +37,6 @@
41 37 /* Begin PBXFileReference section */
42 38 D2362F8B1EB3299300823BF5 /* PayMoneyTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PayMoneyTableViewCell.h; sourceTree = "<group>"; };
43 39 D2362F8C1EB3299300823BF5 /* PayMoneyTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PayMoneyTableViewCell.m; sourceTree = "<group>"; };
44   - D2362FB91EB8267F00823BF5 /* CNLivePaySDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CNLivePaySDK.h; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePaySDK.h; sourceTree = "<group>"; };
45   - D2362FBA1EB8267F00823BF5 /* CNLivePaySDK.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CNLivePaySDK.m; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePaySDK.m; sourceTree = "<group>"; };
46   - D2362FBB1EB8267F00823BF5 /* CNLivePayArg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CNLivePayArg.h; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePayArg.h; sourceTree = "<group>"; };
47   - D2362FBC1EB8267F00823BF5 /* CNLivePayArg.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CNLivePayArg.m; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePayArg.m; sourceTree = "<group>"; };
48   - D2362FC01EB8269E00823BF5 /* CNLivePayNetworkManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLivePayNetworkManager.h; sourceTree = "<group>"; };
49   - D2362FC11EB8269E00823BF5 /* CNLivePayNetworkManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLivePayNetworkManager.m; sourceTree = "<group>"; };
50   - D2362FC21EB8269E00823BF5 /* CNLivePayURLRequestSerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLivePayURLRequestSerialization.h; sourceTree = "<group>"; };
51   - D2362FC31EB8269E00823BF5 /* CNLivePayURLRequestSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLivePayURLRequestSerialization.m; sourceTree = "<group>"; };
52 40 D2362FDE1EB827B500823BF5 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
53 41 D2362FE01EB827C000823BF5 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
54 42 D2362FE21EB827C700823BF5 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
... ... @@ -70,8 +58,7 @@
70 58 D236300C1EB8817400823BF5 /* WXApiObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiObject.h; sourceTree = "<group>"; };
71 59 D265E5301ECAFA88006AE8B6 /* PayTypeTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PayTypeTableViewCell.h; sourceTree = "<group>"; };
72 60 D265E5311ECAFA88006AE8B6 /* PayTypeTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PayTypeTableViewCell.m; sourceTree = "<group>"; };
73   - D27934AB1EC1A3940028F26F /* CNLivePayResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CNLivePayResult.h; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePayResult.h; sourceTree = "<group>"; };
74   - D27934AC1EC1A3940028F26F /* CNLivePayResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CNLivePayResult.m; path = ../../CNLivePaySDK/CNLivePaySDK/CNLivePayResult.m; sourceTree = "<group>"; };
  61 + D2868FDF1EE8F6260037DECF /* CNLivePaySDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLivePaySDK.framework; sourceTree = "<group>"; };
75 62 D28B45A91EB1CC1000ED24B5 /* CNLivePaySDKDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CNLivePaySDKDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
76 63 D28B45AD1EB1CC1000ED24B5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
77 64 D28B45AF1EB1CC1000ED24B5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
... ... @@ -89,6 +76,7 @@
89 76 isa = PBXFrameworksBuildPhase;
90 77 buildActionMask = 2147483647;
91 78 files = (
  79 + D2868FE01EE8F6260037DECF /* CNLivePaySDK.framework in Frameworks */,
92 80 D236300D1EB8817400823BF5 /* libWeChatSDK.a in Frameworks */,
93 81 D23630071EB8725500823BF5 /* libsqlite3.0.tbd in Frameworks */,
94 82 D2362FF31EB8280400823BF5 /* CoreMotion.framework in Frameworks */,
... ... @@ -109,17 +97,6 @@
109 97 /* End PBXFrameworksBuildPhase section */
110 98  
111 99 /* Begin PBXGroup section */
112   - D2362FBF1EB8269E00823BF5 /* CNLiveNetworking */ = {
113   - isa = PBXGroup;
114   - children = (
115   - D2362FC01EB8269E00823BF5 /* CNLivePayNetworkManager.h */,
116   - D2362FC11EB8269E00823BF5 /* CNLivePayNetworkManager.m */,
117   - D2362FC21EB8269E00823BF5 /* CNLivePayURLRequestSerialization.h */,
118   - D2362FC31EB8269E00823BF5 /* CNLivePayURLRequestSerialization.m */,
119   - );
120   - path = CNLiveNetworking;
121   - sourceTree = "<group>";
122   - };
123 100 D2362FDD1EB827B500823BF5 /* Frameworks */ = {
124 101 isa = PBXGroup;
125 102 children = (
... ... @@ -180,7 +157,7 @@
180 157 D28B45AB1EB1CC1000ED24B5 /* CNLivePaySDKDemo */ = {
181 158 isa = PBXGroup;
182 159 children = (
183   - D2362FBF1EB8269E00823BF5 /* CNLiveNetworking */,
  160 + D2868FDF1EE8F6260037DECF /* CNLivePaySDK.framework */,
184 161 D2362FF91EB8516500823BF5 /* Alipay */,
185 162 D2362FFE1EB85BB800823BF5 /* WXApi */,
186 163 D28B45AF1EB1CC1000ED24B5 /* AppDelegate.h */,
... ... @@ -191,12 +168,6 @@
191 168 D2362F8C1EB3299300823BF5 /* PayMoneyTableViewCell.m */,
192 169 D265E5301ECAFA88006AE8B6 /* PayTypeTableViewCell.h */,
193 170 D265E5311ECAFA88006AE8B6 /* PayTypeTableViewCell.m */,
194   - D2362FB91EB8267F00823BF5 /* CNLivePaySDK.h */,
195   - D2362FBA1EB8267F00823BF5 /* CNLivePaySDK.m */,
196   - D2362FBB1EB8267F00823BF5 /* CNLivePayArg.h */,
197   - D2362FBC1EB8267F00823BF5 /* CNLivePayArg.m */,
198   - D27934AB1EC1A3940028F26F /* CNLivePayResult.h */,
199   - D27934AC1EC1A3940028F26F /* CNLivePayResult.m */,
200 171 D28B45B51EB1CC1000ED24B5 /* Main.storyboard */,
201 172 D28B45B81EB1CC1000ED24B5 /* Assets.xcassets */,
202 173 D28B45BA1EB1CC1000ED24B5 /* LaunchScreen.storyboard */,
... ... @@ -288,14 +259,9 @@
288 259 isa = PBXSourcesBuildPhase;
289 260 buildActionMask = 2147483647;
290 261 files = (
291   - D2362FBE1EB8267F00823BF5 /* CNLivePayArg.m in Sources */,
292   - D27934AD1EC1A3940028F26F /* CNLivePayResult.m in Sources */,
293   - D2362FBD1EB8267F00823BF5 /* CNLivePaySDK.m in Sources */,
294 262 D28B45B41EB1CC1000ED24B5 /* ViewController.m in Sources */,
295 263 D265E5321ECAFA88006AE8B6 /* PayTypeTableViewCell.m in Sources */,
296   - D2362FC41EB8269E00823BF5 /* CNLivePayNetworkManager.m in Sources */,
297 264 D28B45B11EB1CC1000ED24B5 /* AppDelegate.m in Sources */,
298   - D2362FC51EB8269E00823BF5 /* CNLivePayURLRequestSerialization.m in Sources */,
299 265 D28B45AE1EB1CC1000ED24B5 /* main.m in Sources */,
300 266 D2362F8D1EB3299300823BF5 /* PayMoneyTableViewCell.m in Sources */,
301 267 );
... ... @@ -421,6 +387,7 @@
421 387 FRAMEWORK_SEARCH_PATHS = (
422 388 "$(inherited)",
423 389 "$(PROJECT_DIR)/CNLivePaySDKDemo/Alipay",
  390 + "$(PROJECT_DIR)/CNLivePaySDKDemo",
424 391 );
425 392 INFOPLIST_FILE = CNLivePaySDKDemo/Info.plist;
426 393 IPHONEOS_DEPLOYMENT_TARGET = 8.0;
... ... @@ -444,6 +411,7 @@
444 411 FRAMEWORK_SEARCH_PATHS = (
445 412 "$(inherited)",
446 413 "$(PROJECT_DIR)/CNLivePaySDKDemo/Alipay",
  414 + "$(PROJECT_DIR)/CNLivePaySDKDemo",
447 415 );
448 416 INFOPLIST_FILE = CNLivePaySDKDemo/Info.plist;
449 417 IPHONEOS_DEPLOYMENT_TARGET = 8.0;
... ...
CNLivePaySDKDemo/AppDelegate.m
... ... @@ -8,7 +8,7 @@
8 8  
9 9 #import "AppDelegate.h"
10 10 #import "ViewController.h"
11   -#import "CNLivePaySDK.h"
  11 +#import <CNLivePaySDK/CNLivePaySDK.h>
12 12  
13 13 #define WXAppId @"wxbcb43c2700c2e6b3"
14 14 #define BundleId @"com.cnlive.shipinzhongguo"
... ...
CNLivePaySDKDemo/CNLiveNetworking/CNLivePayNetworkManager.h deleted 100644 → 0
1   -//
2   -// CNLiveNetworkManager.h
3   -// CNLiveHttpRequestDemo
4   -//
5   -// Created by Android on 16/7/26.
6   -// Copyright © 2016年 Android. All rights reserved.
7   -//
8   -
9   -#import <Foundation/Foundation.h>
10   -
11   -@interface CNLivePayNetworkManager : NSObject
12   -
13   -/**
14   - * 设置超时时间
15   - */
16   -@property (nonatomic, assign) NSTimeInterval timeoutInterval;
17   -
18   -/**
19   - * 缓存策略
20   - */
21   -@property (nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
22   -
23   -+ (nonnull CNLivePayNetworkManager *)manager;
24   -
25   -/**
26   - * GET 请求
27   - * @param URL url
28   - * @param parameters 上传参数
29   - * @param success 请求成功回调
30   - * @param failure 请求失败回调
31   - */
32   -- (void)requestGetURL:(nullable NSString *)URL
33   - parameters:(nullable NSDictionary *)parameters
34   - success:(nullable void (^)(NSURLResponse *_Nullable response, id _Nullable responseObject))success
35   - failure :(nullable void (^)(NSURLResponse *_Nullable response, NSError *_Nullable error))failure;
36   -
37   -/**
38   - * POST 请求
39   - * @param URL url
40   - * @param parameters 上传参数
41   - * @param success 请求成功回调
42   - * @param failure 请求失败回调
43   - */
44   -- (void)requestPostURL:(nullable NSString *)URL
45   - parameters:(nullable NSDictionary *)parameters
46   - success:(nullable void (^)(NSURLResponse *_Nullable response, id _Nullable responseObject))success
47   - failure :(nullable void (^)(NSURLResponse *_Nullable response, NSError *_Nullable error))failure;
48   -
49   -
50   -
51   -@end
CNLivePaySDKDemo/CNLiveNetworking/CNLivePayNetworkManager.m deleted 100644 → 0
1   -//
2   -// CNLiveNetworkManager.m
3   -// CNLiveHttpRequestDemo
4   -//
5   -// Created by Android on 16/7/26.
6   -// Copyright © 2016年 Android. All rights reserved.
7   -//
8   -
9   -#import "CNLivePayNetworkManager.h"
10   -#import "CNLivePayURLRequestSerialization.h"
11   -
12   -/**
13   - * 网络超时时间 默认 60
14   - */
15   -static NSTimeInterval TimeoutInterval = 30.0 ;
16   -
17   -/**
18   - * 缓存策略
19   - * NSURLRequestUseProtocolCachePolicy // 默认的缓存策略(取决于协议)
20   - * NSURLRequestReloadIgnoringLocalCacheData // 忽略缓存,重新请求
21   - * NSURLRequestReloadIgnoringLocalAndRemoteCacheData // 未实现
22   - * NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData // 忽略缓存,重新请求
23   - * NSURLRequestReturnCacheDataElseLoad// 有缓存就用缓存,忽略过期时间!没有缓存就重新请求
24   - * NSURLRequestReturnCacheDataDontLoad// 有缓存就用缓存,没有缓存就不发请求,当做请求出错处理(用于离线模式)
25   - * NSURLRequestReloadRevalidatingCacheData // 未实现
26   - */
27   -static NSURLRequestCachePolicy CachePolicy = NSURLRequestUseProtocolCachePolicy;
28   -
29   -@implementation CNLivePayNetworkManager
30   -
31   -+ (CNLivePayNetworkManager *)manager
32   -{
33   - static CNLivePayNetworkManager *manager = nil;
34   -
35   - static dispatch_once_t predicate;
36   -
37   - dispatch_once(&predicate, ^{
38   -
39   - manager = [[CNLivePayNetworkManager alloc] init];
40   -
41   - });
42   -
43   - manager.cachePolicy = CachePolicy;
44   -
45   - manager.timeoutInterval = TimeoutInterval;
46   -
47   - return manager;
48   -}
49   -
50   --(void)requestGetURL:(NSString *)URL
51   - parameters:(NSDictionary *)parameters
52   - success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success
53   - failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure
54   -{
55   - NSURLSessionDataTask *task = [self dataTaskWithRequestMethod:@"GET" URLString:URL parameters:parameters success:success failure:failure];
56   - [task resume];
57   -}
58   -
59   -- (void)requestPostURL:(NSString *)URL
60   - parameters:(NSDictionary *)parameters
61   - success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success
62   - failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure
63   -{
64   - NSURLSessionDataTask *task = [self dataTaskWithRequestMethod:@"POST" URLString:URL parameters:parameters success:success failure:failure];
65   - [task resume];
66   -}
67   -
68   -- (NSURLSessionDataTask *)dataTaskWithRequestMethod:(NSString *)method
69   - URLString:(NSString *)URLString
70   - parameters:(NSDictionary *)parameters
71   - success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success
72   - failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure
73   -{
74   -
75   - if (![URLString isKindOfClass:[NSString class]]) {
76   - NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"please enter a valid url"}];
77   - failure(nil, error);
78   - return nil;
79   - }
80   -
81   - NSString *newURLString;
82   - if ([method isEqualToString:@"GET"]) {
83   - if (parameters) {
84   - newURLString = [[URLString stringByAppendingString:@"?"] stringByAppendingString:[CNLivePayURLRequestSerialization
85   - CNQueryStringFromParameters:parameters]];
86   - }else{
87   - newURLString = URLString;
88   - }
89   - }else{
90   - newURLString = URLString;
91   - }
92   -
93   - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:newURLString] cachePolicy:self.cachePolicy timeoutInterval:self.timeoutInterval];
94   -
95   - request.HTTPMethod = method;
96   -
97   - if([method isEqual:@"POST"]){
98   - [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
99   - request.HTTPBody =[[CNLivePayURLRequestSerialization CNQueryStringFromParameters:parameters] dataUsingEncoding:NSUTF8StringEncoding];
100   - }
101   -
102   - NSURLSessionDataTask *task = [self dataTaskWithRequest:request success:success failure:failure];
103   -
104   - return task;
105   -}
106   -
107   -- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
108   - success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success
109   - failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure
110   -{
111   - NSURLSession *session = [NSURLSession sharedSession];
112   - NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
113   -
114   - dispatch_async(dispatch_get_main_queue(), ^{
115   - if (error) {
116   - failure(response,error);
117   - }else{
118   - if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
119   - NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
120   - if (httpResponse.statusCode < 400) {
121   - id jsonObj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
122   - success(httpResponse,jsonObj);
123   - } else {
124   - NSError *failureError = [NSError errorWithDomain:NSURLErrorDomain code:httpResponse.statusCode userInfo:httpResponse.allHeaderFields];
125   - failure(httpResponse,failureError);
126   - }
127   - } else {
128   - failure(response,error);
129   - }
130   - }
131   - });
132   - }];
133   -
134   - return task;
135   -}
136   -
137   -- (NSURL *)formatURLString:(NSString *)url
138   -{
139   - NSURL *urlString = [NSURL URLWithString:[url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
140   - return urlString;
141   -}
142   -
143   -@end
CNLivePaySDKDemo/CNLiveNetworking/CNLivePayURLRequestSerialization.h deleted 100644 → 0
1   -//
2   -// CNLiveURLRequestSerialization.h
3   -// CNLiveHttpRequestDemo
4   -//
5   -// Created by Android on 16/7/26.
6   -// Copyright © 2016年 Android. All rights reserved.
7   -//
8   -
9   -#import <Foundation/Foundation.h>
10   -
11   -@interface CNLivePayURLRequestSerialization : NSObject
12   -
13   -+ (nullable NSString *)CNQueryStringFromParameters:(nullable NSDictionary *)parameters;
14   -
15   -@end
CNLivePaySDKDemo/CNLiveNetworking/CNLivePayURLRequestSerialization.m deleted 100644 → 0
1   -//
2   -// CNLiveURLRequestSerialization.m
3   -// CNLiveHttpRequestDemo
4   -//
5   -// Created by Android on 16/7/26.
6   -// Copyright © 2016年 Android. All rights reserved.
7   -//
8   -
9   -#import "CNLivePayURLRequestSerialization.h"
10   -
11   -@interface CNLivePayURLRequestSerialization ()
12   -
13   -@property (readwrite, nonatomic, strong) id value;
14   -
15   -@property (readwrite, nonatomic, strong) id field;
16   -
17   -@end
18   -
19   -@implementation CNLivePayURLRequestSerialization
20   -
21   -- (id)initWithField:(id)field value:(id)value
22   -{
23   - self = [super init];
24   -
25   - if (self) {
26   -
27   - self.field = field;
28   -
29   - self.value = value;
30   - }
31   -
32   - return self;
33   -
34   -}
35   -
36   -#pragma mark -
37   -
38   -FOUNDATION_EXPORT NSArray * CNQueryStringPairsFromDictionary(NSDictionary *dictionary);
39   -FOUNDATION_EXPORT NSArray * CNQueryStringPairsFromKeyAndValue(NSString *key, id value);
40   -
41   -+ (NSString *)CNQueryStringFromParameters:(NSDictionary *)parameters
42   -{
43   - NSMutableArray *mutablePairs = [NSMutableArray array];
44   - for (CNLivePayURLRequestSerialization *pair in CNQueryStringPairsFromDictionary(parameters)) {
45   - [mutablePairs addObject:[pair URLEncodedStringValue]];
46   - }
47   - return [mutablePairs componentsJoinedByString:@"&"];
48   -}
49   -
50   -NSArray * CNQueryStringPairsFromDictionary(NSDictionary *dictionary)
51   -{
52   - return CNQueryStringPairsFromKeyAndValue(nil, dictionary);
53   -}
54   -
55   -/**
56   - * 处理上传参数
57   - */
58   -NSArray * CNQueryStringPairsFromKeyAndValue(NSString *key, id value)
59   -{
60   - NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
61   -
62   - //排序方式
63   - NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(compare:)];
64   -
65   - if ([value isKindOfClass:[NSDictionary class]]) { //字典
66   - NSDictionary *dictionary = value;
67   - for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[sortDescriptor]]) {
68   - id nestedValue = dictionary[nestedKey];
69   - if (nestedKey) {
70   - [mutableQueryStringComponents addObjectsFromArray:CNQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
71   - }
72   - }
73   - }
74   -
75   - else if ([value isKindOfClass:[NSArray class]]){ //数组
76   - NSArray *array = value;
77   - for (id nestedValue in array) {
78   - [mutableQueryStringComponents addObjectsFromArray:CNQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
79   - }
80   - }else if ([value isKindOfClass:[NSSet class]]){ //集合
81   - NSSet *set = value;
82   - for (id obj in [set sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
83   - [mutableQueryStringComponents addObjectsFromArray:CNQueryStringPairsFromKeyAndValue(key, obj)];
84   - }
85   - }else{ //其他类型
86   - [mutableQueryStringComponents addObject:[[CNLivePayURLRequestSerialization alloc] initWithField:key value:value]];
87   - }
88   -
89   - return mutableQueryStringComponents;
90   -}
91   -
92   -static NSString * CNPercentEscapedStringFromString(NSString *string) {
93   - static NSString * const kCNCharactersGeneralDelimitersToEncode = @":#[]@"; // does not include "?" or "/" due to RFC 3986 - Section 3.4
94   - static NSString * const kCNCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
95   -
96   - NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
97   - [allowedCharacterSet removeCharactersInString:[kCNCharactersGeneralDelimitersToEncode stringByAppendingString:kCNCharactersSubDelimitersToEncode]];
98   -
99   -
100   - static NSUInteger const batchSize = 50;
101   -
102   - NSUInteger index = 0;
103   - NSMutableString *escaped = @"".mutableCopy;
104   -
105   - while (index < string.length) {
106   -#pragma GCC diagnostic push
107   -#pragma GCC diagnostic ignored "-Wgnu"
108   - NSUInteger length = MIN(string.length - index, batchSize);
109   -#pragma GCC diagnostic pop
110   - NSRange range = NSMakeRange(index, length);
111   -
112   - range = [string rangeOfComposedCharacterSequencesForRange:range];
113   -
114   - NSString *substring = [string substringWithRange:range];
115   - NSString *encoded = [substring stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
116   - [escaped appendString:encoded];
117   -
118   - index += range.length;
119   - }
120   -
121   - return escaped;
122   -}
123   -
124   -- (NSString *)URLEncodedStringValue {
125   - if (!self.value || [self.value isEqual:[NSNull null]]) {
126   - return CNPercentEscapedStringFromString([self.field description]);
127   - } else {
128   - return [NSString stringWithFormat:@"%@=%@", CNPercentEscapedStringFromString([self.field description]), CNPercentEscapedStringFromString([self.value description])];
129   - }
130   -}
131   -
132   -
133   -@end
CNLivePaySDKDemo/CNLivePaySDK.framework/CNLivePaySDK 0 → 100644
No preview for this file type
CNLivePaySDKDemo/CNLivePaySDK.framework/Headers/CNLivePayArg.h 0 → 100644
  1 +//
  2 +// CNLivePayArg.h
  3 +// CNLivePaySDK
  4 +//
  5 +// Created by cnliveJunBo on 17/5/2.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +typedef enum {
  12 + CNLivePayTypeWeChatPay = 1,
  13 + CNLivePayTypeAliPay = 3,
  14 + CNLivePayTypeInAppPurchase = 1001
  15 +} CNLivePayType;
  16 +
  17 +@interface CNLivePayArg : NSObject
  18 +
  19 +/**
  20 + 视讯云平台获得的第三方平台帐号;
  21 + */
  22 +@property (nonatomic, copy) NSString * account;
  23 +
  24 +
  25 +/**
  26 + 支付类型(微信, 支付宝, 内购)
  27 + */
  28 +@property (nonatomic, assign) CNLivePayType type;
  29 +
  30 +
  31 +/**
  32 + 唯一业务系统中的订单号
  33 + */
  34 +@property (nonatomic, copy) NSString *out_trade_no;
  35 +
  36 +
  37 +/**
  38 + 商品价格,以分为单位,只能是整数;
  39 + */
  40 +@property (nonatomic, assign) int total_fee;
  41 +
  42 +
  43 +/**
  44 + 用户付款通知业务系统接收地址;不能有参数;
  45 + */
  46 +@property (nonatomic, copy) NSString *notify_url;
  47 +
  48 +
  49 +/**
  50 + 订单信息
  51 + */
  52 +@property (nonatomic, copy) NSString *body;
  53 +
  54 +
  55 +/**
  56 + 业务回传参数,传递参数用于给 notify_url 用户付款通知业务系统接收地址拼接参数;
  57 + 业务回传参数可以使用多个参数,由业务系统自行使用。但有长度限制,所有attach 的总字符长度不能超过300。 例如: attach.phone=13523455432 attach.others=o …
  58 + */
  59 +@property (nonatomic, strong) NSDictionary *attach;
  60 +
  61 +
  62 +/**
  63 + 业务系统用户ID
  64 + */
  65 +@property (nonatomic, copy) NSString *user_id;
  66 +
  67 +@end
... ...
CNLivePaySDKDemo/CNLivePaySDK.framework/Headers/CNLivePayResult.h 0 → 100644
  1 +//
  2 +// CNLivePayResult.h
  3 +// CNLivePaySDKDemo
  4 +//
  5 +// Created by cnliveJunBo on 17/5/3.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +/**
  12 + * 返回值详解
  13 + */
  14 +typedef NS_ENUM(NSUInteger, CNLiveBackExplain) {
  15 +
  16 + CNLive_CODE_SUCCESS = 2000, /**< 成功*/
  17 + CNLive_CODE_FAIL_CANCEL = 4004, /**< 用户取消支付*/
  18 + CNLive_CODE_ERROR_DEAL = 4201, /**< 处理中*/
  19 + CNLive_CODE_Failure = 4005, /**< 失败*/
  20 + CNLive_CODE_ERROR_CONNECT = 4202, /**< 网络错误*/
  21 + CNLive_CODE_ERROR_INSIDE = 4006, /**< SDK内部错误*/
  22 + CNLive_CODE_ERROR_NOTADDSDK = 4007, /**< 缺少相关SDK*/
  23 + CNLive_CODE_ERROR_WX_NOT_INSTALL = 4101, /**< 未安装微信*/
  24 + CNLive_CODE_ERROR_WX_NOT_SUPPORT_PAY = 4102, /**< 微信不支持OpenApi*/
  25 + CNLive_CODE_ERROR_WX_SENTFAIL = 4103, /**< 微信发送失败*/
  26 + CNLive_CODE_ERROR_WX_AUTHDENY = 4104, /**< 微信授权失败*/
  27 + CNLive_CODE_ChannelWrong = 4003, /**< 渠道信息错误*/
  28 + CNLive_CODE_ERROR_CHARGE_PARAMETER = 4002 /**< 参数信息错误*/
  29 +};
  30 +
  31 +@interface CNLivePayResult : NSObject
  32 +
  33 +/**
  34 + * 枚举详解
  35 + */
  36 +@property (assign, nonatomic) CNLiveBackExplain explain;
  37 +/**
  38 + * 错误描述
  39 + */
  40 +@property (copy, nonatomic) NSString *backDescription;
  41 +/**
  42 + * 支付渠道返回的错误码
  43 + */
  44 +@property (copy, nonatomic) NSString *channelBackCode;
  45 +/**
  46 + * 支付渠道
  47 + */
  48 +@property (copy, nonatomic) NSString *channel;
  49 +/**
  50 + * 支付渠道返回的信息
  51 + */
  52 +@property (strong, nonatomic) NSString *channelBackInfo;
  53 +
  54 +@end
... ...
CNLivePaySDKDemo/CNLivePaySDK.framework/Headers/CNLivePaySDK.h 0 → 100644
  1 +//
  2 +// CNLivePaySDK.h
  3 +// CNLivePaySDK
  4 +//
  5 +// Created by cnliveJunBo on 17/5/1.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +#import "CNLivePayArg.h"
  11 +#import "CNLivePayResult.h"
  12 +
  13 +typedef void(^CNLCompletionBlock)(CNLivePayResult *cnlivePayResult);
  14 +
  15 +@interface CNLivePaySDK : NSObject
  16 +
  17 +/**
  18 + 获取SDK当前版本号
  19 +
  20 + @return 返回SDK当前版本号
  21 + */
  22 ++ (NSString *)getVersion;
  23 +
  24 +
  25 +/**
  26 + 获取支付核心类单例
  27 +
  28 + @return 返回支付核心类单例
  29 + */
  30 ++ (instancetype)sharedCNLivePayManager;
  31 +
  32 +
  33 +/**
  34 + 注册支付SDK
  35 +
  36 + @param appid 从视讯云平台获取到的appId
  37 + @param appkey 从视讯云平台获取到的appKey
  38 + @warning 必须传参数 appid appkey
  39 + @discussion 您在使用支付SDK所有功能之前,您必须先调用此方法初始化SDK。在App整个生命周期中,您只需要执行一次初始化。
  40 +
  41 + @return 是否注册成功
  42 + */
  43 +- (BOOL) registerApp:(NSString *)appid AppKey:(NSString *)appkey;
  44 +
  45 +
  46 +/**
  47 + 注册微信支付(只有使用了微信支付才会使用到此方法)
  48 +
  49 + @param wxAppId 微信平台申请到的appId
  50 +
  51 + @return 是否注册成功
  52 + */
  53 +- (BOOL) registerWXApiWithWXAppId:(NSString *)wxAppId;
  54 +
  55 +
  56 +/**
  57 + 支付方法(微信, 支付宝)
  58 +
  59 + @param payArg 支付所需参数结构体;
  60 + @param schemeStr 支付宝支付时需要的appScheme,需要与info配置的scheme对应;其他支付不需要可填nil;
  61 + @param completionBlock 支付结果回调;
  62 + @discussion 支付宝 客户端, 网页 支付结果回调都在此方法中的block回调中;
  63 + 微信客户端支付结果回调在此方法中的block回调中;
  64 + */
  65 +- (void)pay:(CNLivePayArg *)payArg appScheme:(NSString *)schemeStr completion:(CNLCompletionBlock)completionBlock;
  66 +
  67 +
  68 +/**
  69 + 支付方法(内购)
  70 +
  71 + @param payArg 支付所需参数结构体;
  72 + @param isDebug 是否是测试环境,上线时务必改成NO;开发环境请填YES,内购支付会到沙盒环境下验证支付结果,验证成功才算支付成功,并且会给用户付款通知业务系统接收地址异步通知时返回参数 sandbox=1 后台可以此作为标记判断加不加商品;真实环境请填NO,内购支付会到真实环境下验证支付结果,验证成功才算支付成功;
  73 + @param productId 内购时商品的ID,只有内购时用到,其他支付可传nil;
  74 + @param completionBlock 支付结果回调;
  75 + @discussion 内购支付结果回调在此方法中的block回调中;
  76 + */
  77 +- (void)pay:(CNLivePayArg *)payArg isDebug:(BOOL)isDebug productId:(NSString *)productId completion:(CNLCompletionBlock)completionBlock;
  78 +
  79 +
  80 +/**
  81 + 处理支付渠道通过URL启动App时传递的数据
  82 + 在 appdelegate
  83 + iOS 8.0 以前
  84 + - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
  85 + iOS 9.0及以后
  86 + - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options;
  87 + 中实现此方法,否则支付结果回调无法实现;
  88 +
  89 + @param url 支付渠道在启动第三方应用时传递过来的URL
  90 +
  91 + @return 成功返回YES,失败返回NO;
  92 + */
  93 +- (BOOL)handleOpenURL:(NSURL *)url;
  94 +
  95 +@end
... ...
CNLivePaySDKDemo/CNLivePaySDK.framework/Info.plist 0 → 100644
No preview for this file type
CNLivePaySDKDemo/CNLivePaySDK.framework/Modules/module.modulemap 0 → 100644
  1 +framework module CNLivePaySDK {
  2 + umbrella header "CNLivePaySDK.h"
  3 +
  4 + export *
  5 + module * { export * }
  6 +}
... ...
CNLivePaySDKDemo/ViewController.m
... ... @@ -7,11 +7,9 @@
7 7 //
8 8  
9 9 #import "ViewController.h"
10   -#import "CNLivePaySDK.h"
  10 +#import <CNLivePaySDK/CNLivePaySDK.h>
11 11 #import "PayMoneyTableViewCell.h"
12 12 #import "PayTypeTableViewCell.h"
13   -#import <CommonCrypto/CommonDigest.h>
14   -#import "CNLivePayNetworkManager.h"
15 13  
16 14 #define bSWidth self.view.bounds.size.width
17 15 #define bSheight self.view.bounds.size.height
... ... @@ -50,66 +48,22 @@ static NSString *payTypeCellId = @&quot;payTypeCellId&quot;;
50 48 self.automaticallyAdjustsScrollViewInsets = NO;
51 49 }
52 50  
53   -#pragma mark - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
54   -#pragma mark 签名机制
55   -
56   -- (NSString *)sortParameters:(NSDictionary*)parameters
57   -{
58   - //对所有传入参数按照字段名的 ASCII 码从小到大排序
59   - NSArray *keyArr=[parameters allKeys];
60   - NSArray *arr = [keyArr sortedArrayUsingSelector:@selector(compare:)];
61   -
62   - NSMutableString *string1 = [[NSMutableString alloc]init];
63   - for (int i=0; i<arr.count; i++) {
64   -
65   - NSString *parametersString = parameters[[arr objectAtIndex:i]];
66   - if (parametersString.length > 0) {
67   - [string1 appendString:[NSString stringWithFormat:@"%@=%@&",[arr objectAtIndex:i],parameters[[arr objectAtIndex:i]]]];
68   - }
69   - }
70   -
71   - if (string1.length > 0) {
72   - [string1 deleteCharactersInRange:NSMakeRange(string1.length-1, 1)];
73   - }
74   -
75   - return string1;
76   -}
77   -
78   -
79   -#pragma mark SHA1加密 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80   -
81   -- (NSString*)sha1:(NSString *)string
82   -{
83   - NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
84   -
85   - uint8_t digest[CC_SHA1_DIGEST_LENGTH];
86   -
87   - CC_SHA1(data.bytes, (unsigned int)data.length, digest);
88   -
89   - NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
90   -
91   - for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
92   - [output appendFormat:@"%02x", digest[i]];
93   -
94   - while ([[output substringToIndex:1] isEqualToString:@"0"]) {
95   - output = [[NSMutableString alloc] initWithString:[output substringFromIndex:1]];
96   - }
97   -
98   - return output;
99   -}
100   -
101 51 #pragma mark - Pay !!!!!!!!!!!!!!!!!!!!!!
102 52 - (void)pay {
103 53  
104 54 self.button.selected = YES;
105 55 [_button setUserInteractionEnabled:NO];
106 56  
  57 + int total_fee = [_moneyCell.textField.text floatValue] * 100;
  58 + if (total_fee == 0) {
  59 + total_fee = 1;
  60 + }
107 61 if (_payType == 0) {
108 62 CNLivePayArg *arg = [[CNLivePayArg alloc] init];
109 63 arg.account = @"ztsx";
110 64 arg.type = CNLivePayTypeAliPay;
111 65 arg.out_trade_no = [self produceRandomNumber];
112   - arg.total_fee = [_moneyCell.textField.text floatValue] * 100;
  66 + arg.total_fee = total_fee;
113 67 arg.notify_url = @"http://unifypay.cnlive.com/test/notify_url";
114 68 arg.body = @"您购买了一头猪";
115 69 NSDictionary *dict = @{@"a":@"1",@"b":@"2",@"c":@"3"};
... ... @@ -130,7 +84,7 @@ static NSString *payTypeCellId = @&quot;payTypeCellId&quot;;
130 84 arg.account = @"liveshow";
131 85 arg.type = CNLivePayTypeWeChatPay;
132 86 arg.out_trade_no = [self produceRandomNumber];
133   - arg.total_fee = [_moneyCell.textField.text floatValue] * 100;
  87 + arg.total_fee = total_fee;
134 88 arg.notify_url = @"http://unifypay.cnlive.com/test/notify_url";
135 89 arg.body = @"您购买了一头牛";
136 90  
... ...