/** * * 查询订单 * @param WxPayData inputObj 提交给查询订单API的参数 * @param int timeOut 超时时间 * @throws WxPayException * @return 成功时返回订单查询结果,其他抛异常 */ public static WxPayData OrderQuery(int paymentId, WxPayData inputObj, int timeOut = 6) { string sendUrl = "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至少填一个!"); } JsApiConfig jsApiConfig = new JsApiConfig(paymentId); inputObj.SetValue("appid", jsApiConfig.AppId); //公众账号ID inputObj.SetValue("mch_id", jsApiConfig.Partner); //商户号 inputObj.SetValue("nonce_str", GenerateNonceStr()); //随机字符串 inputObj.SetValue("sign", inputObj.MakeSign(jsApiConfig.Key)); //签名 string xml = inputObj.ToXml(); var startTime = DateTime.Now; //开始时间 string response = HttpService.Post(xml, sendUrl, false, timeOut); //调用HTTP通信接口提交数据 var endTime = DateTime.Now; //结束时间 int timeCost = (int)((endTime - startTime).TotalMilliseconds); //计算所用时间 //将xml格式的数据转化为对象以返回 WxPayData result = new WxPayData(); result.FromXml(response, jsApiConfig.Key); ReportCostTime(paymentId, sendUrl, timeCost, result);//测速上报 return(result); }
/** * * 测速上报接口实现 * @param WxPayData inputObj 提交给测速上报接口的参数 * @param int timeOut 测速上报接口超时时间 * @throws WxPayException * @return 成功时返回测速上报接口返回的结果,其他抛异常 */ public static WxPayData Report(int paymentId, WxPayData inputObj, int timeOut = 1) { JsApiConfig jsApiConfig = new JsApiConfig(paymentId); string url = "https://api.mch.weixin.qq.com/payitil/report"; //检测必填参数 if (!inputObj.IsSet("interface_url")) { throw new WxPayException("接口URL,缺少必填参数interface_url!"); } if (!inputObj.IsSet("return_code")) { throw new WxPayException("返回状态码,缺少必填参数return_code!"); } if (!inputObj.IsSet("result_code")) { throw new WxPayException("业务结果,缺少必填参数result_code!"); } if (!inputObj.IsSet("user_ip")) { throw new WxPayException("访问接口IP,缺少必填参数user_ip!"); } if (!inputObj.IsSet("execute_time_")) { throw new WxPayException("接口耗时,缺少必填参数execute_time_!"); } inputObj.SetValue("appid", jsApiConfig.AppId); //公众账号ID inputObj.SetValue("mch_id", jsApiConfig.Partner); //商户号 inputObj.SetValue("user_ip", DTRequest.GetIP()); //终端ip inputObj.SetValue("time", DateTime.Now.ToString("yyyyMMddHHmmss")); //商户上报时间 inputObj.SetValue("nonce_str", GenerateNonceStr()); //随机字符串 inputObj.SetValue("sign", inputObj.MakeSign(jsApiConfig.Key)); //签名 string xml = inputObj.ToXml(); string response = HttpService.Post(xml, url, false, timeOut); WxPayData result = new WxPayData(); result.FromXml(response, jsApiConfig.Key); return(result); }