using PMS.BusinessModels.ComplaintManage;
using PMS.BusinessModels.MobileProblem;
using PMS.BusinessModels.ModelExtend;
using PMS.BusinessModels.SMS;
using PMS.EntityModels.WorkFlow;
using PMS.Interface;
using PMS.Interface.MessageManage;
using PMS.Interface.MoblieProblemRegist;
using PMS.Interface.SysManager;
using PMS.Interface.WorkFlow;
using PMS.Plugins.SMS;
using PMS.Plugins.WeChart;
using QWPlatform.SystemLibrary;
using QWPlatform.SystemLibrary.LogManager;
using QWPlatform.SystemLibrary.Utils;
using QWPlatform.SystemLibrary.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace PMS.WebUI.Controllers
{
///
/// 创建人:伍莲魁
/// 创建日期:2018/12/25
/// 功能描述:移动端登录控制器
///
[CheckLogin(false)]
public class MobileAccountController : Controller
{
IAccount account_obj = InterfaceFactory.CreateBusinessInstance();
IMoblieProblem MoblieProblem_obj = InterfaceFactory.CreateBusinessInstance();
IWorkFlow IWorkFlowModel = InterfaceFactory.CreateBusinessInstance();
// GET: MobileAccount
//推送消息
IMessageManage notice = InterfaceFactory.CreateBusinessInstance();
public ActionResult ComplaintLogin()
{
return View();
}
public ActionResult MobileProblemLogin(string Tele,int isOpenWechatLgoin=1,string Messge="")
{
var userkey = CookiesHelper.GetCookieValue("UserID");
ViewBag.Tele = Tele;
ViewBag.isOpenWechatLgoin = isOpenWechatLgoin;
ViewBag.Messge = Messge;
ViewBag.userkey = !string.IsNullOrEmpty(userkey) ? "1" : "0";
return View();
}
public ActionResult ScanPlus()
{
return View();
}
public ActionResult myscan()
{
return View();
}
///
/// 投诉用户登录(移动端)
///
///
[CrossSite]
public ActionResult UserLogin(string Complainttelephone, string password)
{
//读取IP
var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
var userkey = CookiesHelper.GetCookieValue("UserID");
//到数据库中验证是否正确
var r = account_obj.Login(Complainttelephone, password, ip);
if (r.Success)
{//登录成功
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r.Message, null).ToString(), "application/json");
}
else
{//登录失败
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, r.Message, null).ToString(), "application/json");
}
}
[Route("Scan/{ProductCode}/{InstitutionResId}/{registrantID}")]
public ActionResult ScanCodeRegist(string ProductCode, string InstitutionResId, string registrantID)
{
ViewBag.ProductCode = ProductCode;
ViewBag.InstitutionResId = InstitutionResId;
ViewBag.registrantID = registrantID;
return View();
}
public ActionResult RegistSucess()
{
return View();
}
public ActionResult ModifyPassword()
{
return View();
}
///
/// 资源ID获取站点信息
///
///
///
public ActionResult GetInstitutions(string InstitutionsSorID)
{
return Content(MoblieProblem_obj.GetInstitutionsID(InstitutionsSorID).ToJson(), "application/json");
}
///
/// 扫码登记产品问题
///
///
///
public ActionResult SubmitProblemByScanCode(SubmitProblemFormModel model)
{
///通过机构资源ID获取机构ID
DataTable Institution = MoblieProblem_obj.GetInstitutionsID(model.InstitutionID);
var InstitutionID = Institution.Rows[0].GetValueByName("ID");
var ProjectID = Institution.Rows[0].GetValueByName("项目ID");
model.InstitutionID = model.InstitutionID;
/// 获取登记流程ID和进入流程ID
var sub = GetProceessID(InstitutionID, ProjectID);
model.ProcessID = sub.ProcessID;
model.NextProcessID = sub.NextProcessID;
///获取当前登陆账户信息
var CurrentAccount = SysCom.Instance.GetCurrentAccount();
if (CurrentAccount != null)
{
model.registrantID = CurrentAccount.PersonID;
model.registrant = CurrentAccount.Name;
}
var r = MoblieProblem_obj.SubmitProblem("0", model);
if (!String.IsNullOrEmpty(r))
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "登记失败!用户不存在或内部错误,请联系管理员!", null).ToString(), "application/json");
}
}
///
/// 获取登记流程ID和进入流程ID
///
///
///
private SubmitProblemFormModel GetProceessID(string InstitutionID,string ProjectID)
{
SubmitProblemFormModel model = new SubmitProblemFormModel();
WorkFlowModel workmodel = new WorkFlowModel();
///通过用户资源ID获取
workmodel = MoblieProblem_obj.GetNewProblemWorkId(InstitutionID, ProjectID);
///登记流程ID
model.ProcessID = workmodel.ID;
///目录ID
model.Catalog = workmodel.CategoryID ?? 1;
///获取进入流程ID
model.NextProcessID = IWorkFlowModel.GetNewProblemWorkFlowID(model.Catalog, 3, 1);
return model;
}
///
/// 上传附件到FTP并保存到问题附件
///
///
///
///
public ActionResult FlieUploadAndSave(string ProcessId)
{
var files = this.Request.Files;
var rs = false;
var Model = new ProcessFileModel();
Model.Name ="扫码用户";
Model.ProcessId = ProcessId;
if (files.Count > 0)
{
for (int i = 0; i < files.Count; i++)
{
using (BinaryReader br = new BinaryReader(files[i].InputStream))
{
byte[] byteData = br.ReadBytes((int)files[i].InputStream.Length);
var uploadFile = files[i];
var fileName = uploadFile.FileName;
string _tp = System.IO.Path.GetExtension(fileName);
//判断附件类型
string fileType = "2";
if (_tp == ".jpg" || _tp == ".png" || _tp == ".jpeg" || _tp == ".bmp")
{
fileType = "1";
}
Model.Type = fileType;
//上传
var UplodResult = SysCom.Instance.UploadFileToFtp(byteData, fileName, _tp);
///是否上传成功
if (UplodResult.code == 100)
{
///保存到问题附件表
Model.FileId = UplodResult.data;
rs = IWorkFlowModel.SaveProcessFile(Model);
}
}
}
}
if (rs)
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "成功", null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "失败", null).ToString(), "application/json");
}
}
///
/// 注销
///
///
public ActionResult LogOut()
{
HttpCookie hc = Request.Cookies["UserID"];
hc.Expires = DateTime.Now.AddDays(-1);
hc.Path = "/";
hc.Value = "";
Response.AppendCookie(hc);
return Content("OK");
}
#region 注册
[Route("Regist/{PersonResource_id}/{InstitutionsSorId}")]
public ActionResult ProblemUserVer(string PersonResource_id, string InstitutionsSorId)
{
ViewBag.PersonResource_id = PersonResource_id;
ViewBag.InstitutionsSorId = InstitutionsSorId;
return View();
}
///
/// 注册页面
///
///
public ActionResult Register()
{
return View();
}
///
/// 用户校验
///
///
public ActionResult UserCheck(string PersonResource_id)
{
var r = MoblieProblem_obj.UserCheck(PersonResource_id);
if (!String.IsNullOrEmpty(r))
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "校验失败!请联系管理员", null).ToString(), "application/json");
}
}
///
/// 获取用户已存在信息
///
///
///
///
public ActionResult GetExistInfo(string PersonResource_id)
{
var json = MoblieProblem_obj.GetExistInfo(PersonResource_id);
return Content(json, "application/json");
}
///
/// 手机获取用户信息
///
///
///
public ActionResult TeleGetUserInfo(string Tele)
{
var json = MoblieProblem_obj.TeleGetUserInfo(Tele);
return Content(json, "application/json");
}
///
/// 更新资源ID
///
///
///
///
///
public ActionResult UpdateResourceID(string UserGetId,string Tele,string edType)
{
var r = MoblieProblem_obj.UpdateResourceID(UserGetId, Tele, edType);
if (!String.IsNullOrEmpty(r))
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "更新失败!请查看日志", null).ToString(), "application/json");
}
}
///
/// 获取注册验证码
///
///
///
public ActionResult GetSMSCode(string tele)
{
bool r = false;
///发送短信
var code = "";
var dt = account_obj.GetTelAccountInfo(tele);
if (dt != null && dt.Rows.Count > 0)
{
}
else
{
Logger.Instance.Info("手机号未注册,就在进行发验证码" + tele);
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "当前手机号未生成账号,请点击右上角先进行注册", null).ToString(), "application/json");
}
var smsSend = SendSMS.SendKuaiZiSMS(tele, ref code);
if (!string.IsNullOrEmpty(code))
{
r = MoblieProblem_obj.GetSMSCode(tele, code);
}
if (r)
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "发送成功,10分钟内有效!", null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "短信发送失败,请联系管理员", null).ToString(), "application/json");
}
}
public ActionResult UserRegist(MobileUserRegistModel Model)
{
var r = MoblieProblem_obj.UserRegist(Model);
if (!String.IsNullOrEmpty(r))
{
WeChartPush(Model.hospitalname,Model.name,Model.telephone, Model.Channel);
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "校验失败!请查看日志", null).ToString(), "application/json");
}
}
///
/// 微信推送消息
///
/// 医院名称
/// 姓名
/// 电话
/// 渠道id
private void WeChartPush( string HospitalName, string name, string tel,string ChannelID)
{
string str = "您有新的账号申请需要审核!";
NotificationDto no = new NotificationDto();
no.style = "3";
no.template_code = "gImsyFY_Rq6eceoAT9lAIBsWyZHdjWRijMK0OmhfjGQ";
no.template_value = "{\"first\":{\"value\":\"" + str + "\",\"color\":\"#173177\"},\"keyword1\":{\"value\":\"" + name + "\",\"color\":\"#173177\"},\"keyword2\":{\"value\":\"" + DateTime.Now + "\",\"color\":\"#173177\"},\"keyword3\":{\"value\":\"" + HospitalName + "\",\"color\":\"#173177\"},\"keyword4\":{\"value\":\"" + DateTime.Now + "\",\"color\":\"#173177\"},\"remark\":{\"value\":\"你有新的账户申请需要审核,请及时登录系统进行审核。\",\"color\":\"#173177\"}}";
//no.url = "https://zlpms.zlsoft.com:8078/MobileProblem/ProblemDetail/" + ProblemID;
List list = new List();
var dt = MoblieProblem_obj.GetChannelExtend(ChannelID);
if (dt != null && dt.Rows.Count > 0)
{
for(int i=0;i< dt.Rows.Count;i++)
{
MessageDetailsDto mdd = new MessageDetailsDto();
mdd.接收人id = dt.Rows[i].GetValueByName("微信id");
list.Add(mdd);
}
no.record_items = list;
notice.SendWeChartTempletMessge(no);
}
//mdd.接收人id = "oR2TM1RJcCi4E93BWPgz8i42vRcY";
}
///
/// 获取渠道信息
///
///
public ActionResult GetChannel()
{
var json = MoblieProblem_obj.GetChannel();
return Content(json, "application/json");
}
///
/// 修改密码
///
///
///
///
///
public ActionResult PasswordModifySubmit(string telephone,string Code,string password)
{
var r = MoblieProblem_obj.PasswordModifySubmit(telephone, Code, password);
if (r=="1")
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "修改成功", null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, r, null).ToString(), "application/json");
}
}
#endregion
#region 获取APP
[Route("GetApp/{Type}")]
public ActionResult GetAppforPC(string Type)
{
var pathbase = this.HttpContext.Server.MapPath("/AppDownLoad/");
var AppType = string.Empty;
var AppName = string.Empty;
if (Type == "Android")
{
pathbase += "ZLPMS.apk";
AppName = "ZLPMS.apk";
AppType = ".apk";
}
else
{
pathbase += "ZLPMS.ipa";
AppName = "ZLPMS.ipa";
AppType = ".ipa";
}
if (System.IO.File.Exists(pathbase))
{
try
{
var data = System.IO.File.ReadAllBytes(pathbase);
return File(data, "application/octet-stream", AppName);
}
catch (Exception ex)
{
Logger.Instance.Error("读取文件失败", ex);
return View();
}
}
else
{
Logger.Instance.Warn("未获取到APP对象");
return View();
}
}
[Route("GetAppFTP/{Type}")]
public ActionResult GetAppforFtp(string Type)
{
var obj = SysCom.Instance.DownloadFileBase64FromFtp("4781", string.Empty);
if (obj != null)
{
//将base64转bytes
var data = Convert.FromBase64String(obj.base64);
return File(data, "application/octet-stream", obj.fileName);
}
else
{
Logger.Instance.Warn("未获取到APP文件对象" );
return View();
}
}
#endregion
#region 微信登陆autho
///
/// 获取token,并且判断用户
///
///
///
///
public ActionResult GetToken(string code, string state)
{
var AppID = System.Configuration.ConfigurationManager.AppSettings["AppID"];
var AppSecret = System.Configuration.ConfigurationManager.AppSettings["AppSecret"];
// 获取 openId
var strUrl ="https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code";
strUrl = string.Format(strUrl, AppID, AppSecret, code);
var t = HttpCrossDomain.Get(strUrl);
var item = Strings.JsonToModel(t);
////获取用户信息
//string UserInfo = GetUserInfo(item.access_token, item.openid);
//WechatUserinfo user = new WechatUserinfo();
//if (!string.IsNullOrEmpty(UserInfo))
//{
// user= Strings.JsonToModel(UserInfo);
//}
string account = string.Empty;
string pwd = string.Empty;
if (IsRegisteredWeChat(item.openid,out account,out pwd))
{
//如果存在直接登陆
var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
var r = account_obj.WeChatLogin(account, pwd, ip);
if (r.Success)
{
//登陆成功
return Redirect("/MobileProblem/Home");
}
else
{
//登陆失败
return RedirectToAction("MobileProblemLogin?isOpenWechatLgoin=0&Messge="+r.Message);
}
}
else
{
Logger.Instance.Info("GetToken方法获取OpenId=" + t);
TempData["OpenUserId"] = item.openid;
//不存在跳转到手机号码填写页面
return RedirectToAction("AccountVerification");
}
}
private string GetUserInfo(string access_token,string openId)
{
if (access_token != null)
{
var strUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN";
strUrl = string.Format(strUrl, access_token, openId);
var jsonStr = HttpCrossDomain.Get(strUrl);
return jsonStr;
}
else
{
Logger.Instance.Error("调用方法GetToken没有拿到tokenId");
return "";
}
}
///
/// 判断该OpenId是否绑定账户
///
///
///
private bool IsRegisteredWeChat(string openId,out string account,out string pwd)
{
return MoblieProblem_obj.IsRegisteredWeChat(openId,out account, out pwd);
}
///
/// 手机号码验证
///
///
public ActionResult AccountVerification()
{
return View();
}
public ActionResult IsAccountExist(string tele)
{
var t = MoblieProblem_obj.IsAccountExist(tele);
return Content(t?"1":"0");
}
///
/// 将手机号码与微信OpenId绑定
///
///
///
///
public ActionResult WechatVerification(string telephone,string Code)
{
try
{
if (TempData["OpenUserId"] == null)
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, "获取授权失败,请重新关注公众号继续绑定。", null).ToString(), "application/json");
}
var OpenId = TempData["OpenUserId"].ToString();
Logger.Instance.Info("一:将手机号码与微信OpenId进行绑定,OpenId=" + OpenId);
string pwd = string.Empty;
string msg = string.Empty;
var r = MoblieProblem_obj.WechatVerification(telephone, Code, OpenId, out pwd,out msg);
Logger.Instance.Info("二:将手机号码与微信OpenId进行绑定,绑定成功="+ telephone+"手机|"+ Code+"验证码|+"+ pwd+"|pwd");
if (r)
{
var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
var result = account_obj.WeChatLogin(telephone, pwd, ip);
if (result.Success)
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "验证成功", null).ToString(), "application/json");
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, result.Message, null).ToString(), "application/json");
}
}
else
{
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, msg, null).ToString(), "application/json");
}
}
catch (Exception ex)
{
Logger.Instance.Error("将手机号码与微信OpenId绑定出错,原因:" + ex);
return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, "验证出错,请联系管理员", null).ToString(), "application/json");
}
}
#region 新版微信登录
public ActionResult WechatBinding()
{
var AppID = System.Configuration.ConfigurationManager.AppSettings["AppID"];
var RedirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];
return Redirect(string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}/MobileAccount/WechatLogin&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", AppID, RedirectUri));
}
///
/// 微信登录
///
///
///
public ActionResult WechatLogin(string code)
{
var item = WeChartMessage.WeChatUserInfo(code);
string account = string.Empty;
string pwd = string.Empty;
if (IsRegisteredWeChat(item.wx_openid, out account, out pwd))
{
//如果存在直接登陆
var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
var r = account_obj.WeChatLogin(account, pwd, ip);
if (r.Success)
{
//登陆成功
return Redirect("/MobileProblem/Home");
}
else
{
//登陆失败
return RedirectToAction("MobileProblemLogin?isOpenWechatLgoin=0&Messge=" + r.Message);
}
}
else
{
Logger.Instance.Info("WechatLogin方法获取OpenId=" + item.wx_openid+"|微信用户="+ item.wx_nickname+"|是否关注=" + item.NoAttention);
TempData["OpenUserId"] = item.wx_openid;
//不存在跳转到手机号码填写页面
return RedirectToAction("AccountVerification");
}
}
#endregion
#endregion
}
}