protected void Page_Load(object sender, EventArgs e) { BaseModel <Object> resultData = new BaseModel <Object>(); string uid = GetReqValue("uid"); string feeid = GetReqValue("feeid"); string from = GetReqValue("from"); string key = GetReqValue("key"); if (uid == "" || feeid == "" || from == "") { //检查openid和product_id是否返回 uid是否返回 WxPayError err = new WxPayError(); err.return_code = "FAIL"; err.return_msg = "统一下单失败"; resultData.code = 1; resultData.info = "统一下单失败"; resultData.result = err; Log.Info(this.GetType().ToString(), "The data WeChat post is error : " + LitJson.JsonMapper.ToJson(err)); } else { string paytype = "2"; AppPay appPay = new AppPay(); resultData = appPay.ProcessOrder(uid, feeid, from, paytype, key); } Response.ContentType = "application/json"; Response.Write(LitJson.JsonMapper.ToJson(resultData)); }
public BaseModel <Object> ProcessOrder(string uid, string feeid, string from, string paytype, string key) { //调统一下单接口,获得下单结果 WxPayData unifiedOrderResult = new WxPayData(); BaseModel <Object> resultData = new BaseModel <Object>(); try { AlipayOrder fee = GetFee(uid, feeid, from, paytype, key); unifiedOrderResult = UnifiedOrder(fee); //若下单失败,则立即返回结果给微信支付后台 if (!unifiedOrderResult.IsSet("appid") || !unifiedOrderResult.IsSet("mch_id") || !unifiedOrderResult.IsSet("prepay_id")) { WxPayError err = new WxPayError(); err.return_code = "FAIL"; err.return_msg = "统一下单失败"; resultData.code = 1; resultData.info = "统一下单失败"; resultData.result = err; return(resultData); } //统一下单成功,则返回成功结果给微信支付后台 //WxPayData data = new WxPayData(); //data.SetValue("return_code", "SUCCESS"); //data.SetValue("return_msg", "OK"); //data.SetValue("appid", WxPayConfig.APPID); //data.SetValue("mch_id", WxPayConfig.MCHID); //data.SetValue("key", WxPayConfig.KEY);//key //data.SetValue("nonce_str", WxPayApi.GenerateNonceStr()); //data.SetValue("prepay_id", unifiedOrderResult.GetValue("prepay_id")); //data.SetValue("result_code", "SUCCESS"); //data.SetValue("err_code_des", "OK"); //int amount = 0; //int.TryParse(fee.amount.ToString(), out amount); //data.SetValue("out_trade_no", fee.orderNo); //data.SetValue("fee_money", amount); //data.SetValue("fee_name", fee.feeName); //data.SetValue("fee_des", fee.fee_des); //data.SetValue("paytype", fee.paytype); //data.SetValue("crttime", fee.crttime); //data.SetValue("sign", data.MakeSign()); int amount = 0; if (com.zgyey.sgspay.common.AppSetting.Contains(com.zgyey.sgspay.common.AppSetting.DemoFeeids, feeid)) { amount = 1; } else { if (!int.TryParse(fee.amount.ToString(), out amount)) { amount = 100; } } object prepay_id = unifiedOrderResult.GetValue("prepay_id"); WxPaySuccess wp = new WxPaySuccess() { return_code = "SUCCESS", return_msg = "OK", appid = WxPayConfig.APPID, mch_id = WxPayConfig.MCHID, key = WxPayConfig.KEY,//key nonce_str = WxPayApi.GenerateNonceStr(), prepay_id = prepay_id, result_code = "SUCCESS", err_code_des = "OK", out_trade_no = fee.orderNo.ToString(), fee_money = amount, fee_name = fee.feeName.ToString(), fee_des = fee.fee_des.ToString(), paytype = fee.paytype, crttime = fee.crttime }; resultData.code = 0; resultData.info = "统一下单成功"; resultData.result = wp; Log.Info(this.GetType().ToString(), "UnifiedOrder success , send data to WeChat : " + LitJson.JsonMapper.ToJson(wp)); return(resultData); } catch (Exception ex)//若在调统一下单接口时抛异常,立即返回结果给微信支付后台 { WxPayError err = new WxPayError(); err.return_code = "FAIL"; err.return_msg = "统一下单失败"; resultData.code = 1; resultData.info = "统一下单失败"; resultData.result = err; Log.Error(this.GetType().ToString(), "UnifiedOrder failure : " + LitJson.JsonMapper.ToJson(err)); return(resultData); } }