美文网首页
iOS 集成支付功能 (微信支付 + 支付宝支付)

iOS 集成支付功能 (微信支付 + 支付宝支付)

作者: PittWong | 来源:发表于2016-07-07 17:46 被阅读297次

    微信支付

    流程 :
    移动端向后台发送购物请求 -> 后台发送相应信息发给微信 -> 微信生成订单反馈给后台 -> 后台反馈订单信息给移动端 -> 移动端用相应信息调用手机微信客户端 -> 完成支付收到相应反馈再给后台发送完成信息备案存储

    移动端工作

    1.下载微信支付SDK
    https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1

    2.在工程General中添加添加相应静态库

    B2F44D11-3980-4D24-81C7-7EAD9652AAB7.png

    3.在Info中添加 微信开发者ID


    4BECEABF-3ADC-4546-A9EC-95F30389D590.png

    4.appDelegate中程序已启动注册微信支付

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        [WXApi registerApp:@"wxb4ba3c02aa476ea1" withDescription:@"com.kdx.touchfound"];
    
        return YES;
    }```
    5.发送用户选择货品给后台,获取后台回馈的订单信息,填充后调用微信客户端
    
            NSMutableString *retcode = [dict objectForKey:@"retcode"];
            if (retcode.intValue == 0){
                NSMutableString *stamp = [dict objectForKey:@"timestamp"];
                
                //调起微信支付
                PayReq* req = [[PayReq alloc] init];
                req.partnerId = [dict objectForKey:@"partnerid"];
                req.prepayId = [dict objectForKey:@"prepayid"];
                req.nonceStr = [dict objectForKey:@"noncestr"];
                req.timeStamp = stamp.intValue;
                req.package = [dict objectForKey:@"package"];
                req.sign = [dict objectForKey:@"sign"];
                [WXApi sendReq:req];
                //日志输出
                NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
            }
    
    
    6.接收支付结果
    在AppDelegate中遵守协议  <WXApiDelegate>
    

    //用于接收支付结果

    • (void)onResp:(BaseResp *)resp {
      if ([resp isKindOfClass:[PayResp class]]) {
      NSString stringMsg,strTitle = @"支付结果";
      switch (resp.errCode) {
      case WXSuccess:
      stringMsg = @"支付结果 : 成功";
      NSLog(@"支付成功 - retcode = %d",resp.errCode);
      break;

            default:
                stringMsg = @"支付结果 : 失败";
                NSLog(@"支付成功 - retcode = %d",resp.errCode);
                break;
        } 
      

      }
      }
      //用于应用间跳转

    • (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
      return [WXApi handleOpenURL:url delegate:self];
      }

    相关文章

      网友评论

          本文标题:iOS 集成支付功能 (微信支付 + 支付宝支付)

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