//生成二维码地址 private string GetPayUrl(v4_pay_logVModel pay) { //pay.IsPay = 1; string body = string.Format("【{0}{1}】电费充值", pay.ModuleAddr, "");//商品描述; int total_fee = (int)(pay.PayAmt * 100); string out_trade_no = ""; string productId = pay.Co_id.ToString() + "-" + pay.Module_id.ToString() + "-" + pay.ModuleAddr; string urlPay = ""; urlPay = new WxPayAPI.WxPay().GetPayUrl(productId, body, total_fee, out out_trade_no); pay.Trade_no = out_trade_no; return(urlPay); }
public APIRst GetYdAlarmOfChargeChkPay(string pTrade_no, string pPayType) { APIRst rst = new APIRst(); string status = ""; string out_trade_no = CommFunc.ConvertDBNullToString(pTrade_no); int payType = CommFunc.ConvertDBNullToInt32(pPayType); if (string.IsNullOrEmpty(out_trade_no)) { status = "订单号为空"; } else { try { bool pass = false; if (payType == 1) { pass = new WxPayAPI.WxPay().GetResult(out_trade_no, out status); } else if (payType == 2) { pass = new WxPayAPI.WxPay().GetRefundQuery(out_trade_no, out status); } else { status = "支付类型错误"; } rst.rst = pass; rst.err.msg = status; rst.data = status; //if (pass == true) // status = "检测到已经成功支付到微信账号中"; //else // status = "未成功支付到微信账号"; } catch (Exception ex) { status = "检测错误:" + ex.Message + " 请重试!"; rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = status; } } return(rst); }
public HttpResponseMessage GetYdPayOnQrCode(string pQrUrl) { try { if (string.IsNullOrEmpty(pQrUrl)) { return(new HttpResponseMessage(HttpStatusCode.NoContent)); } System.Drawing.Bitmap image = new WxPayAPI.WxPay().GetQrCode(pQrUrl); //保存为PNG到内存流 System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //输出二维码图片 var resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new StreamContent(new System.IO.MemoryStream(ms.GetBuffer())); resp.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png"); return(resp); } catch (Exception ex) { FileLog.WriteLog("产生二维码错误(YdPostPayInMd_01OnQrCode)", ex.Message + ex.StackTrace); throw new Exception("产生二维码错误(YdPostPayInMd_01OnQrCode)" + ex.Message); } }
// 回调 public APIRst YdPrepPayInMdRecallPay(int pId, int pMid, string pTrade_no) { long log_id = CommFunc.ConvertDBNullToLong(pId); int module_id = CommFunc.ConvertDBNullToInt32(pMid); string out_trade_no = CommFunc.ConvertDBNullToString(pTrade_no); APIRst rst = new APIRst(); string msg = ""; string status = ""; bool result = false; bool pass = true; bool upSb = true; bool upDb = false; DateTime dtNow = DateTime.Now; long cmd_log_id = 0; #region 检查支付结果并更新数据库 System.Threading.Thread.Sleep(1000);/*一秒检查一次*/ object row = ""; object osObj = new { upSb = false, upDb = false, msg = "" }; try { if (string.IsNullOrEmpty(out_trade_no)) { result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id); } else { lock (ObjLock) {/*每次只能单独运行,目的是防止重复更新数据库的充值信息(重要事情)*/ pass = new WxPayAPI.WxPay().GetResult(out_trade_no, out status); if (pass == true) { result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id); } } } // if (result == true) { string msg2 = ""; if (cmd_log_id != 0) //立刻发送命令到网关 { /*充值命令*/ upSb = false; upSb = new YdToGw(user.Ledger, user.Uid).YdToGwAgain(cmd_log_id, out upDb, out msg2); } else { upDb = true;/*是否下发命令网关*/ } //#region 发送命令到网关(这款用于河北工业大学的SB设备,特殊定制化) //DataTable cmdPay = bll.GetGwPayData(module_id); //foreach (DataRow dr in cmdPay.Rows) //{ // decimal sbRdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]); // decimal sbSyZsVal = CommFunc.ConvertDBNullToDecimal(dr["SyZsVal"]); // CommandVModel cmd = ModelHandler<CommandVModel>.FillModel(dr); // cmd.Fun_id = 0; // cmd.FunType = "PaySb1"; // cmd.FunName = "充电"; // cmd.DataValue = (sbRdVal - sbSyZsVal).ToString("f2"); // cmd.Descr = "充电"; // cmd.IsUI = true; // cmd.IsNDb = true; // new YdToGw(user.Ledger, user.Uid).SendCmd(cmd); // // // cmd = ModelHandler<CommandVModel>.FillModel(dr); // cmd.Fun_id = 0; // cmd.FunType = "PaySb2"; // cmd.FunName = "增电"; // cmd.DataValue = sbSyZsVal.ToString("f2"); // cmd.Descr = "增电"; // cmd.IsUI = true; // cmd.IsNDb = true; // new YdToGw(user.Ledger, user.Uid).SendCmd(cmd); //} //#endregion //#region 发送短信 //bll.SendSms(log_id); //#endregion v4_pay_logVModel vpay = bll.GetV4_pay_log(log_id); osObj = new { upSb = upSb, upDb = upDb, msg = msg2 }; decimal chrgVal = 0, useVal = 0, rdVal = 0, syZsVal = 0; DataTable dtSource = bll.GetYdPostPayInMdOnList(module_id); if (dtSource.Rows.Count > 0) { chrgVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["ChrgVal"]); useVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["UseVal"]); rdVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["RdVal"]); syZsVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["SyZsVal"]); } row = new { ChrgVal = chrgVal.ToString("f2"), UseVal = useVal.ToString("f2"), RdVal = rdVal.ToString("f2"), SyVal = (rdVal - syZsVal).ToString("f2"), SyZsVal = syZsVal.ToString("f2") }; //判断是否拉闸 YDS6000.BLL.Exp.Syscont.ParameterBLL sysBll = new YDS6000.BLL.Exp.Syscont.ParameterBLL(user.Ledger, user.Uid); var dt = sysBll.GetAlarmCfg(); if (dt != null && dt.Rows.Count > 0) { decimal odValue = CommFunc.ConvertDBNullToDecimal(dt.Rows[0]["CfValue"]); int isClosed = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Rule"]); if (isClosed == 1) { if (rdVal <= odValue) { if (!YdBatchControlOfSsr("Ssr", "1", module_id.ToString())) { FileLog.WriteLog("拉闸失败(YdPrepPayInMdRecallPay)", "拉闸失败"); } } else { if (vpay.PayType == (int)PayType.pay) {/*充值动作才能合闸*/ if (!YdBatchControlOfSsr("Ssr", "0", module_id.ToString())) { FileLog.WriteLog("合闸失败(YdPrepPayInMdRecallPay)", "合闸失败"); } } } } } } object obj = new { pass = pass, row = row, osObj = osObj }; rst.rst = result; rst.data = obj; rst.err.msg = msg; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("预付费错误(YdPrepPayInMdRecallPay)", ex.Message + ex.StackTrace); } #endregion return(rst); }