/*** * 申请退款完整业务流程逻辑 * @param transaction_id 微信订单号(优先使用) * @param out_trade_no 商户订单号 * @param out_refund_no 商户退款单号 * @param total_fee 订单总金额 * @param refund_fee 退款金额 * @return 退款结果(xml格式) */ public static WxpayResult Run(string transaction_id, string out_trade_no, string out_refund_no, string total_fee, string refund_fee) { Log.Info("Refund", "Refund is processing..."); WxPayData data = new WxPayData(); if (!string.IsNullOrEmpty(transaction_id))//微信订单号存在的条件下,则已微信订单号为准 { data.SetValue("transaction_id", transaction_id); } else//微信订单号不存在,才根据商户订单号去退款 { data.SetValue("out_trade_no", out_trade_no); } data.SetValue("total_fee", int.Parse(total_fee)); //订单总金额 data.SetValue("refund_fee", int.Parse(refund_fee)); //退款金额 data.SetValue("out_refund_no", out_refund_no); data.SetValue("op_user_id", WxPayConfig.MCHID); //操作员,默认为商户号 WxPayData result = WxPayApi.Refund(data); //提交退款申请给API,接收返回数据 Log.Info("Refund", "Refund process complete, result : " + result.ToXml()); Log.Info("result_code", result.GetValue("result_code").ToString()); WxpayResult wxResult = new WxpayResult(); wxResult.result_code = result.GetValue("result_code") != null && result.GetValue("result_code").ToString() == "SUCCESS"; if (result.GetValue("err_code") != null) { wxResult.err_code = result.GetValue("err_code").ToString(); } if (result.GetValue("err_code_des") != null) { wxResult.err_code_des = result.GetValue("err_code_des").ToString(); } return(wxResult); //return result.GetValue("result_code") != null && result.GetValue("result_code").ToString() == "SUCCESS"; //return result.ToPrintStr(); }
/** * * 查询订单 * @param WxPayData inputObj 提交给查询订单API的参数 * @param int timeOut 超时时间 * @throws WxPayException * @return 成功时返回订单查询结果,其他抛异常 */ public static WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6) { string url = "https://api.mch.weixin.qq.com/pay/orderquery"; //检测必填参数 if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id")) { throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!"); } inputObj.SetValue("appid", WxPayConfig.SERVERAPPID); //公众账号ID inputObj.SetValue("mch_id", WxPayConfig.SERVERMCHID); //商户号 inputObj.SetValue("sub_appid", WxPayConfig.APPID); //公众账号ID inputObj.SetValue("sub_mch_id", WxPayConfig.MCHID); //商户号 //inputObj.SetValue("appid", WxPayConfig.APPID);//公众账号ID //inputObj.SetValue("mch_id", WxPayConfig.MCHID);//商户号 inputObj.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //随机字符串 inputObj.SetValue("sign", inputObj.MakeSign()); //签名 string xml = inputObj.ToXml(); var start = DateTime.Now; Log.Error("WxPayApi", "OrderQuery request : " + xml); string response = HttpService.Post(xml, url, false, timeOut);//调用HTTP通信接口提交数据 Log.Error("WxPayApi", "OrderQuery response : " + response); var end = DateTime.Now; int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时 //将xml格式的数据转化为对象以返回 WxPayData result = new WxPayData(); result.FromXml(response); ReportCostTime(url, timeCost, result);//测速上报 return(result); }
public static void Inition() { appId = WxPayConfig.APPID; timestamp = WxPayApi.GenerateTimeStamp(); nonceStr = WxPayApi.GenerateNonceStr(); }