weixin_common.js 20 KB

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