美文网首页
秋秋的支付宝

秋秋的支付宝

作者: 淡若烟 | 来源:发表于2016-07-30 10:49 被阅读63次

不能对不起我的几个粉丝~,我决定更新一篇文章啦~

点击支付宝 进入下载demo及创建应用的的平台啦~当然还有其他完全写好了的,这就给你们点我--demo

创建应用,挨个填写信息即可,这个让老板自己创去吧,创好了找他要账号

创建应用.png

当然,这些东西看起来太复杂了,我得给你一个实际的项目,跟 后台做过交互的,成功调起了,不然那些参数传过来传过去的,看着太过繁琐,还不如实际一些,程序猿,不就喜欢最直接的么,哪来那些弯弯扭扭~~

这几个东西,你懂的,先放进去,那个Alipay文件夹,demo里面都有,先下载了,拖进去

必要的库.png

在appledegate 导入#import "AlipaySDK/AlipaySDK.h"
并导入下面的代码
<pre><code>

-(BOOL)application:(UIApplication *)app openURL:(NSURL )url options:(NSDictionary)options<code>
{
if([url.host isEqualToString:@"safepay"])
{
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
}];
}
return YES;
}

</code></pre>

现在就去viewcontroller 调用
先写一个方法,然后在点击方法内调用传入价格商品名即可,这个时候跟后台之前商品数据进行对接即可。

<pre><code>
//支付宝付款
-(void)userpayWithMoney:(NSString *)money Productname:(NSString *)productname
{
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
NSString * resultStr = [user objectForKey:@"ordernum"];
Order *order = [[Order alloc] init];
order.partner = alipartner;//支付宝PID例@"2066511942711331"这里进行了宏定义
order.seller = aliseller;//支付宝商家账户这里进行了宏定义就是收钱那个账号
order.tradeNO = resultStr; //订单ID也就是订单号,可以自己随机生成传给后台,也可以后台生成传给展示数据,我这里是自己生成的,下面可以给你生成的代码(由商家自行制定)
//必须要商品标题
order.productName = productname; //商品标题
NSString * pricestr = [money stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"¥"]];
float p = [pricestr floatValue];
order.amount = [NSString stringWithFormat:@"%.2f",p]; //商品价格
order.notifyURL = payURL; //回调URL这里进行了宏定义,这个url找后台要
//以下参数是固定的
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showUrl = @"m.alipay.com";

//应用注册scheme,在AlixPayDemo-Info.plist定义URL types
NSString *appScheme = @"lalalla";//这个就自己写上你自己的了

//将商品信息拼接成字符串
NSString *orderSpec = [order description];
NSLog(@"orderSpec = %@",orderSpec);

//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(aliprivateKey);//支付宝私钥 怎么获取,这里有详解[私钥获取方法](http://blog.it985.com/12276.html)
NSString *signedString = [signer signString:orderSpec];

//将签名成功字符串格式化为订单字符串,请严格按照该格式
NSString *orderString = nil;
if (signedString != nil)
{
    orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
                   orderSpec, signedString, @"RSA"];
    
    [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"reslut = %@",resultDic);
        dispatch_async(dispatch_get_main_queue(),^{
            int success = [[resultDic objectForKey:@"resultStatus"] intValue] ;
            if (success==9000)
            {
                UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:@"支付成功" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction * act = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action)
                {
                    [self.navigationController pushViewController:[[OrderController alloc]init] animated:YES];
                }];
                [alertView addAction:act];
                
                [self presentViewController:alertView animated:YES completion:nil];
            }
            else if (success==6001)
            {
                UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:@"支付取消" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction * act = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alertView addAction:act];
                
                [self presentViewController:alertView animated:YES completion:nil];
            }
            else
            {
                UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:@"支付失败" preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction * act = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                [alertView addAction:act];
                
                [self presentViewController:alertView animated:YES completion:nil];
            }
        });
        
    }];
}

}

</code></pre>

相关文章

  • 秋秋的支付宝

    不能对不起我的几个粉丝~,我决定更新一篇文章啦~ 点击支付宝 进入下载demo及创建应用的的平台啦~当然还有其他完...

  • 秋的秋,不是秋

    #秋的秋,不是秋# 秋意渐浓,晚风习习~ 空气中弥漫着被你撩拨时而膨胀荷尔蒙的气息 我来或不来,你依然会静静绽放出...

  • 秋秋秋

  • 秋秋秋

    我知道我是如此的匮乏,羞于破土,羞于萌芽,扎根去吸收那些汁水和土壤,是多么满足。有情怀和信仰的根须,又是多么幸福在...

  • 泪奔!支付宝这两笔钱竟然两天后就过期了……

    大家好,我是「省钱达人」秋小叶! 今天我打开支付宝一看: 「Whaaaaat,我有 1602 个支付宝积分到 20...

  • 秋日胜春朝

    谁言秋之萧条? 谁言秋之凄凉? 秋花秋果秋绚烂, 秋梨秋豆秋丰收, 秋橘秋柿秋如意 秋柚秋枣秋甜蜜 秋云秋雁秋浪漫...

  • 秋秋

    初中的时候,我的男性同桌在看一本言情小说叫《麻雀要革命》,后来他借给我看了,还真是挺好看的,里面的女主叫麻秋秋,一...

  • 秋、秋

    叶子换了颜色 说要走了 云儿换了颜色 说不哭了 麦子换了颜色 说长大了 你背上行囊 说分手了 粉红色的日记本落满灰...

  • 秋秋

    秋天不回来吗?在寝室里默默的看着树人的文章,突然看见了《眉间尺》。哇⊙ω⊙原来鲁迅是玄幻修真的小说鼻祖啊|...

  • 秋秋

    秋秋,是一条狗。 因为凡是狗都必须有一个“球球”这样肥嘟嘟的名字,或者是“小白”这样小清新大众化的名字。我曾经很希...

网友评论

      本文标题:秋秋的支付宝

      本文链接:https://www.haomeiwen.com/subject/pextsttx.html