public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); string out_trade_no= notifyData.GetValue("out_trade_no").ToString(); Log.Info(this.GetType().ToString(), "异步通知中的定单号:" + out_trade_no); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); //===========================修改定单状态 by xin.gao //确认支付,已支付,支付时间的更新 TOURISM.BLL.orders bll = new TOURISM.BLL.orders(); bool result = bll.UpdateField(out_trade_no, "status=2,payment_status=2,payment_id=4,payment_time='" + DateTime.Now + "'"); if (!result) { res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "修改订单状态失败 : " + res.ToXml()); } else { Log.Info(this.GetType().ToString(), "修改订单状态成功 : " + res.ToXml()); } //===========================修改定单状态结束 by xin.gao page.Response.Write(res.ToXml()); page.Response.End(); } }
public void WeiXinOrderPay(string order_no, string total_fee, string version, string equType, string equName) { try { Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing..."); WxPayData data = new WxPayData(); TOURISM.BLL.orders bll = new TOURISM.BLL.orders(); TOURISM.Model.orders model = bll.GetModel(order_no); if (model == null) { Context.Response.Write("{\"status\":\"false\",\"data\":\"定单号不存在\"}"); return; } decimal totalFree = 0; decimal.TryParse(total_fee, out totalFree); if (model.order_amount != totalFree) { Context.Response.Write("{\"status\":\"false\",\"data\":\"订单金额和支付金额不相符\"}"); return; } string time_stamp = WxPayApi.GenerateTimeStamp(); data.SetValue("body", model.order_goods == null ? "" : model.order_goods[0].goods_name);//商品描述 data.SetValue("attach", "test");//附加数据 data.SetValue("out_trade_no", order_no);//随机字符串 //注意total_fee是分,此处不能传小数,只能传整数 data.SetValue("total_fee", Convert.ToInt16(totalFree * 100).ToString());//总金额 data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));//交易起始时间 data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));//交易结束时间 data.SetValue("goods_tag", "gaoxin");//商品标记 data.SetValue("trade_type", "APP");//交易类型 data.SetValue("time_stamp", time_stamp);//时间戳 data.SetValue("product_id", order_no);//商品ID WxPayData result = WxPayApi.UnifiedOrder(data);//调用统一下单接口 //string _url = result.GetValue("code_url").ToString();//获得统一下单接口返回的二维码链接 string _prepayid = result.GetValue("prepay_id").ToString(); string _sign = result.GetValue("sign").ToString(); string _nonce_str = result.GetValue("nonce_str").ToString(); //Log.Info(this.GetType().ToString(), "webservice接口中url: " + _url + ",prepayid:" + _prepayid + ",sign:" + _sign); //进行二次签名,改变sign值(此方法在终端实现) Object json_result = new { //code_url = _url, prepay_id = _prepayid, sign = _sign, nonceStr = _nonce_str, package = "Sign=WXPay", time_stamp = time_stamp, message = "success", status = "true" }; //return url; //WriteWebServiceLog(version, equType, equName, "WeiXinOrderPay", ""); Context.Response.Write(ObjToJson.ToJson(json_result)); } catch (Exception ex) { Log.Info(this.GetType().ToString(), "error:" + ex.Message); Context.Response.Write("{\"status\":\"false\",\"data\":\"{}\",\"message\":\"" + ex.Message + "\"}"); } }