weixin_common.js 21 KB

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