weixin_common.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. //切换发布版本 true:正式版,连接生产环境;false:测试版,连接测试环境。
  2. var publish_version = true;
  3. //var publish_version = false;
  4. if(publish_version){
  5. //正式环境(厦门i健康)
  6. var server = "http://srijk.yihu.com/wlyy/";
  7. var appId = "wxe627ffaee2d05a40";
  8. var urlName = "wlyy";
  9. var weixinUrl = "srijk.yihu.com";
  10. var agentName = "wlyyAgent";
  11. var agentName1 = "wlyyAgent1";
  12. var OpenidAgent = "OpenidAgent";
  13. var judgeAgent = "judgeAgent";
  14. var pageName = "pageurl";
  15. var wxurl = "http%3a%2f%2fwww.srijk.com%2fwlyy%2fwx%2fhtml";
  16. var imurl="http://58.22.123.195:3000";
  17. var imgUrlDomain = 'http://srijk.yihu.com/';
  18. }else{
  19. //测试环境
  20. // var server = "http://srijk.yihu.com/wlyy/";
  21. // var server = "http://172.19.103.72:9096/wlyy/";
  22. var server = "http://192.168.131.24:8082/";//仕杰
  23. // var server = "http://192.168.131.102:8080/";//伟达
  24. // var server = "http://192.168.131.127:8070/";//逸祥
  25. // var server = "http://192.168.131.133:8080/";//文杰
  26. var appId = "wxe627ffaee2d05a40";
  27. var urlName = "wlyy";
  28. var weixinUrl = "srijk.yihu.com";
  29. var agentName = "wlyyAgent";
  30. var agentName1 = "wlyyAgent1";
  31. var OpenidAgent = "OpenidAgent";
  32. var judgeAgent = "judgeAgent";
  33. var pageName = "pageurl";
  34. var wxurl = "http%3a%2f%2fwww.srijk.com%2fwlyy%2fwx%2fhtml";
  35. var imurl="http://172.19.103.72:3000";
  36. // var imurl="http://192.168.131.24:3000";//仕杰
  37. var imgUrlDomain = 'http://srijk.yihu.com/';
  38. }
  39. //添加openid白名单,只有这个名单内的openid才可以在线支付
  40. var openidList = [];
  41. //设置变量,控制是否可以在线支付
  42. var canPayOnline = true;
  43. if(GetRequest().openid){
  44. checkCanPayOnline(GetRequest().openid);
  45. }
  46. //添加处方功能的openid白名单
  47. var prescriptionOpenidList = ['123456'];
  48. var canPrescription = true;
  49. if(GetRequest().openid){
  50. checkCanPrescription(GetRequest().openid);
  51. }
  52. //保存userAgent
  53. function wxSaveUserAgent(id, uid, openid, token,lastUid) {
  54. if(window.localStorage.getItem(agentName)){
  55. window.localStorage.removeItem(agentName);
  56. }
  57. var userAgent = {
  58. id: id,
  59. uid: uid,
  60. openid: openid,
  61. token: token,
  62. lastUid: (lastUid ? lastUid:""),
  63. platform: 3
  64. }
  65. userAgent = JSON.stringify(userAgent);
  66. // var userAgent = "{\"id\":" + id + ",\"uid\":\"" + uid + "\",\"openid\":\"" + openid + "\",\"token\":\"" + token + "\",\"lastUid\":\"" + (lastUid ? lastUid:"") + "\",\"platform\":3}";
  67. window.localStorage.setItem(agentName, userAgent);
  68. return userAgent;
  69. }
  70. //保存userAgent1
  71. function wxSaveUserAgent1(uid, name, photo) {
  72. if(window.localStorage.getItem(agentName1)){
  73. window.localStorage.removeItem(agentName1);
  74. }
  75. var userAgent = {
  76. uid: uid,
  77. name: name,
  78. photo: photo
  79. }
  80. userAgent = JSON.stringify(userAgent);
  81. // var userAgent = "{\"uid\":" + uid + ",\"name\":\"" + name + "\",\"photo\":\"" + photo + "\"}";
  82. window.localStorage.setItem(agentName1, userAgent);
  83. return userAgent;
  84. }
  85. //保存openid
  86. function saveAgentOpenid(openid){
  87. if(window.localStorage.getItem(OpenidAgent)){
  88. window.localStorage.removeItem(OpenidAgent);
  89. }
  90. var agentOpenid = "{\"openid\":\"" + openid + "\"}";
  91. window.localStorage.setItem(OpenidAgent, agentOpenid);
  92. }
  93. //保存页面跳转值
  94. function saveAgentJudge(judge){
  95. if(window.localStorage.getItem(judgeAgent)){
  96. window.localStorage.removeItem(judgeAgent);
  97. }
  98. var agentJudge = "{\"judge\":" + judge + "}";
  99. window.localStorage.setItem(judgeAgent, agentJudge);
  100. }
  101. //保存跳转页面到agent
  102. function saveAgentPage(pageurl){
  103. if(window.localStorage.getItem(pageName)){
  104. window.localStorage.removeItem(pageName);
  105. }
  106. var agentPage = "{\"pageurl\":\"" + pageurl + "\"}";
  107. window.localStorage.setItem(pageName, agentPage);
  108. //如果页面中有code这个参数,及微信授权返回的code,将这个code保存在storage中
  109. if(pageurl.indexOf("code=") > -1){
  110. var arr = pageurl.split("code=");
  111. var code = arr[1].split("&")[0];
  112. window.localStorage.setItem("weixinCode", code);
  113. }
  114. }
  115. //清空所有的agent
  116. function clearAgent(){
  117. if(window.localStorage.getItem(agentName)){
  118. window.localStorage.removeItem(agentName);
  119. }
  120. if(window.localStorage.getItem(agentName1)){
  121. window.localStorage.removeItem(agentName1);
  122. }
  123. window.localStorage.removeItem("weixinCode"); //清楚缓存的code
  124. // if(window.localStorage.getItem(OpenidAgent)){
  125. // window.localStorage.removeItem(OpenidAgent);
  126. // }
  127. }
  128. //获取链接上的参数
  129. function GetRequest() {
  130. var url = location.search; //获取url中"?"符后的字串
  131. var theRequest = new Object();
  132. if (url.indexOf("?") != -1) {
  133. var str = url.substr(1);
  134. strs = str.split("&");
  135. for(var i = 0; i < strs.length; i ++) {
  136. theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
  137. }
  138. }
  139. //添加toName的信息
  140. if(theRequest.toName){
  141. localStorage.setItem("toName", theRequest.toName);
  142. }
  143. return theRequest;
  144. }
  145. //新的判断用户是否登录的方法,先校验openid是否一致
  146. function checkUserAgent(){
  147. var Request = new Object();
  148. Request = GetRequest();
  149. var code = Request["code"];
  150. var userAgent = window.localStorage.getItem(agentName);
  151. var agentCode = localStorage.getItem("weixinCode");
  152. if(code == "" || code == null || code == undefined){
  153. if(agentCode){
  154. //存在agentCode,说明一定获取openid成功过。
  155. if(!userAgent){
  156. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  157. agentOpenids = JSON.parse(agentOpenids);
  158. var url = window.parent.location.href;
  159. saveAgentPage(url);
  160. window.location.href = "../../home/html/login.html?type=0&openid=" + agentOpenids.openid;
  161. }else{
  162. try{
  163. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  164. if(agentOpenids){
  165. agentOpenids = JSON.parse(agentOpenids);
  166. checkCanPayOnline(agentOpenids.openid);
  167. checkCanPrescription(agentOpenids.openid);
  168. }
  169. queryInit();
  170. }catch(e){
  171. }
  172. }
  173. }else{
  174. if(!userAgent){
  175. d.close();
  176. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'授权失败',bottom:true}).show();
  177. //模板消息的情况,模板消息带上openid的值给页面
  178. var openid = Request['openid'];
  179. saveAgentOpenid(openid);
  180. var url = window.parent.location.href;
  181. saveAgentPage(url);
  182. window.location.href = "../../home/html/login.html?type=0&openid=" + openid;
  183. }else{
  184. try{
  185. checkCanPayOnline(Request['openid']);
  186. checkCanPrescription(Request['openid']);
  187. queryInit();
  188. }catch(e){
  189. }
  190. }
  191. }
  192. }
  193. else{
  194. //校验code与缓存中的code是否一致,一致的话则不再向后端获取openid,因为code只能使用一次
  195. if(agentCode && (code == agentCode)){
  196. try{
  197. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  198. if(agentOpenids){
  199. agentOpenids = JSON.parse(agentOpenids);
  200. checkCanPayOnline(agentOpenids.openid);
  201. checkCanPrescription(agentOpenids.openid)
  202. }
  203. queryInit();
  204. }catch(e){
  205. }
  206. }else{
  207. //校验登录的openid是否与缓存中存在的一致
  208. d.show();
  209. sendPost('weixin/getOpenidByCode', {code: code}, 'json', 'post', openidFailed, function(res){
  210. if (res.status == 200) {
  211. d.close();
  212. localStorage.setItem("weixinCode", code);
  213. var openid = res.openid,
  214. agentOpenids = window.localStorage.getItem(OpenidAgent),
  215. agentOpenid = agentOpenids && JSON.parse(agentOpenids).openid;
  216. saveAgentOpenid(openid);
  217. if( agentOpenid == openid){
  218. if(!userAgent){
  219. var url = window.parent.location.href;
  220. saveAgentPage(url);
  221. window.location.href = "../../home/html/login.html?type=0&openid=" + openid;
  222. }else{
  223. try{
  224. checkCanPayOnline(openid);
  225. checkCanPrescription(openid);
  226. queryInit();
  227. }catch(e){
  228. }
  229. }
  230. }else{
  231. var url = window.parent.location.href;
  232. saveAgentPage(url);
  233. window.location.href = server + "wx/html/home/html/login.html?type=0&openid=" + openid;
  234. }
  235. } else {
  236. openidFailed(res);
  237. }
  238. });
  239. }
  240. }
  241. }
  242. //判断用户是否登录
  243. function checkUserAgent1(){
  244. var userAgent = window.localStorage.getItem(agentName);
  245. if(!userAgent){
  246. var agentOpenid = window.localStorage.getItem(OpenidAgent);
  247. if(!agentOpenid||agentOpenid=="undefined"){
  248. var Request = new Object();
  249. Request = GetRequest();
  250. var code = Request["code"];
  251. if(code == "" || code == null || code == undefined){
  252. d.close();
  253. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'授权失败',bottom:true}).show();
  254. }
  255. else{
  256. d.show();
  257. var data = {};
  258. data.code = code;
  259. sendPost('weixin/getOpenidByCode', data, 'json', 'post', openidFailed, openidSuccess);
  260. }
  261. }
  262. else{
  263. var jsonstr = $.parseJSON(agentOpenid);
  264. var openid = jsonstr.openid;
  265. if((pagetype>=20&&pagetype<=27) || pagetype=='-1' || pagetype==3 || !pagetype){
  266. pagetype = 0;
  267. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  268. }
  269. // window.location.href = server + "wx/html/home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  270. window.location.href = "../../home/html/login.html?type=" + pagetype //+ "&openid=" + openid;
  271. }
  272. }
  273. else{
  274. try{
  275. queryInit();
  276. }catch(e){
  277. }
  278. }
  279. }
  280. //判断openid是否在可以在线支付的白名单里面
  281. function checkCanPayOnline(id){
  282. if(id && openidList.indexOf(id)>-1){
  283. canPayOnline = true;
  284. }
  285. }
  286. //判断openid是否在可以开启处方功能的白名单中
  287. function checkCanPrescription(id){
  288. if(id && prescriptionOpenidList.indexOf(id)>-1){
  289. canPrescription = true;
  290. }
  291. }
  292. //成功
  293. function openidSuccess(res) {
  294. if (res.status == 200) {
  295. var openid = res.openid;
  296. saveAgentOpenid(openid);
  297. window.location.href = server + "wx/html/home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  298. } else {
  299. openidFailed(res);
  300. }
  301. }
  302. //失败
  303. function openidFailed(res) {
  304. d.close();
  305. // if(window.localStorage.getItem(OpenidAgent)){
  306. // window.localStorage.removeItem(OpenidAgent);
  307. // }
  308. if (res && res.msg) {
  309. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  310. } else {
  311. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取认证信息失败',bottom:true}).show();
  312. }
  313. }
  314. //判断用户是否有签约
  315. function checkSign(type){
  316. d.show();
  317. var userAgent = window.localStorage.getItem(agentName);
  318. if(userAgent){
  319. var data = {};
  320. $.ajax(server + "patient/is_sign", {
  321. data: data,
  322. type: 'POST',
  323. dataType: 'json',
  324. beforeSend: function(request) {
  325. request.setRequestHeader("userAgent", userAgent);
  326. },
  327. error: function(res) {
  328. d.close();
  329. if(res.status == 999 || res.status == 998 || res.status == 997){
  330. loginUrl(res.status);
  331. return;
  332. }
  333. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'校验失败',bottom:true}).show();
  334. },
  335. success: function(res) {
  336. d.close();
  337. if(res.status == 999 || res.status == 998 || res.status == 997){
  338. loginUrl(res.status);
  339. }
  340. else if (res.status == 200) {
  341. var is_sign = res.data;//0未签约,1已签约
  342. if(is_sign == 0){
  343. dialog({
  344. title: '提示',
  345. content: '您还未签约,请先签约,谢谢!',
  346. okValue:'签约',
  347. ok: function (){
  348. window.location.href = server + "wx/html/ssgg/html/choose-region.html";
  349. },
  350. cancelValue: '不了',
  351. cancel: function () {
  352. return;
  353. }
  354. }).showModal();
  355. }else{
  356. if(type == 1){
  357. window.location.href = server + "wx/html/zxwz/html/teachers-consult-commit.html";
  358. }
  359. }
  360. } else {
  361. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  362. }
  363. }
  364. });
  365. }
  366. else{
  367. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'用户信息错误',bottom:true}).show();
  368. }
  369. }
  370. var toUsers = localStorage.getItem("toUser");
  371. var curId = localStorage.getItem("id");
  372. var toName = localStorage.getItem("toName");
  373. var consultCode = localStorage.getItem("consultCode");
  374. var pageUrl = {
  375. /**通用跳转**/
  376. 0:function(){
  377. var pageurl = "";
  378. var agentPage = window.localStorage.getItem(pageName);
  379. if(agentPage){
  380. var jsonstr = $.parseJSON(agentPage);
  381. pageurl = jsonstr.pageurl;
  382. }
  383. if(pageurl){
  384. return pageurl;
  385. }else{
  386. return "../../grzx/html/my-detail.html";
  387. }
  388. }(),
  389. //关注咨询列表
  390. "1": "../../yszx/html/doctor-consultation.html",
  391. //我的关注医生列表
  392. "2": "../../yszx/html/focused-doctor.html",
  393. //查找医生
  394. "3": "../../yszx/html/select-consult-doctor.html",
  395. //个人中心
  396. "4": "../../grzx/html/my-detail.html",
  397. ///**签约管理首页**/ "-1":"../../qygl/html/signing-doctors.html",//签约管理首页
  398. ///**医生咨询首页**/ 1:"../../yszx/html/doctor-consultation.html",
  399. ///**医生指导首页**/ 3:"../../yszd/html/doctor-guidance.html",//医生指导首页
  400. ///**疾病社区首页**/ 4:"../../jbsq/html/disease-community.html",//疾病社区首页
  401. ///**健康记录首页**/ 5:"../../jkjl/html/health-record.html",//健康记录
  402. ///**我的设备首页**/ 6:"../../wdsb/html/my-equipments.html",//我的设备
  403. ///**我的资料首页**/ 11:"../../grzx/html/my-detail.html",
  404. ///**我的设备首页**/ 15:"../../wdsb/html/my-equipments.html",
  405. ///**签约选择医生**/ 16:"../../qygl/html/select-doctor.html",
  406. ///**签约搜索医生**/ 17:"../../qygl/html/search-doctor.html",
  407. ///**签约医生主页**/ 18:function(){
  408. // var doctor = localStorage.getItem("doccode");
  409. // return "../../ssgg/html/doctor-homepage-new.html?openid="+0+"&state="+doctor;
  410. // }(),
  411. ///**我的预约首页**/ 20:"../../wdyy/html/my-appointment.html",
  412. ///**预约挂号提交**/ 21:"https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wxurl+"%2fwdyy%2fhtml%2finfo-confirm.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect",
  413. // 22:"../../jtgx/html/family.html",
  414. ///**预约详情首页**/ 23:"../../wdyy/html/detail-appointment.html?openid="+0+"&toUser="+toUsers+"&id="+curId+"&toName="+toName,
  415. ///**医生咨询详情**/ 24:"../../yszx/html/consulting-doctor.html?openid="+0+"&toUser="+toUsers+"&consult="+consultCode+"&toName="+toName,
  416. ///**医生指导详情**/ 25:"../../yszd/html/guidance-detail.html?openid="+0+"&toUser="+toUsers+"&id="+curId+"&toName="+toName,
  417. ///**健康教育**/ 26:"../../jkjy/html/article_list.html",
  418. ///**健康详情**/ 27:function(){
  419. // var artoUser = localStorage.getItem("toUser");
  420. // var article = localStorage.getItem("article");
  421. // return "../../jkjy/html/article.html?dataId="+article+"&toUser="+artoUser+"&toName="+toName;
  422. // }(),
  423. // /**新的健康详情**/ 50:function(){
  424. // var artoUser = localStorage.getItem("toUser");
  425. // var article = localStorage.getItem("article");
  426. // return "../../jkjy/html/article2.html?dataId="+article+"&toUser="+artoUser+"&toName="+toName;
  427. // }(),
  428. // 28:"../../jkda/html/jiuzhenjilu.html",
  429. // 29:"../../jkda/html/jianchajianyan.html",
  430. // 30:"../../survey/html/survey_info.html?openid="+0+"&toUser="+toUsers+"&toName="+toName+"&survey_id="+localStorage.getItem("survey_id"),
  431. ///**签约管理首页2**/ 31:"../../qygl/html/signing_management.html",//签约管理首页
  432. ///*社区体检*/ 32: "../../jkda/html/jiankangtijian.html",
  433. ///*续签页面*/ 33: "../../xuqian/html/information.html",
  434. ///**意见反馈**/ 34:"../../yjfk/html/feedback.html",
  435. ///**公共咨询**/ 36:"../../jbsq/html/public-consult-detail.html",
  436. ///*处方记录 */ 38: "../../prescription/html/prescription_records.html",
  437. ///*续方订单跟踪页*/ 41: '../../prescription/html/order_tracking.html?openid='+0+'&toUser='+toUsers+'&toName='+toName+'&code='+window.localStorage.getItem("prescriptionCode"),
  438. /////*续方记录页*/ 42: '../../prescription/html/re-prescription_info.html?openid='+0+'&toUser='+toUsers+'&toName='+toName+'&code='+window.localStorage.getItem("prescriptionCode"),
  439. // /*孕检计划*/ 45: "../../fybj/html/yunjianjihua.html",
  440. // /*免疫计划*/ 46: "../../fybj/html/mianyijihua.html",
  441. // /*慢病管理修改*/ 47: "../../jbsq/html/slow-disease-manage.html",
  442. // /**免疫预约首页**/ 48:"../../wdyy/html/immune-appointment.html",
  443. // /**免疫预约详情页**/ 49:"../../wdyy/html/detail-immune-appointment.html"
  444. }
  445. Date.prototype.Format = function(formatStr)
  446. {
  447. var str = formatStr;
  448. var Week = ['日','一','二','三','四','五','六'];
  449. str=str.replace(/yyyy|YYYY/,this.getFullYear());
  450. str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
  451. str=str.replace(/MM/,this.getMonth()>8?(this.getMonth()+1).toString():'0' + (this.getMonth()+1));
  452. str=str.replace(/M/g,this.getMonth()+1);
  453. str=str.replace(/w|W/g,Week[this.getDay()]);
  454. str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
  455. str=str.replace(/d|D/g,this.getDate());
  456. str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
  457. str=str.replace(/h|H/g,this.getHours());
  458. str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
  459. str=str.replace(/m/g,this.getMinutes());
  460. str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
  461. str=str.replace(/s|S/g,this.getSeconds());
  462. return str;
  463. }
  464. var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  465. //document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_1265315380'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D1265315380' type='text/javascript'%3E%3C/script%3E"));