/// <summary> /// 统一下单, 获取预付单号 /// </summary> /// <param name="trade_sheet">交易订单</param> /// <param name="pay_notify_url">交易通知回调URL</param> /// <param name="app_id">公众号appid</param> /// <param name="mch_id">公众号mch_id</param> /// <param name="mch_secret">公众号mch_secret</param> /// <returns></returns> public static WXTradeResUnifiedOrder unifiedOrder(TradeSheetBase trade_sheet, string pay_notify_url, string app_id, string mch_id, string mch_secret) { if (trade_sheet == null || trade_sheet.sheet_no.isNull()) { return(new WXTradeResUnifiedOrder("传入订单信息有误")); } //将支付金额转换为分 if (trade_sheet.PayAmountCent <= 0) { return(new WXTradeResUnifiedOrder("传入金额有误")); } var post = new WXTradePostUnifiedOrder(); post.device_info = trade_sheet.device_info; if (post.device_info.isNull()) { post.device_info = "WEB"; } post.body = trade_sheet.product_name; post.out_trade_no = trade_sheet.sheet_no; post.total_fee = trade_sheet.PayAmountCent.ToString(); post.spbill_create_ip = trade_sheet.client_ip; post.trade_type = "JSAPI"; post.openid = trade_sheet.customer_open_id; post.notify_url = pay_notify_url; Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(post.getContent(app_id, mch_id, mch_secret))); string response = HttpUtil.postStream(WXUrls.UNIFIED_ORDER, null, stream); var result = new WXTradeResUnifiedOrder(); result.setContentString(response); return(result); }
/// <summary> /// 统一下单, 获取预付单号 /// </summary> /// <param name="trade_sheet">交易订单</param> /// <returns></returns> public WXTradeResUnifiedOrder unifiedOrder(TradeSheetBase trade_sheet) { return(WXUtil.unifiedOrder(trade_sheet, PAY_NOTIFY_URL, APP_ID, MCH_ID, MCH_SECRET)); }