/// <summary> /// 统一下单xml结果转化实体 /// </summary> /// <param name="xml">xml</param> /// <returns>统一下单结果</returns> public static UnifiedOrderResult ConvertToUnifiedOrderResult(string xml) { UnifiedOrderResult unifiedOrderResult = new UnifiedOrderResult(); XElement doc = XElement.Parse(xml); if (doc.Element("return_code").GetString() == "SUCCESS") { if (doc.Element("result_code").GetString() == "SUCCESS") { unifiedOrderResult.IsSuccess = true; unifiedOrderResult.Appid = doc.Element("appid").GetString(); unifiedOrderResult.MchId = doc.Element("mch_id").GetString(); unifiedOrderResult.DeviceInfo = doc.Element("device_info").GetString(); unifiedOrderResult.NonceStr = doc.Element("nonce_str").GetString(); unifiedOrderResult.Sign = doc.Element("sign").GetString(); unifiedOrderResult.TradeType = doc.Element("trade_type").GetString(); unifiedOrderResult.PrepayId = doc.Element("prepay_id").GetString(); } else { unifiedOrderResult.IsSuccess = false; unifiedOrderResult.Message = doc.Element("err_code_des").GetString(); } } else { unifiedOrderResult.IsSuccess = false; unifiedOrderResult.Message = doc.Element("return_msg").GetString(); } return(unifiedOrderResult); }
public UnifiedOrderResult UnifiedOrderByJsApi(WxAppInfoConfig config, string openId, string orderSn, decimal orderAmount, string goods_tag, string ip, string body, DateTime?time_expire = null) { var ret = new UnifiedOrderResult(); TenpayUtil tenpayUtil = new TenpayUtil(config); UnifiedOrder unifiedOrder = new UnifiedOrder(); unifiedOrder.openid = openId; unifiedOrder.out_trade_no = orderSn; //商户订单号 unifiedOrder.spbill_create_ip = "192.168.1.1"; //终端IP unifiedOrder.total_fee = Convert.ToInt32(orderAmount * 100); //标价金额 unifiedOrder.body = body; //商品描述 unifiedOrder.trade_type = "JSAPI"; if (time_expire != null) { unifiedOrder.time_expire = time_expire.Value.ToString("yyyyMMddHHmmss"); } if (!string.IsNullOrEmpty(goods_tag)) { unifiedOrder.goods_tag = goods_tag; } ret = tenpayUtil.UnifiedOrder(unifiedOrder); return(ret); }
public UnifiedOrderResult PostXml(UnifiedOrderParam param) { SetParams(param); ValidateParameters(); ResultBuilder resultBuilder = PostForResult(Url, false, TimeOut); resultBuilder.BasicValidate(); UnifiedOrderResult result = new UnifiedOrderResult(resultBuilder); return(result); }
/// <summary> /// 获取掉起支付签名 /// </summary> /// <param name="result">统一下单结果</param> /// <param name="config">配置</param> /// <returns>参数</returns> public static SortedDictionary <string, string> GetPaySign(UnifiedOrderResult result, Config config) { SortedDictionary <string, string> sParams = new SortedDictionary <string, string> { { "appid", config.GetAppId() }, { "partnerid", config.GetPid() }, { "prepayid", result.PrepayId }, { "package", "Sign=WXPay" }, { "noncestr", Config.GetNoncestr() }, { "timestamp", Config.GetTimestamp() }, }; var sign = Signature.Getsign(sParams, config.GetKey()); sParams.Add("sign", sign); return(sParams); }
//public UnifiedOrderResult UnifiedOrder(UnifiedOrder order) //{ // var rt = new UnifiedOrderResult(); // TenpayUnifiedOrderApi api = new TenpayUnifiedOrderApi(_config, order); // var result = _request.DoPost(_config, api); // string prepayId = null; // result.TryGetValue("prepay_id", out prepayId); // rt.PrepayId = prepayId; // return rt; //} public UnifiedOrderResult UnifiedOrder(UnifiedOrder order) { var rt = new UnifiedOrderResult(); TenpayUnifiedOrderApi api = new TenpayUnifiedOrderApi(_config, order); var result = _request.DoPost(_config, api); string prepayId = null; string code_url = null; result.TryGetValue("prepay_id", out prepayId); result.TryGetValue("code_url", out code_url); rt.PrepayId = prepayId; rt.CodeUrl = code_url; return(rt); }
/// <summary> /// 创建微信支付参数 /// </summary> /// <param name="parameters">签名参数</param> /// <param name="unifiedOrderResult">统一下单参数</param> /// <returns>结果</returns> public static UnifiedOrderResult CreatePayParameters(SortedDictionary <string, string> parameters, UnifiedOrderResult unifiedOrderResult) { UnifiedOrderResult result = new UnifiedOrderResult { Appid = parameters["appid"], DeviceInfo = unifiedOrderResult.DeviceInfo, IsSuccess = unifiedOrderResult.IsSuccess, Message = unifiedOrderResult.Message, MchId = parameters["partnerid"], PrepayId = parameters["prepayid"], NonceStr = parameters["noncestr"], Timestamp = parameters["timestamp"], Sign = parameters["sign"], TradeType = unifiedOrderResult.TradeType }; return(result); }
public UnifiedOrderResult UnifiedOrderByNative(WxAppInfoConfig config, string merchantId, string orderSn, decimal orderAmount, string goods_tag, string ip, string body, DateTime time_expire) { var ret = new UnifiedOrderResult(); TenpayUtil tenpayUtil = new TenpayUtil(config); UnifiedOrder unifiedOrder = new UnifiedOrder(); unifiedOrder.openid = ""; unifiedOrder.out_trade_no = orderSn; //商户订单号 unifiedOrder.spbill_create_ip = ip; //终端IP unifiedOrder.total_fee = Convert.ToInt32(orderAmount * 100); //标价金额 unifiedOrder.body = body; //商品描述 unifiedOrder.trade_type = "NATIVE"; unifiedOrder.time_expire = time_expire.ToString("yyyyMMddHHmmss"); unifiedOrder.goods_tag = goods_tag; unifiedOrder.attach = "{\"merchantId\":\"" + merchantId + "\"}"; ret = tenpayUtil.UnifiedOrder(unifiedOrder); return(ret); }
/// <summary> /// 提交到微信,返回二维码的URL,通过二维码工具解析它 /// </summary> /// <param name="orderid">订单号</param> /// <param name="vMoney">单位:分</param> /// <param name="userID">用户ID</param> /// <param name="product_id">产品ID</param> /// <returns></returns> public string RechargeTo(string orderid, decimal vMoney, int userID, string product_id = "") { var totalfee = (int)vMoney; string strImaUrl = string.Empty; Dictionary <string, string> dictReturnParams = new Dictionary <string, string>(); try { WxPayClient client = GetWxPayClient(); UnifiedOrderParam unifiedOrderParam = new UnifiedOrderParam() { Body = "微信支付", Out_trade_no = orderid, Total_fee = totalfee, Spbill_create_ip = "", Time_start = DateTime.Now.ToString("yyyyMMddHHmmss"), Time_expire = DateTime.Now.AddMinutes(30).ToString("yyyyMMddHHmmss"), Trade_type = TradeType.NATIVE, Product_id = product_id }; UnifiedOrderResult result = client.CreateUnifiedOrder(unifiedOrderParam); if (result.Success) { dictReturnParams.Add("CodeUrl", result.Code_Url); dictReturnParams.Add("PrepayId", result.Prepay_Id); strImaUrl = result.Code_Url; } else { dictReturnParams.Add("Error", result.ErrorMessage); } } catch (Exception ex) { dictReturnParams.Add("Error", ex.Message); } return(strImaUrl); }