tijian_tieying/web/dccdc/Controllers/xgController.cs

997 lines
44 KiB
C#
Raw Normal View History

2025-02-20 12:14:39 +08:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Remoting;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using dccdc.BLL;
using dccdc.DAL;
using dccdc.Models;
using Newtonsoft.Json;
using QRCoder;
/*using sancai.Model;*/
namespace dccdc.Controllers
{
public class xgController : Controller
{
#region
private string GetOAuthOpenId(string code)
{
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Common.Global.YMAppId + "&secret=" + Common.Global.YMAppsecret + "&code=" + code + "&grant_type=authorization_code";
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream(); //获取响应的字符串流
if (stream != null)
{
StreamReader sr = new StreamReader(stream); //创建一个stream读取流
string html = sr.ReadToEnd(); //从头读到尾放到字符串html李米
sr.Close();
stream.Close();
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(html);
return html;
}
return "";
}
#endregion
// GET: xg
[AllowAnonymous]
public ActionResult yy(string djType)
{
try
{
HttpCookie hou = Request.Cookies["xgopenuser"];
if (hou != null && (!string.IsNullOrEmpty(hou.Value)))
{
Session["xgopenuser"] = hou.Value;
}
if (Session["xgopenuser"] == null || Session["xgopenuser"].ToString() == "")
{
string code = Request.QueryString["code"];
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("ss" + code);
if (string.IsNullOrEmpty(code))
{
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
"&redirect_uri=" + Url.Encode(Common.Global.getParmValue("xgrul")) +
"&response_type=code&scope=snsapi_base#wechat_redirect");
}
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sb" + code);
//string openidstr = geto;
var openidstr = GetOAuthOpenId(code);
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
Session["xgopenuser"] = openid.openid;
HttpCookie hc = new HttpCookie("xgopenuser");
hc.Value = openid.openid;
Response.Cookies.Add(hc);
/*
bool sfgz = db.sfgz(openid.openid);
if (!sfgz)
{
return RedirectToAction("nosub");
}*/
}
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sb" + Session["xgopenuser"]);
var xgydj = new xg_yyxx();
xgydj.openid = Session["xgopenuser"].ToString();
xgydj = new xgDal().gethavenodjyy(xgydj.openid);
/*
var hy = db.gethybyopenid(Session["openuser"].ToString());
if (hy != null)
{
Session["HY"] = hy;
return RedirectToAction("myhome");
}
*/
if (xgydj == null)
{
xgydj = new xg_yyxx();
}
else
{
if ( string.IsNullOrEmpty(djType))
{
return RedirectToAction("myyy");
}
else
{
xgydj = new xg_yyxx();
}
}
return View(xgydj);
}
catch (Exception ex)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(ex.Message + ex.StackTrace);
return View();
}
}
[AllowAnonymous]
public string savedj(string tm, string yyid)
{
tm = tm.ToUpper();
if (!tm.StartsWith("HS"))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "条码格式不正确!" });
}
if (tm.IndexOf("IN1") < 3)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "条码格式不正确!" });
}
int c;
string sc = tm.Substring(0, tm.IndexOf("IN1"));
sc = sc.Replace("HS", "");
if (!int.TryParse(sc, out c))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "条码格式不正确!" });
}
var dal = new xgDal();
Models.xg_ydytm vtm = dal.getydytm(tm);
if (vtm == null)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "系统中无当前条码记录!" });
}
if (vtm.czyid == 0)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "当前条码还未出库!" });
}
vtm.bdsj = DateTime.Now;
int yyc = dal.gettmyycs(tm);
if (yyc >= c)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "当前条码登记人数已超过" + c + "人,不能再登记!" });
}
//var xgyy = new xgDal();
var jryy = dal.getjryyid(yyid);
//string sjh = "";
if (jryy == null)
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "预约信息异常!" });
if (dal.jrydj(jryy.sfzh))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "今日已登记不能重复登记!" });
}
string cks = "";
for (int i = 0; i < jryy.yymx.Length; i++)
{
cks += jryy.yymx[i].xmid + ",";
}
cks = cks.Trim(',');
var djxx = new xgDjxx();
djxx.bgbh = jryy.xlh;
djxx.bgzt = 0;
djxx.djid = vtm.czyid;
djxx.djsj = DateTime.Now;
djxx.guid = Guid.NewGuid().ToString("N");
djxx.djxm = dal.getczyname(vtm.czyid);
djxx.xm = jryy.xm;
djxx.sfzh = jryy.sfzh;
djxx.sjh = jryy.sjh;
djxx.yyid = jryy.id;
djxx.xlh = tm;
djxx.djsj = DateTime.Now;
djxx.jcrq = DateTime.Now.ToString("yyyy-MM-dd");
djxx.ypmc = "";
foreach (string yp in cks.Split(','))
{
var y = dal.getyp(yp);
djxx.jcxm += y.jcxm + "、";
if (!djxx.ypmc.Contains(y.bmxm))
djxx.ypmc += y.bmxm + "、";
}
dal.savedjxx(djxx, cks.Split(','));
jryy.djzt = 1;
jryy.djsj = DateTime.Now;
jryy.djrxm = dal.getczyname(vtm.czyid);
jryy.djrid = vtm.czyid;
dal.gxyyxx(jryy);
vtm.bdsj = DateTime.Now;
dal.gxtmsysj(vtm);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "登记成功!" });
}
[AllowAnonymous]
public string saveyy(xg_yyxx yyxx, string scks)
{
HttpCookie hou = Request.Cookies["xgopenuser"];
if (Session["xgopenuser"] == null && hou != null && (!string.IsNullOrEmpty(hou.Value)))
{
Session["xgopenuser"] = hou.Value;
}
if (Session["xgopenuser"] == null || Session["xgopenuser"].ToString() == "")
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "获取微信信息失败,请重新扫描二维码登记!" });
}
var xgyy = new xgDal();
yyxx.yyrq = DateTime.Now.Date;
bool jryy = xgyy.checkjryy(yyxx);
if (jryy)
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = "您预约人员今天已经预约请不要重复预约!" });
else
{
yyxx.xlh = DateTime.Now.ToString("yyyyMMdd").Substring(2) + (int.Parse(new G_identityBll().GetMaxId("XG" + DateTime.Now.ToString("yyyyMMdd"), 1)) + 1000);
yyxx.yysj = DateTime.Now;
yyxx.openid = Session["xgopenuser"].ToString();
yyxx.djzt = 0;
if(string.IsNullOrEmpty(yyxx.djType))
{
yyxx.djType = "my";
}
}
try
{
xgyy.savedj(yyxx, scks);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "登记成功!" });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = ex.Message });
}
}
[AllowAnonymous]
public string xgtm(string id)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new xgDal().getxgtm(id));
}
public string deletedj(string id)
{
try
{
var dal = new xgDal();
dal.deletedj(id);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = "删除成功!" });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
}
}
public string reportids(string ids)
{
var user = Session["loginUser"] as ERPUser;
try
{
var dal = new xgDal();
string[] idz = ids.Split(',');
foreach (var id in idz)
{
if (!string.IsNullOrEmpty(id))
dal.reportid(id, user.ID);
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = "操作成功!" });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
}
}
[AllowAnonymous]
public string xgdj(string xm, string sjh, string sfzh, string cks, string username, string xlh, string jmqr)
{
try
{
if (string.IsNullOrEmpty(cks))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "请选择检查样本!" }); ;
}
if (!string.IsNullOrEmpty(username))
{
Session["loginUser"] = new DAL.ERPUserDal().getbyusername(username);
}
if (Session["loginUser"] == null)
Session["loginUser"] = new ERPUser { ID = -1, TrueName = "自助助机" };
var user = Session["loginUser"] as ERPUser;
var xgdal = new xgDal();
if (xgdal.jrydj(sfzh))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "今日已登记不能重复登记!" });
}
var yyxx = xgdal.getjryy(sfzh);
var djxx = new xgDjxx();
djxx.xm = xm;
djxx.sfzh = sfzh;
djxx.sjh = sjh;
if (yyxx != null)
{
djxx.bgbh = yyxx.xlh;
djxx.yyid = yyxx.id;
yyxx.djzt = 1;
yyxx.djrid = user.ID;
yyxx.djrxm = user.TrueName;
yyxx.djsj = DateTime.Now;
}
else
{
djxx.bgbh = DateTime.Now.ToString("yyyyMMdd").Substring(2) + (int.Parse(new G_identityBll().GetMaxId("XG" + DateTime.Now.ToString("yyyyMMdd"), 1)) + 1000);
}
if (!string.IsNullOrEmpty(xlh))
{
djxx.bgbh = xlh;
}
djxx.bgzt = 0;
djxx.jcrq = DateTime.Now.ToString("yyyy-MM-dd");
string[] jcyps = cks.Trim(',').Split(',');
djxx.ypmc = "";
foreach (string yp in jcyps)
{
var y = xgdal.getyp(yp);
djxx.jcxm += y.jcxm + "、";
if (!djxx.ypmc.Contains(y.bmxm))
djxx.ypmc += y.bmxm + "、";
}
//djxx.jcxm.Trim('、');
//djxx.ypmc.Trim('、');
djxx.djid = user.ID;
djxx.djxm = user.TrueName;
djxx.djsj = DateTime.Now;
int id = xgdal.savedjxx(djxx, jcyps);
if (yyxx != null)
{
xgdal.gxyyxx(yyxx);
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = "登记成功!", id });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
}
}
public string getyyxx(string sfzh)
{
var xgyy = new xgDal();
var jryy = xgyy.getjryy(sfzh);
//string sjh = "";
if (jryy == null)
jryy = new xg_yyxx();
return Newtonsoft.Json.JsonConvert.SerializeObject(jryy);
}
[AllowAnonymous]
public string getyyxxxlh(string xlh)
{
var xgyy = new xgDal();
var jryy = xgyy.getjryyxlh(xlh);
//string sjh = "";
if (jryy == null)
jryy = new xg_yyxx();
return Newtonsoft.Json.JsonConvert.SerializeObject(jryy);
}
[AllowAnonymous]
public FileResult down(string id, string guid)
{
/*
HttpCookie hou = Request.Cookies["xgsfz"];
if (Session["xgsfz"] == null && hou != null && (!string.IsNullOrEmpty(hou.Value)))
{
Session["xgsfz"] = hou.Value;
}
if (Session["xgsfz"] == null || Session["xgsfz"].ToString() == "")
{
Bitmap b = new Bitmap(800, 600);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, 800, 600);
var sf = g.MeasureString("验证信息异常请重新验证!", new Font("微软雅黑", 16));
var l = 800 / 2 - sf.Width / 2;
var t = 600 / 2 - sf.Height / 2;
g.DrawString("验证信息异常请重新验证!", new Font("微软雅黑", 16), Brushes.Red, l, t);
MemoryStream ems = new MemoryStream();
b.Save(ems, System.Drawing.Imaging.ImageFormat.Jpeg);
ems.Position = 0;
return File(ems, "image/jpeg");
}
*/
FastReport.Report webReport = new FastReport.Report(); // 创建报表对象
System.IO.MemoryStream ms = new System.IO.MemoryStream();
FastReport.Export.Image.ImageExport pdf = new FastReport.Export.Image.ImageExport();
//webReport.Width = 1150;//设置报表宽度
//webReport.Height = 780;//设置报表高度
try
{
var dal = new xgDal();
var djxx = dal.getJYSQD(int.Parse(id), guid);
/*
if (djxx.sfzh != Session["xgsfz"].ToString())
{
Bitmap b = new Bitmap(800, 600);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, 800, 600);
var sf = g.MeasureString("非验证报告!", new Font("微软雅黑", 16));
var l = 800 / 2 - sf.Width / 2;
var t = 600 / 2 - sf.Height / 2;
g.DrawString("非验证报告!", new Font("微软雅黑", 16), Brushes.Red, l, t);
MemoryStream ems = new MemoryStream();
b.Save(ems, System.Drawing.Imaging.ImageFormat.Jpeg);
ems.Position = 0;
return File(ems, "image/jpeg");
}*/
DataTable dt = new DataTable(); //Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(Newtonsoft.Json.JsonConvert.SerializeObject(new xgDal().getJYSQD(int.Parse(id))));
dt.Columns.Add("bgbm");
dt.Columns.Add("ypmc");
dt.Columns.Add("jcrq");
dt.Columns.Add("jcxm");
dt.Columns.Add("xm");
dt.Columns.Add("sfzh");
dt.Columns.Add("ysz");
dt.Columns.Add("gsz");
dt.Columns.Add("xqkt");
dt.Columns.Add("bgrq");
dt.Columns.Add("pic_jy", typeof(byte[]));
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
dr["jcrq"] = djxx.jcrq;
dr["bgbm"] = djxx.bgbh;
dr["bgrq"] = djxx.bgrq;
dr["xm"] = djxx.xm;
dr["sfzh"] = djxx.sfzh;
dr["ypmc"] = djxx.ypmc.Substring(0, djxx.ypmc.Length - 1);
dr["jcxm"] = djxx.jcxm.Substring(0, djxx.jcxm.Length - 1);
dr["ysz"] = dal.getjg(djxx.id, 1);
dr["gsz"] = dal.getjg(djxx.id, 2);
dr["xqkt"] = dal.getjg(djxx.id, 3);
dr["pic_jy"] = Common.Global.getqm(djxx.jyid);
webReport.Load(this.Server.MapPath("~/report/") + "dcjkbg.frx");//调用报表
webReport.RegisterData(dt, "bg"); //传递数据
//webReport.SetParameterValue("JYFF", dt3.Rows[0]["Jcfamc"].ToString());
webReport.Prepare();
}
catch (Exception ex)
{
//ViewBag.errmsg = ex.Message;
Bitmap b = new Bitmap(800, 600);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, 800, 600);
var sf = g.MeasureString(ex.Message, new Font("微软雅黑", 16));
var l = 800 / 2 - sf.Width / 2;
var t = 600 / 2 - sf.Height / 2;
g.DrawString(ex.Message, new Font("微软雅黑", 16), Brushes.Red, l, t);
MemoryStream ems = new MemoryStream();
b.Save(ems, System.Drawing.Imaging.ImageFormat.Jpeg);
ems.Position = 0;
return File(ems, "image/jpeg");
}
//ViewBag.WebReport = webReport;//赋值报表给页面
webReport.Export(pdf, ms);
webReport.Dispose();
ms.Position = 0;
return File(ms, "image/jpeg");
}
[AllowAnonymous]
public string addydytm(string barcode)
{
int state = 0;
if (new xgDal().addydytm(barcode))
{
state = 1;
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state, msg = "", tag = "" });
}
/// <summary>
/// 打印分配页面
/// </summary>
/// <returns></returns>
public ActionResult fenpei()
{
return View();
}
public string gettmzt()
{
var dal = new xgDal();
int tmcount = 0;
string tmmin = "";
string tmmax = "";
tmcount = dal.getkytmcount();
tmmin = dal.getmin();
tmmax = dal.getmax();
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, tmcount, tmmin, tmmax });
}
public string tmlyjl(int page, int pagesize, string s_lyr, string s_lysj)
{
int c;
var list = new xgDal().tmlyjm(page, pagesize, s_lyr, s_lysj, out c);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Rows = list, Total = c });
}
public string getczy(string key)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new xgDal().getczys(key));
}
public string fftm(string lyrid, string tmmin, string tmmax)
{
try
{
string t1, t2;
t1 = tmmin.Substring(0, tmmin.ToUpper().IndexOf("IN1") + 3).ToUpper();
t2 = tmmax.Substring(0, tmmax.ToUpper().IndexOf("IN1") + 3).ToUpper();
if (t1 != t2)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "申请的条码类型不一致!" });
}
int imin = 0;
int imax = 0;
tmmin = tmmin.Substring(tmmin.ToUpper().IndexOf("IN1") + 3);
tmmax = tmmax.Substring(tmmax.ToUpper().IndexOf("IN1") + 3);
int len = tmmin.Length;
if (!int.TryParse(tmmin, out imin))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "开始条码不正确!" });
}
if (!int.TryParse(tmmax, out imax))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "开始条码不正确!" });
}
if (imax < imin)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "结束条码不能小于开始条码!" });
}
var dal = new xgDal();
int c = 0;
var user = Session["loginUser"] as ERPUser;
for (int i = imin; i <= imax; i++)
{
if (dal.lytm(user.ID, t1 + i.ToString().PadLeft(len, '0'), lyrid))
c++;
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = "成功发放个" + c + "条码!" });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = ex.Message });
}
}
[AllowAnonymous]
public ActionResult myreport()
{
/*
Session["xgsfz"] = IDCard;
HttpCookie hc = new HttpCookie("xgsfz");
hc.Value = IDCard;
Response.Cookies.Add(hc);
Session["xgsjh"] = Mobile;
HttpCookie hcs = new HttpCookie("xgsjh");
hcs.Value = Mobile;
Response.Cookies.Add(hcs);
return Json(new { State = 1, Message = "验证成功!" });
*/
HttpCookie hou = Request.Cookies["xgsfz"];
if (Session["xgsfz"] == null && hou != null && (!string.IsNullOrEmpty(hou.Value)))
{
Session["xgsfz"] = hou.Value;
}
if (Session["xgsfz"] == null || Session["xgsfz"].ToString() == "")
{
ViewBag.model = new List<xgDjxx>();
return View();
}
ViewBag.model = new xgDal().getdjListbysfz(Session["xgsfz"].ToString());
return View();
}
[AllowAnonymous]
public ActionResult check()
{
return View();
}
public ActionResult list()
{
return View();
}
public string getYYList(int page, int pagesize, string xm, string yyrq)
{
var user = Session["loginUser"] as ERPUser;
var bll = new xgDal();
int count = bll.getyyCount(xm, yyrq);
var list = bll.getyyList(xm, yyrq, page, pagesize);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list }, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public string getdjList(int page, int pagesize, string xm, string cygtm, string yyrq,string jd,string ryfl)
{
var user = Session["loginUser"] as ERPUser;
var bll = new xgDal();
int count = bll.getdjCount(xm, yyrq,jd,ryfl);
var list = bll.getdjList(xm, cygtm, yyrq, page, pagesize,jd,ryfl);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Total = count, Rows = list }, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public ActionResult djList()
{
ViewBag.rylxs = new xgDal().getrylxs();
return View();
}
public string export(string xm, string cygtm, string yyrq, string jd, string ryfl)
{
try
{
DataTable list = new xgDal().getdjList(xm, cygtm, yyrq, jd, ryfl);
string path = "~/export/" + Guid.NewGuid().ToString("N") + ".xlsx";
xiaoy.Excel.ExcelFile.SetData(list, Server.MapPath(path), xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 1, msg = Url.Content(path) });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { state = 0, msg = ex.Message });
}
//return "";
}
[AllowAnonymous]
public JsonResult getsjyzm(string Mobile, string IDCard)
{
if (System.Text.RegularExpressions.Regex.IsMatch(Mobile, "^1[3|4|5|6|7|8|9]\\d{9}$"))
{
var xgdal = new DAL.xgDal();
bool have = xgdal.getbgbysfzsjh(Mobile, IDCard);
if (!have)
{
return Json(new { State = 0, Message = "没有查到您7天以内的核酸检测报告" });
}
var dxyz = new BLL.DuanXinYanZhengBll();
string cookieid = Guid.NewGuid().ToString();// Request.Cookies["clientid"].Value;
var yzm = dxyz.getYanZheng(Session.SessionID, cookieid, Request.UserHostAddress, Mobile);
if (yzm.id == 0)
{
return Json(new { State = 0, Message = yzm.bz });
}
else
{
var commonbll = new BLL.Common();
string yddx = commonbll.getParm_Value("qyyddx", "false", "是否启用移动短信");
if (yddx == "false")
{
string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
string dxmb = commonbll.getParm_Value("aldxmb", "SMS_80120090", "短信模版");
//string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
//string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
//var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
//var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
//var fz = Session["FenZhan"] as Model.FenZhan;
//Common.SendMsg.Send(sjh, yznr, fz.id);
String product = "Dysmsapi";//短信API产品名称
String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
String accessKeyId = AccessKeyID;//你的accessKeyId
String accessKeySecret = AccessKeySecret;//你的accessKeySecret
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.PhoneNumbers = Mobile;
//必填:短信签名-可在短信控制台中找到
request.SignName = qm;
//必填:短信模板-可在短信控制台中找到
request.TemplateCode = dxmb;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { code = yzm.smscode });
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.OutId = "21212121211";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
//System.Console.WriteLine(sendSmsResponse.Message);
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
}
catch (Aliyun.Acs.Core.Exceptions.ServerException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//System.Console.WriteLine("Hello World!");
//return Json(new { State = 0, Message = e.Message});
}
catch (ClientException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//return Json(new { State = 0, Message = e.Message});
}
return Json(new { State = 1, Message = yzm.id.ToString() });
}
else
{
//http://112.35.1.155:1992/sms/norsubmit
string ydhttp = commonbll.getParm_Value("ydhttp", "http://112.35.1.155:1992/sms/tmpsubmit", "移动短信地址");
var req = new Models.duanxin.msend();
req.ecName = commonbll.getParm_Value("yddxqymc", "德州市德城区疾病预防控制中心", "企业名称");
req.apId = commonbll.getParm_Value("yddxapId", "jkoa", "接口账号用户名");
req.mobiles = yzm.ShouJiHao;
req.sign = commonbll.getParm_Value("yddxsign", "d37CYmrbG", "签名编码");
req.templateId = "2c2e4092e23f432097dadf5672645ca6";
req.addSerial = "";
string[] parms = new string[1];
parms[0] = yzm.smscode;
req.parms = Newtonsoft.Json.JsonConvert.SerializeObject(parms);
var md5 = MD5.Create();
//secretKey
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(req.ecName + req.apId + commonbll.getParm_Value("yddxsecretKey", "a7551898", "短信接口密码") + req.templateId + req.mobiles + req.parms + req.sign));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
req.mac = sb.ToString().ToLower();
WebClient wc = new WebClient();
string upstr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
upstr = upstr.Replace("parms", "params");
//new {params }
//upstr.Insert(upstr.Length-1,",")
byte[] resp = wc.UploadData(ydhttp, System.Text.Encoding.UTF8.GetBytes(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(upstr))));
var nres = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.duanxin.nrecive>(System.Text.Encoding.UTF8.GetString(resp));
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(System.Text.Encoding.UTF8.GetString(resp));
return Json(new { State = 1, Message = yzm.id.ToString() });
}
}
}
else
{
return Json(new { State = 0, Message = "请输入正确的手机号码!" });
}
}
[AllowAnonymous]
public JsonResult ChargeResult(string Mobile, string IDCard, string yzm, string yzmid)
{
var yzmbll = new BLL.DuanXinYanZhengBll();
//int iyzmid;
//int.TryParse(yzmid, out iyzmid);
if (string.IsNullOrEmpty(yzmid))
{
return Json(new { State = 0, Message = "手机验证码不正确!" });
}
var myzm = yzmbll.getYZMById(yzmid);
if (myzm == null)
{
return Json(new { State = 0, Message = "手机验证码不正确!" });
}
if (myzm.ShouJiHao != Mobile)
{
return Json(new { State = 0, Message = "手机号码和获取验证码的手机号码不一致!" });
}
if ((DateTime.Now - myzm.sendtime).TotalMinutes > myzm.YanZhengYouXiaoQi)
{
return Json(new { State = 0, Message = "验证码已经超过有效期!" });
}
if (myzm.state != 0)
{
return Json(new { State = 0, Message = "验证码已经使用不能重复验证!" });
}
if (myzm.smscode != yzm)
{
return Json(new { State = 0, Message = "手机验证码不正确!" });
}
yzmbll.YanZhenged(myzm);
Session["xgsfz"] = IDCard;
HttpCookie hc = new HttpCookie("xgsfz");
hc.Value = IDCard;
Response.Cookies.Add(hc);
Session["xgsjh"] = Mobile;
HttpCookie hcs = new HttpCookie("xgsjh");
hcs.Value = Mobile;
Response.Cookies.Add(hcs);
return Json(new { State = 1, Message = "验证成功!" });
}
[AllowAnonymous]
public ActionResult myyy(string djType)
{
try
{
HttpCookie hou = Request.Cookies["xgopenuser"];
if (hou != null && (!string.IsNullOrEmpty(hou.Value)))
{
Session["xgopenuser"] = hou.Value;
}
if (Session["xgopenuser"] == null || Session["xgopenuser"].ToString() == "")
{
string code = Request.QueryString["code"];
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("ss" + code);
if (string.IsNullOrEmpty(code))
{
//DB.Common comm = new DB.Common();
return Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Common.Global.YMAppId +
"&redirect_uri=" + Url.Encode(new BLL.Common().getParm_Value("xgmyyy", "http://oa.dcqcdc.com/dccdc/xg/myyy", "微信uri我的预约")) +
"&response_type=code&scope=snsapi_base#wechat_redirect");
}
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sb" + code);
//string openidstr = geto;
var openidstr = GetOAuthOpenId(code);
var openid = Newtonsoft.Json.JsonConvert.DeserializeObject<OAuthopenid>(openidstr);
Session["xgopenuser"] = openid.openid;
HttpCookie hc = new HttpCookie("xgopenuser");
hc.Value = openid.openid;
Response.Cookies.Add(hc);
/*
bool sfgz = db.sfgz(openid.openid);
if (!sfgz)
{
return RedirectToAction("nosub");
}*/
}
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info("sb" + Session["xgopenuser"]);
var xgydj = new xg_yyxx();
xgydj.openid = Session["xgopenuser"].ToString();
xgydj = new DAL.xgDal().getlastxgydd(xgydj.openid);
/*
var hy = db.gethybyopenid(Session["openuser"].ToString());
if (hy != null)
{
Session["HY"] = hy;
return RedirectToAction("myhome");
}
*/
var bll = new DAL.xgDal();
//ViewBag.tjlx = new SelectList(bll.GetListByrylx(), "id", "flmc");
if (xgydj == null)
{
return RedirectToAction("yy");
}
else
{
if (string.IsNullOrEmpty(djType))
{
if (xgydj.yyrq == DateTime.Now.Date||xgydj.djsj.Date==DateTime.Now.Date||xgydj.djzt==0)
{
xgDjxx djxx = new xgDal().getdjxxbyyyid(xgydj.id);
if (djxx != null)
xgydj.djxlh = djxx.xlh;
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
ViewBag.timeStamp = Convert.ToInt64(ts.TotalSeconds).ToString();
ViewBag.nonceStr = Guid.NewGuid().ToString("N");
string[] ArrayList = { "jsapi_ticket=" + Common.Global.jsapi_ticketYM, "timestamp=" + ViewBag.timeStamp, "noncestr=" + ViewBag.nonceStr, "url=" + Request.Url.AbsoluteUri.Split('#')[0] };
Array.Sort(ArrayList);
string signature = string.Join("&", ArrayList);
var sha1 = System.Security.Cryptography.SHA1.Create();
signature = BitConverter.ToString(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signature))).Replace("-", ""); //对该字符串进行sha1加密
signature = signature.ToLower();//对字符串中的字母部分进行小写转换,非字母字符不作处理
ViewBag.signature = signature;
var list = new List<xg_yyxx>();
list.Add(xgydj);
ViewBag.list = list;
return View();
}
}
else
{
var list = new xgDal().getjryyother(Session["xgopenuser"].ToString());
foreach (var m in list)
{
xgDjxx djxx = new xgDal().getdjxxbyyyid(m.id);
if (djxx != null)
m.djxlh = djxx.xlh;
}
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
ViewBag.timeStamp = Convert.ToInt64(ts.TotalSeconds).ToString();
ViewBag.nonceStr = Guid.NewGuid().ToString("N");
string[] ArrayList = { "jsapi_ticket=" + Common.Global.jsapi_ticketYM, "timestamp=" + ViewBag.timeStamp, "noncestr=" + ViewBag.nonceStr, "url=" + Request.Url.AbsoluteUri.Split('#')[0] };
Array.Sort(ArrayList);
string signature = string.Join("&", ArrayList);
var sha1 = System.Security.Cryptography.SHA1.Create();
signature = BitConverter.ToString(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signature))).Replace("-", ""); //对该字符串进行sha1加密
signature = signature.ToLower();//对字符串中的字母部分进行小写转换,非字母字符不作处理
ViewBag.signature = signature;
ViewBag.other = "他人";
ViewBag.list = list;
return View();
}
}
return RedirectToAction("yy");
}
catch (Exception ex)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(ex.Message + ex.StackTrace);
return View();
}
}
[AllowAnonymous]
public FileResult qr(string id)
{
if (string.IsNullOrEmpty(id))
{
id = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(id, QRCodeGenerator.ECCLevel.Q);
QRCode qrcode = new QRCode(qrCodeData);
// qrcode.GetGraphic 方法可参考最下发“补充说明”
Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false);
MemoryStream ms = new MemoryStream();
qrCodeImage.Save(ms, ImageFormat.Jpeg);
return File(ms.ToArray(), "image/Jpeg", id + ".jpg");
}
/// <summary>
/// 获取地区
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public string getArea(string code)
{
var bll = new AreaBll();
return JsonConvert.SerializeObject(bll.GetSubordinate(code));
}
/// <summary>
/// 获取地区
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public string getAreaRecursion(string code)
{
var bll = new AreaBll();
List<AreaModel> lists = bll.GetSubordinate(code);
//List<AreaModel> list = setTree(lists, code);
return JsonConvert.SerializeObject(lists);
}
}
}