1.導(dǎo)入框架?
libWechatSDK.a?? WXApi.h ? WXApiObject.h
1.首先需要注冊應(yīng)用時的APPID以及APP_SECRET。
2.設(shè)置商戶秘鑰旺芽。
3.主要參數(shù)
//訂單標題,展示給用戶
NSString *order_name? ? = @"2016流年運程全部解釋";
//訂單金額,單位(分)
NSString *order_price? = @"600";//6元 價格
//================================
//預(yù)付單參數(shù)訂單設(shè)置
//================================
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"]; //支付設(shè)備號或門店號
[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"];? //支付結(jié)果異步通知
[packageParams setObject: orderno? ? ? ? ? forKey:@"out_trade_no"];//商戶訂單號
[packageParams setObject: @"192.168.10.183"? ? forKey:@"spbill_create_ip"];//發(fā)器支付的機器ip
[packageParams setObject: order_price? ? ? forKey:@"total_fee"];? ? ? //訂單金額,單位為分
以上生成的內(nèi)容用于微信的預(yù)支付
//調(diào)起微信支付
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"];? ? //創(chuàng)建package簽名 md5加密方法[WXUtil md5:contentString]
[WXApi sendReq:req]; ? //跳轉(zhuǎn)微信支付