1.导入框架
libWechatSDK.a WXApi.h WXApiObject.h
1.首先需要注册应用时的APPID以及APP_SECRET。
2.设置商户秘钥。
3.主要参数
//订单标题,展示给用户
NSString *order_name = @"2016流年运程全部解释";
//订单金额,单位(分)
NSString *order_price = @"600";//6元 价格
//================================
//预付单参数订单设置
//================================
srand( (unsigned)time(0) );
NSString *noncestr = [NSString stringWithFormat:@"%d", rand()];
NSString *orderno = [NSString stringWithFormat:@"%ld",time(0)];
NSMutableDictionary *packageParams = [NSMutableDictionary dictionary];
[packageParams setObject: appid forKey:@"appid"]; //开放平台appid
[packageParams setObject: mchid forKey:@"mch_id"]; //商户号
[packageParams setObject: @"APP-001" forKey:@"device_info"]; //支付设备号或门店号
[packageParams setObject: noncestr forKey:@"nonce_str"]; //随机串
[packageParams setObject: @"APP" forKey:@"trade_type"]; //支付类型,固定为APP
[packageParams setObject: order_name forKey:@"body"]; //订单描述,展示给用户
[packageParams setObject: NOTIFY_URL forKey:@"notify_url"]; //支付结果异步通知
[packageParams setObject: orderno forKey:@"out_trade_no"];//商户订单号
[packageParams setObject: @"192.168.10.183" forKey:@"spbill_create_ip"];//发器支付的机器ip
[packageParams setObject: order_price forKey:@"total_fee"]; //订单金额,单位为分
以上生成的内容用于微信的预支付
//调起微信支付
PayReq* req = [[PayReq alloc] init];
req.openID = [dict objectForKey:@"appid"]; //APPID
req.partnerId = [dict objectForKey:@"partnerid"]; //APP_SECRET
req.prepayId = [dict objectForKey:@"prepayid"]; //以上商户信息的xml格式拼串
req.nonceStr = [dict objectForKey:@"noncestr"]; //随机串
req.timeStamp = stamp.intValue;
req.package = [dict objectForKey:@"package"]; //Sign=WXPay
req.sign = [dict objectForKey:@"sign"]; //创建package签名 md5加密方法[WXUtil md5:contentString]
[WXApi sendReq:req]; //跳转微信支付