Commit 565bc7897fb7fc281ab0ad16c677b92ab1c7fe04
1 parent
45b84a46
update
Showing
1 changed file
with
72 additions
and
1 deletions
06.支付云/4.2app.md
| ... | ... | @@ -58,8 +58,10 @@ NSString *string = [NSString stringWithFormat:@"%@&key=%@", [self signvalue:para |
| 58 | 58 | |
| 59 | 59 | ``` |
| 60 | 60 | |
| 61 | -2)将步骤1中得到的string进行SHA1加密并全部大写即得到sign签名字符串,需要导入文件#import<CommonCrypto/CommonDigest.h> | |
| 61 | +2)将步骤1中得到的string进行SHA1加密并全部大写即得到sign签名字符串,需要导入文件 | |
| 62 | 62 | ```object-c |
| 63 | +#import<CommonCrypto/CommonDigest.h> | |
| 64 | + | |
| 63 | 65 | NSString *signString = [[self sha1:string] uppercaseString]; |
| 64 | 66 | |
| 65 | 67 | - (NSString*)sha1:(NSString *)string |
| ... | ... | @@ -77,6 +79,75 @@ NSString *signString = [[self sha1:string] uppercaseString]; |
| 77 | 79 | } |
| 78 | 80 | ``` |
| 79 | 81 | sign样例: 7656A9FEFB5D8A08AB41723A843FC3C0B3818A0A |
| 82 | + | |
| 83 | +3)请求支付云预支付订单接口 | |
| 84 | +预支付订单的参数列表中必传参数(包括生成的sign)和非必传参数(根据业务需求自行判断需传哪些参数)拼接成参数字典,请求预支付订单接口https://api.cnlive.com/open/api2/unifypay/prepay | |
| 85 | +将支付云返回数据解析(支付宝为例),需导入头文件 | |
| 86 | + | |
| 87 | +```object-c | |
| 88 | +#import<AlipaySDK/AlipaySDK.h> | |
| 89 | + | |
| 90 | +NSDictionary *parameters = @{@"account":account, //和支付云对接app支付对应的命名一致 如: @"testDemoAlipay" | |
| 91 | + @"type":@"3",//以支付宝为例 | |
| 92 | + @"appId":AppId, //AppID | |
| 93 | + @"out_trade_no":outTradeNo, //唯一订单号 | |
| 94 | + @"total_fee":totalFee, //订单总价 | |
| 95 | + @"notify_url":notifyUrl, //回调地址(用户付款通知业务系统接收地址) | |
| 96 | + @"body":body, //订单信息 | |
| 97 | +@"user_id":userId, //用户id | |
| 98 | + @"attach.sid":userId, //用户id | |
| 99 | +@"attach.orderId":outTradeNo, //唯一订单号 | |
| 100 | +@"attach.value":descript,//商品描述 | |
| 101 | + @"sign":signString//RSA加密签名串 | |
| 102 | + }; | |
| 103 | + | |
| 104 | +__block NSString *signedString = @""; | |
| 105 | +[[AFHTTPRequestOperationManager manager] POST:prepay parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
| 106 | + if ([[NSString stringWithFormat:@"%@", responseObject[@"errorCode"]] isEqualToString:@"0"]) | |
| 107 | + { | |
| 108 | + signedString=responseObject[@"data"][@"alipay_app"]; | |
| 109 | + NSString *orderString = nil; | |
| 110 | + NSString *appScheme = @"testDemo您的app包名"; | |
| 111 | + if (signedString != nil) { | |
| 112 | + orderString = signedString; | |
| 113 | + | |
| 114 | + [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) { | |
| 115 | + NSString *resultStr = [resultDic objectForKey:@"resultStatus"]; | |
| 116 | + if ([resultStr isEqualToString:@"9000"]) { | |
| 117 | + //PaySuccess支付成功 | |
| 118 | + } | |
| 119 | + else if ([resultStr isEqualToString:@"6001"]) { | |
| 120 | + //UserCancel用户取消 | |
| 121 | + } | |
| 122 | + else {//PayFailure支付失败 | |
| 123 | + } | |
| 124 | + }]; | |
| 125 | + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
| 126 | +}]; | |
| 127 | + | |
| 128 | +``` | |
| 129 | +```object-c | |
| 130 | +4) AppDelegate.m中添加支付结果客户端回调判断 | |
| 131 | +- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ | |
| 132 | + if ([url.host isEqualToString:@"safepay"]) {//支付宝支付结果 | |
| 133 | + [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { | |
| 134 | + NSLog(@"result = %@",resultDic); | |
| 135 | + NSString *resultStr = [resultDic objectForKey:@"resultStatus"]; | |
| 136 | +if ([resultStr isEqualToString:@"9000"]) { | |
| 137 | +//PaySuccess | |
| 138 | + } | |
| 139 | +else if ([resultStr isEqualToString:@"6001"]) | |
| 140 | +{//UserCancel | |
| 141 | + } | |
| 142 | +else { | |
| 143 | +//PayFailure | |
| 144 | + } | |
| 145 | + }]; | |
| 146 | + return YES; | |
| 147 | + } | |
| 148 | + return NO; | |
| 149 | +} | |
| 150 | +``` | |
| 80 | 151 | ##### Android |
| 81 | 152 | |
| 82 | 153 | ### 支付宝接入 | ... | ... |