博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
支付-微信支付(1)
阅读量:6423 次
发布时间:2019-06-23

本文共 3426 字,大约阅读时间需要 11 分钟。

  1. 微信支付
- (void)wechatPayClick{    NSMutableDictionary *dict = [NSMutableDictionary dictionary];    [dict setObject:WeChatAppID forKey:@"appid"];    [dict setObject:@"税务代理预缴税金" forKey:@"body"];    [dict setObject:WeChatMCH_ID forKey:@"mch_id"];    [dict setObject:[AppMethod getRandomString] forKey:@"nonce_str"];    [dict setObject:WeChatNOTIFY_URL forKey:@"notify_url"];        [dict setObject:@"ZLDD-201703070014" forKey:@"out_trade_no"];    [dict setObject:[AppMethod deviceIPAdress] forKey:@"spbill_create_ip"];    [dict setObject:@"1" forKey:@"total_fee"];    [dict setObject:@"APP" forKey:@"trade_type"];        NSDictionary *params = [AppMethod partnerSignOrder:dict];        NSString *postStr = [params XMLString];    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.mch.weixin.qq.com/pay/unifiedorder"]];    [request setHTTPMethod:@"POST"];    [request addValue: @"text/html,text/plain,text/json" forHTTPHeaderField:@"Content-Type"];    [request setHTTPBody:[postStr dataUsingEncoding:NSUTF8StringEncoding]];        NSURLSession *requestSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];        NSURLSessionDataTask *task = [requestSession  dataTaskWithRequest:request completionHandler:^(NSData * _Nullable body , NSURLResponse * _Nullable response, NSError * _Nullable error) {                                                                        NSLog(@"Response object: %@" , response);                    NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];                    //   NSDictionary *dic=[bodyString mj_JSONObject];                    //打印应答中的body                    NSLog(@"Response body: %@" , body);                    NSDictionary *dic=     [[XMLDictionaryParser sharedInstance] dictionaryWithData:body];                                        PayReq* req             = [[PayReq alloc] init];                    req.partnerId           = WeChatMCH_ID;                    req.prepayId            = [dic objectForKey:@"prepay_id"];                    req.nonceStr            = [dic objectForKey:@"nonce_str"];                    req.timeStamp           = [[NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSince1970]] intValue];                    req.package             = @"Sign=WXPay";                                        NSMutableDictionary *rdict = [NSMutableDictionary dictionary];                    [rdict setObject:WeChatAppID forKey:@"appid"];                    [rdict setObject:req.partnerId forKey:@"partnerid"];                    [rdict setObject:req.prepayId forKey:@"prepayid"];                    [rdict setObject:req.nonceStr forKey:@"noncestr"];                    [rdict setObject:[NSString stringWithFormat:@"%u",(unsigned int)req.timeStamp] forKey:@"timestamp"];                    [rdict setObject:req.package forKey:@"package"];                    NSDictionary *result = [AppMethod partnerSignOrder:rdict];                                                            req.sign                = [result objectForKey:@"sign"];                                        [WXApi sendReq:req];                                                                                                                        }];    [task resume];    }复制代码
  • 拼接参数:

  • 上传接口,获取预下单ID,打开微信,支付

转载于:https://juejin.im/post/5b8f7d3f5188255ca00c6b50

你可能感兴趣的文章
一句话下拖库
查看>>
Deploy Office Communications Server 2007R2 Group Chat Server(二)
查看>>
在Cacti上实现MSN报警机制
查看>>
如何对C++虚基类构造函数
查看>>
XFire WebService开发快速起步
查看>>
JavaScript 函数replace揭秘
查看>>
QTP解决内嵌IE窗体方法2
查看>>
“王子”的演讲:N828印象
查看>>
判断JS字符串中是否包含某些字符
查看>>
Phalanger---PHP的.NET编译器
查看>>
Scanner----java控制台和文件读取的利器(java 5新增)
查看>>
如何安全设定和检测你的密码安全性?
查看>>
一例HP ADG数据恢复成功(8×73GB SCSI)
查看>>
虚拟化系列-Citrix XenServer 6.1 XenMotion与HA
查看>>
TFS创建团队项目(三)
查看>>
对发展的一点小感想
查看>>
示例化讲解RIP路由更新机制
查看>>
eclipse不能自动编译工程的解决方法
查看>>
Powershell管理系列(九)删除Exchange用户邮箱中多余的电子邮件地址
查看>>
Swt/Jface进度条
查看>>