MobileAccountController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. using PMS.BusinessModels.ComplaintManage;
  2. using PMS.BusinessModels.MobileProblem;
  3. using PMS.BusinessModels.ModelExtend;
  4. using PMS.BusinessModels.SMS;
  5. using PMS.EntityModels.WorkFlow;
  6. using PMS.Interface;
  7. using PMS.Interface.MessageManage;
  8. using PMS.Interface.MoblieProblemRegist;
  9. using PMS.Interface.SysManager;
  10. using PMS.Interface.WorkFlow;
  11. using PMS.Plugins.SMS;
  12. using PMS.Plugins.WeChart;
  13. using QWPlatform.SystemLibrary;
  14. using QWPlatform.SystemLibrary.LogManager;
  15. using QWPlatform.SystemLibrary.Utils;
  16. using QWPlatform.SystemLibrary.Web;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Data;
  20. using System.IO;
  21. using System.Linq;
  22. using System.Net;
  23. using System.Web;
  24. using System.Web.Mvc;
  25. namespace PMS.WebUI.Controllers
  26. {
  27. /// <summary>
  28. /// 创建人:伍莲魁
  29. /// 创建日期:2018/12/25
  30. /// 功能描述:移动端登录控制器
  31. /// </summary>
  32. [CheckLogin(false)]
  33. public class MobileAccountController : Controller
  34. {
  35. IAccount account_obj = InterfaceFactory.CreateBusinessInstance<IAccount>();
  36. IMoblieProblem MoblieProblem_obj = InterfaceFactory.CreateBusinessInstance<IMoblieProblem>();
  37. IWorkFlow IWorkFlowModel = InterfaceFactory.CreateBusinessInstance<IWorkFlow>();
  38. // GET: MobileAccount
  39. //推送消息
  40. IMessageManage notice = InterfaceFactory.CreateBusinessInstance<IMessageManage>();
  41. public ActionResult ComplaintLogin()
  42. {
  43. return View();
  44. }
  45. public ActionResult MobileProblemLogin(string Tele,int isOpenWechatLgoin=1,string Messge="")
  46. {
  47. var userkey = CookiesHelper.GetCookieValue("UserID");
  48. ViewBag.Tele = Tele;
  49. ViewBag.isOpenWechatLgoin = isOpenWechatLgoin;
  50. ViewBag.Messge = Messge;
  51. ViewBag.userkey = !string.IsNullOrEmpty(userkey) ? "1" : "0";
  52. return View();
  53. }
  54. public ActionResult ScanPlus()
  55. {
  56. return View();
  57. }
  58. public ActionResult myscan()
  59. {
  60. return View();
  61. }
  62. /// <summary>
  63. /// 投诉用户登录(移动端)
  64. /// </summary>
  65. /// <returns></returns>
  66. [CrossSite]
  67. public ActionResult UserLogin(string Complainttelephone, string password)
  68. {
  69. //读取IP
  70. var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
  71. var userkey = CookiesHelper.GetCookieValue("UserID");
  72. //到数据库中验证是否正确
  73. var r = account_obj.Login(Complainttelephone, password, ip);
  74. if (r.Success)
  75. {//登录成功
  76. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r.Message, null).ToString(), "application/json");
  77. }
  78. else
  79. {//登录失败
  80. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, r.Message, null).ToString(), "application/json");
  81. }
  82. }
  83. [Route("Scan/{ProductCode}/{InstitutionResId}/{registrantID}")]
  84. public ActionResult ScanCodeRegist(string ProductCode, string InstitutionResId, string registrantID)
  85. {
  86. ViewBag.ProductCode = ProductCode;
  87. ViewBag.InstitutionResId = InstitutionResId;
  88. ViewBag.registrantID = registrantID;
  89. return View();
  90. }
  91. public ActionResult RegistSucess()
  92. {
  93. return View();
  94. }
  95. public ActionResult ModifyPassword()
  96. {
  97. return View();
  98. }
  99. /// <summary>
  100. /// 资源ID获取站点信息
  101. /// </summary>
  102. /// <param name="InstitutionsSorID"></param>
  103. /// <returns></returns>
  104. public ActionResult GetInstitutions(string InstitutionsSorID)
  105. {
  106. return Content(MoblieProblem_obj.GetInstitutionsID(InstitutionsSorID).ToJson(), "application/json");
  107. }
  108. /// <summary>
  109. /// 扫码登记产品问题
  110. /// </summary>
  111. /// <param name="model"></param>
  112. /// <returns></returns>
  113. public ActionResult SubmitProblemByScanCode(SubmitProblemFormModel model)
  114. {
  115. ///通过机构资源ID获取机构ID
  116. DataTable Institution = MoblieProblem_obj.GetInstitutionsID(model.InstitutionID);
  117. var InstitutionID = Institution.Rows[0].GetValueByName<string>("ID");
  118. var ProjectID = Institution.Rows[0].GetValueByName<string>("项目ID");
  119. model.InstitutionID = model.InstitutionID;
  120. /// 获取登记流程ID和进入流程ID
  121. var sub = GetProceessID(InstitutionID, ProjectID);
  122. model.ProcessID = sub.ProcessID;
  123. model.NextProcessID = sub.NextProcessID;
  124. ///获取当前登陆账户信息
  125. var CurrentAccount = SysCom.Instance.GetCurrentAccount();
  126. if (CurrentAccount != null)
  127. {
  128. model.registrantID = CurrentAccount.PersonID;
  129. model.registrant = CurrentAccount.Name;
  130. }
  131. var r = MoblieProblem_obj.SubmitProblem("0", model);
  132. if (!String.IsNullOrEmpty(r))
  133. {
  134. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
  135. }
  136. else
  137. {
  138. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "登记失败!用户不存在或内部错误,请联系管理员!", null).ToString(), "application/json");
  139. }
  140. }
  141. /// <summary>
  142. /// 获取登记流程ID和进入流程ID
  143. /// </summary>
  144. /// <param name="model"></param>
  145. /// <returns></returns>
  146. private SubmitProblemFormModel GetProceessID(string InstitutionID,string ProjectID)
  147. {
  148. SubmitProblemFormModel model = new SubmitProblemFormModel();
  149. WorkFlowModel workmodel = new WorkFlowModel();
  150. ///通过用户资源ID获取
  151. workmodel = MoblieProblem_obj.GetNewProblemWorkId(InstitutionID, ProjectID);
  152. ///登记流程ID
  153. model.ProcessID = workmodel.ID;
  154. ///目录ID
  155. model.Catalog = workmodel.CategoryID ?? 1;
  156. ///获取进入流程ID
  157. model.NextProcessID = IWorkFlowModel.GetNewProblemWorkFlowID(model.Catalog, 3, 1);
  158. return model;
  159. }
  160. /// <summary>
  161. /// 上传附件到FTP并保存到问题附件
  162. /// </summary>
  163. /// <param name="file"></param>
  164. /// <param name="Model"></param>
  165. /// <returns></returns>
  166. public ActionResult FlieUploadAndSave(string ProcessId)
  167. {
  168. var files = this.Request.Files;
  169. var rs = false;
  170. var Model = new ProcessFileModel();
  171. Model.Name ="扫码用户";
  172. Model.ProcessId = ProcessId;
  173. if (files.Count > 0)
  174. {
  175. for (int i = 0; i < files.Count; i++)
  176. {
  177. using (BinaryReader br = new BinaryReader(files[i].InputStream))
  178. {
  179. byte[] byteData = br.ReadBytes((int)files[i].InputStream.Length);
  180. var uploadFile = files[i];
  181. var fileName = uploadFile.FileName;
  182. string _tp = System.IO.Path.GetExtension(fileName);
  183. //判断附件类型
  184. string fileType = "2";
  185. if (_tp == ".jpg" || _tp == ".png" || _tp == ".jpeg" || _tp == ".bmp")
  186. {
  187. fileType = "1";
  188. }
  189. Model.Type = fileType;
  190. //上传
  191. var UplodResult = SysCom.Instance.UploadFileToFtp(byteData, fileName, _tp);
  192. ///是否上传成功
  193. if (UplodResult.code == 100)
  194. {
  195. ///保存到问题附件表
  196. Model.FileId = UplodResult.data;
  197. rs = IWorkFlowModel.SaveProcessFile(Model);
  198. }
  199. }
  200. }
  201. }
  202. if (rs)
  203. {
  204. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "成功", null).ToString(), "application/json");
  205. }
  206. else
  207. {
  208. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "失败", null).ToString(), "application/json");
  209. }
  210. }
  211. /// <summary>
  212. /// 注销
  213. /// </summary>
  214. /// <returns></returns>
  215. public ActionResult LogOut()
  216. {
  217. HttpCookie hc = Request.Cookies["UserID"];
  218. hc.Expires = DateTime.Now.AddDays(-1);
  219. hc.Path = "/";
  220. hc.Value = "";
  221. Response.AppendCookie(hc);
  222. return Content("OK");
  223. }
  224. #region 注册
  225. [Route("Regist/{PersonResource_id}/{InstitutionsSorId}")]
  226. public ActionResult ProblemUserVer(string PersonResource_id, string InstitutionsSorId)
  227. {
  228. ViewBag.PersonResource_id = PersonResource_id;
  229. ViewBag.InstitutionsSorId = InstitutionsSorId;
  230. return View();
  231. }
  232. /// <summary>
  233. /// 注册页面
  234. /// </summary>
  235. /// <returns></returns>
  236. public ActionResult Register()
  237. {
  238. return View();
  239. }
  240. /// <summary>
  241. /// 用户校验
  242. /// </summary>
  243. /// <returns></returns>
  244. public ActionResult UserCheck(string PersonResource_id)
  245. {
  246. var r = MoblieProblem_obj.UserCheck(PersonResource_id);
  247. if (!String.IsNullOrEmpty(r))
  248. {
  249. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
  250. }
  251. else
  252. {
  253. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "校验失败!请联系管理员", null).ToString(), "application/json");
  254. }
  255. }
  256. /// <summary>
  257. /// 获取用户已存在信息
  258. /// </summary>
  259. /// <param name="UserGetId"></param>
  260. /// <param name="InstitutionsID"></param>
  261. /// <returns></returns>
  262. public ActionResult GetExistInfo(string PersonResource_id)
  263. {
  264. var json = MoblieProblem_obj.GetExistInfo(PersonResource_id);
  265. return Content(json, "application/json");
  266. }
  267. /// <summary>
  268. /// 手机获取用户信息
  269. /// </summary>
  270. /// <param name="Tele"></param>
  271. /// <returns></returns>
  272. public ActionResult TeleGetUserInfo(string Tele)
  273. {
  274. var json = MoblieProblem_obj.TeleGetUserInfo(Tele);
  275. return Content(json, "application/json");
  276. }
  277. /// <summary>
  278. /// 更新资源ID
  279. /// </summary>
  280. /// <param name="UserGetId"></param>
  281. /// <param name="Tele"></param>
  282. /// <param name="edType"></param>
  283. /// <returns></returns>
  284. public ActionResult UpdateResourceID(string UserGetId,string Tele,string edType)
  285. {
  286. var r = MoblieProblem_obj.UpdateResourceID(UserGetId, Tele, edType);
  287. if (!String.IsNullOrEmpty(r))
  288. {
  289. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
  290. }
  291. else
  292. {
  293. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "更新失败!请查看日志", null).ToString(), "application/json");
  294. }
  295. }
  296. /// <summary>
  297. /// 获取注册验证码
  298. /// </summary>
  299. /// <param name="tele"></param>
  300. /// <returns></returns>
  301. public ActionResult GetSMSCode(string tele)
  302. {
  303. bool r = false;
  304. ///发送短信
  305. var code = "";
  306. var dt = account_obj.GetTelAccountInfo(tele);
  307. if (dt != null && dt.Rows.Count > 0)
  308. {
  309. }
  310. else
  311. {
  312. Logger.Instance.Info("手机号未注册,就在进行发验证码" + tele);
  313. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "当前手机号未生成账号,请点击右上角先进行注册", null).ToString(), "application/json");
  314. }
  315. var smsSend = SendSMS.SendKuaiZiSMS(tele, ref code);
  316. if (!string.IsNullOrEmpty(code))
  317. {
  318. r = MoblieProblem_obj.GetSMSCode(tele, code);
  319. }
  320. if (r)
  321. {
  322. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "发送成功,10分钟内有效!", null).ToString(), "application/json");
  323. }
  324. else
  325. {
  326. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "短信发送失败,请联系管理员", null).ToString(), "application/json");
  327. }
  328. }
  329. public ActionResult UserRegist(MobileUserRegistModel Model)
  330. {
  331. var r = MoblieProblem_obj.UserRegist(Model);
  332. if (!String.IsNullOrEmpty(r))
  333. {
  334. WeChartPush(Model.hospitalname,Model.name,Model.telephone, Model.Channel);
  335. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, r, null).ToString(), "application/json");
  336. }
  337. else
  338. {
  339. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, "校验失败!请查看日志", null).ToString(), "application/json");
  340. }
  341. }
  342. /// <summary>
  343. /// 微信推送消息
  344. /// </summary>
  345. /// <param name="HospitalName">医院名称</param>
  346. /// <param name="name">姓名</param>
  347. /// <param name="tel">电话</param>
  348. /// <param name="ChannelID">渠道id</param>
  349. private void WeChartPush( string HospitalName, string name, string tel,string ChannelID)
  350. {
  351. string str = "您有新的账号申请需要审核!";
  352. NotificationDto no = new NotificationDto();
  353. no.style = "3";
  354. no.template_code = "gImsyFY_Rq6eceoAT9lAIBsWyZHdjWRijMK0OmhfjGQ";
  355. 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\"}}";
  356. //no.url = "https://zlpms.zlsoft.com:8078/MobileProblem/ProblemDetail/" + ProblemID;
  357. List<MessageDetailsDto> list = new List<MessageDetailsDto>();
  358. var dt = MoblieProblem_obj.GetChannelExtend(ChannelID);
  359. if (dt != null && dt.Rows.Count > 0)
  360. {
  361. for(int i=0;i< dt.Rows.Count;i++)
  362. {
  363. MessageDetailsDto mdd = new MessageDetailsDto();
  364. mdd.接收人id = dt.Rows[i].GetValueByName<string>("微信id");
  365. list.Add(mdd);
  366. }
  367. no.record_items = list;
  368. notice.SendWeChartTempletMessge(no);
  369. }
  370. //mdd.接收人id = "oR2TM1RJcCi4E93BWPgz8i42vRcY";
  371. }
  372. /// <summary>
  373. /// 获取渠道信息
  374. /// </summary>
  375. /// <returns></returns>
  376. public ActionResult GetChannel()
  377. {
  378. var json = MoblieProblem_obj.GetChannel();
  379. return Content(json, "application/json");
  380. }
  381. /// <summary>
  382. /// 修改密码
  383. /// </summary>
  384. /// <param name="telephone"></param>
  385. /// <param name="Code"></param>
  386. /// <param name="password"></param>
  387. /// <returns></returns>
  388. public ActionResult PasswordModifySubmit(string telephone,string Code,string password)
  389. {
  390. var r = MoblieProblem_obj.PasswordModifySubmit(telephone, Code, password);
  391. if (r=="1")
  392. {
  393. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "修改成功", null).ToString(), "application/json");
  394. }
  395. else
  396. {
  397. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.Forbidden, r, null).ToString(), "application/json");
  398. }
  399. }
  400. #endregion
  401. #region 获取APP
  402. [Route("GetApp/{Type}")]
  403. public ActionResult GetAppforPC(string Type)
  404. {
  405. var pathbase = this.HttpContext.Server.MapPath("/AppDownLoad/");
  406. var AppType = string.Empty;
  407. var AppName = string.Empty;
  408. if (Type == "Android")
  409. {
  410. pathbase += "ZLPMS.apk";
  411. AppName = "ZLPMS.apk";
  412. AppType = ".apk";
  413. }
  414. else
  415. {
  416. pathbase += "ZLPMS.ipa";
  417. AppName = "ZLPMS.ipa";
  418. AppType = ".ipa";
  419. }
  420. if (System.IO.File.Exists(pathbase))
  421. {
  422. try
  423. {
  424. var data = System.IO.File.ReadAllBytes(pathbase);
  425. return File(data, "application/octet-stream", AppName);
  426. }
  427. catch (Exception ex)
  428. {
  429. Logger.Instance.Error("读取文件失败", ex);
  430. return View();
  431. }
  432. }
  433. else
  434. {
  435. Logger.Instance.Warn("未获取到APP对象");
  436. return View();
  437. }
  438. }
  439. [Route("GetAppFTP/{Type}")]
  440. public ActionResult GetAppforFtp(string Type)
  441. {
  442. var obj = SysCom.Instance.DownloadFileBase64FromFtp("4781", string.Empty);
  443. if (obj != null)
  444. {
  445. //将base64转bytes
  446. var data = Convert.FromBase64String(obj.base64);
  447. return File(data, "application/octet-stream", obj.fileName);
  448. }
  449. else
  450. {
  451. Logger.Instance.Warn("未获取到APP文件对象" );
  452. return View();
  453. }
  454. }
  455. #endregion
  456. #region 微信登陆autho
  457. /// <summary>
  458. /// 获取token,并且判断用户
  459. /// </summary>
  460. /// <param name="code"></param>
  461. /// <param name="state"></param>
  462. /// <returns></returns>
  463. public ActionResult GetToken(string code, string state)
  464. {
  465. var AppID = System.Configuration.ConfigurationManager.AppSettings["AppID"];
  466. var AppSecret = System.Configuration.ConfigurationManager.AppSettings["AppSecret"];
  467. // 获取 openId
  468. var strUrl ="https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code";
  469. strUrl = string.Format(strUrl, AppID, AppSecret, code);
  470. var t = HttpCrossDomain.Get(strUrl);
  471. var item = Strings.JsonToModel<WechatToken>(t);
  472. ////获取用户信息
  473. //string UserInfo = GetUserInfo(item.access_token, item.openid);
  474. //WechatUserinfo user = new WechatUserinfo();
  475. //if (!string.IsNullOrEmpty(UserInfo))
  476. //{
  477. // user= Strings.JsonToModel<WechatUserinfo>(UserInfo);
  478. //}
  479. string account = string.Empty;
  480. string pwd = string.Empty;
  481. if (IsRegisteredWeChat(item.openid,out account,out pwd))
  482. {
  483. //如果存在直接登陆
  484. var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
  485. var r = account_obj.WeChatLogin(account, pwd, ip);
  486. if (r.Success)
  487. {
  488. //登陆成功
  489. return Redirect("/MobileProblem/Home");
  490. }
  491. else
  492. {
  493. //登陆失败
  494. return RedirectToAction("MobileProblemLogin?isOpenWechatLgoin=0&Messge="+r.Message);
  495. }
  496. }
  497. else
  498. {
  499. Logger.Instance.Info("GetToken方法获取OpenId=" + t);
  500. TempData["OpenUserId"] = item.openid;
  501. //不存在跳转到手机号码填写页面
  502. return RedirectToAction("AccountVerification");
  503. }
  504. }
  505. private string GetUserInfo(string access_token,string openId)
  506. {
  507. if (access_token != null)
  508. {
  509. var strUrl = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN";
  510. strUrl = string.Format(strUrl, access_token, openId);
  511. var jsonStr = HttpCrossDomain.Get(strUrl);
  512. return jsonStr;
  513. }
  514. else
  515. {
  516. Logger.Instance.Error("调用方法GetToken没有拿到tokenId");
  517. return "";
  518. }
  519. }
  520. /// <summary>
  521. /// 判断该OpenId是否绑定账户
  522. /// </summary>
  523. /// <param name="openId"></param>
  524. /// <returns></returns>
  525. private bool IsRegisteredWeChat(string openId,out string account,out string pwd)
  526. {
  527. return MoblieProblem_obj.IsRegisteredWeChat(openId,out account, out pwd);
  528. }
  529. /// <summary>
  530. /// 手机号码验证
  531. /// </summary>
  532. /// <returns></returns>
  533. public ActionResult AccountVerification()
  534. {
  535. return View();
  536. }
  537. public ActionResult IsAccountExist(string tele)
  538. {
  539. var t = MoblieProblem_obj.IsAccountExist(tele);
  540. return Content(t?"1":"0");
  541. }
  542. /// <summary>
  543. /// 将手机号码与微信OpenId绑定
  544. /// </summary>
  545. /// <param name="telephone"></param>
  546. /// <param name="Code"></param>
  547. /// <returns></returns>
  548. public ActionResult WechatVerification(string telephone,string Code)
  549. {
  550. try
  551. {
  552. if (TempData["OpenUserId"] == null)
  553. {
  554. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, "获取授权失败,请重新关注公众号继续绑定。", null).ToString(), "application/json");
  555. }
  556. var OpenId = TempData["OpenUserId"].ToString();
  557. Logger.Instance.Info("一:将手机号码与微信OpenId进行绑定,OpenId=" + OpenId);
  558. string pwd = string.Empty;
  559. string msg = string.Empty;
  560. var r = MoblieProblem_obj.WechatVerification(telephone, Code, OpenId, out pwd,out msg);
  561. Logger.Instance.Info("二:将手机号码与微信OpenId进行绑定,绑定成功="+ telephone+"手机|"+ Code+"验证码|+"+ pwd+"|pwd");
  562. if (r)
  563. {
  564. var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
  565. var result = account_obj.WeChatLogin(telephone, pwd, ip);
  566. if (result.Success)
  567. {
  568. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.OK, "验证成功", null).ToString(), "application/json");
  569. }
  570. else
  571. {
  572. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, result.Message, null).ToString(), "application/json");
  573. }
  574. }
  575. else
  576. {
  577. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, msg, null).ToString(), "application/json");
  578. }
  579. }
  580. catch (Exception ex)
  581. {
  582. Logger.Instance.Error("将手机号码与微信OpenId绑定出错,原因:" + ex);
  583. return Content(new PmsJsonResoult(System.Net.HttpStatusCode.ExpectationFailed, "验证出错,请联系管理员", null).ToString(), "application/json");
  584. }
  585. }
  586. #region 新版微信登录
  587. public ActionResult WechatBinding()
  588. {
  589. var AppID = System.Configuration.ConfigurationManager.AppSettings["AppID"];
  590. var RedirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];
  591. 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));
  592. }
  593. /// <summary>
  594. /// 微信登录
  595. /// </summary>
  596. /// <param name="code"></param>
  597. /// <returns></returns>
  598. public ActionResult WechatLogin(string code)
  599. {
  600. var item = WeChartMessage.WeChatUserInfo(code);
  601. string account = string.Empty;
  602. string pwd = string.Empty;
  603. if (IsRegisteredWeChat(item.wx_openid, out account, out pwd))
  604. {
  605. //如果存在直接登陆
  606. var ip = QWPlatform.SystemLibrary.Utils.Strings.GetWebClientIP();
  607. var r = account_obj.WeChatLogin(account, pwd, ip);
  608. if (r.Success)
  609. {
  610. //登陆成功
  611. return Redirect("/MobileProblem/Home");
  612. }
  613. else
  614. {
  615. //登陆失败
  616. return RedirectToAction("MobileProblemLogin?isOpenWechatLgoin=0&Messge=" + r.Message);
  617. }
  618. }
  619. else
  620. {
  621. Logger.Instance.Info("WechatLogin方法获取OpenId=" + item.wx_openid+"|微信用户="+ item.wx_nickname+"|是否关注=" + item.NoAttention);
  622. TempData["OpenUserId"] = item.wx_openid;
  623. //不存在跳转到手机号码填写页面
  624. return RedirectToAction("AccountVerification");
  625. }
  626. }
  627. #endregion
  628. #endregion
  629. }
  630. }