weixin_common.js 21 KB

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