weixin_common.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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://ehr.yihu.com/csijk/";
  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://ehr.yihu.com/csijk/wx/html/";
  19. var imurl="http://222.218.31.19:3000";
  20. var imgUrlDomain = 'http://172.19.103.54/';
  21. }else{
  22. //测试环境(健康之路i厦门)
  23. // var server = "http://ehr.yihu.com/csijk/";
  24. var server = "http://172.19.103.88:9092/wlyy/";
  25. // var server = "http://192.168.131.243:8080/";//志南
  26. // var server = "http://192.168.131.154:8080/";//张丹
  27. // var server = "http://192.168.131.24:8080/";//仕杰
  28. // var server = "http://192.168.131.127:8060/";//逸祥
  29. // var server = "http://192.168.131.133:8080/";//文杰
  30. // var server = "http://192.168.131.113:8080/";//俊杰
  31. var appId = "wx1f129f7b51701428";
  32. var urlName = "wlyy";
  33. var weixinUrl = "ehr.yihu.com";
  34. var agentName = "wlyyAgent";
  35. var agentName1 = "wlyyAgent1";
  36. var OpenidAgent = "OpenidAgent";
  37. var judgeAgent = "judgeAgent";
  38. var pageName = "pageurl";
  39. var wxurl = "http%3a%2f%2fehr.yihu.com%2fwlyy%2fwx%2fhtml";
  40. var wsurl = 'ws://172.19.103.76:3030/netex';
  41. var imgUrlDomain = "http://172.19.103.54/";//添加图片服务器路径;
  42. var imurl="http://172.19.103.72:3000";
  43. var articleUrl = "http://172.19.103.87:9088"//健康教育文章详情
  44. // var imurl="http://192.168.131.24:3000";//仕杰
  45. //var imurl="http://192.168.131.127:3000";//逸祥
  46. //测试环境(健康之路当阳)
  47. //var server = "http://weixin.xmtyw.cn/wlyy-dev/";
  48. //var appId = "wxd03f859efdf0873d";
  49. //var urlName = "wlyy-dev";
  50. //var weixinUrl = "weixin.xmtyw.cn";
  51. //var agentName = "wlyyAgent_test";
  52. //var agentName1 = "wlyyAgent_test1";
  53. //var OpenidAgent = "OpenidAgent_test";
  54. //var judgeAgent = "judgeAgent_test";
  55. //var pageName = "pageurl_test";
  56. //var wxurl = "http%3a%2f%2fweixin.xmtyw.cn%2fwlyy-dev%2fwx%2fhtml";
  57. //var wsurl = 'ws://172.19.103.76:3030/netex';
  58. //var imurl="http://172.19.103.29:3008";
  59. }
  60. //添加openid白名单,只有这个名单内的openid才可以在线支付
  61. var openidList = [];
  62. //设置变量,控制是否可以在线支付
  63. var canPayOnline = true;
  64. if(GetRequest().openid){
  65. checkCanPayOnline(GetRequest().openid);
  66. }
  67. //添加处方功能的openid白名单
  68. var prescriptionOpenidList = ['123456'];
  69. var canPrescription = true;
  70. if(GetRequest().openid){
  71. checkCanPrescription(GetRequest().openid);
  72. }
  73. //保存userAgent
  74. function wxSaveUserAgent(id, uid, openid, token,lastUid) {
  75. if(window.localStorage.getItem(agentName)){
  76. window.localStorage.removeItem(agentName);
  77. }
  78. var userAgent = {
  79. id: id,
  80. uid: uid,
  81. openid: openid,
  82. token: token,
  83. lastUid: (lastUid ? lastUid:""),
  84. platform: 3
  85. }
  86. userAgent = JSON.stringify(userAgent);
  87. // var userAgent = "{\"id\":" + id + ",\"uid\":\"" + uid + "\",\"openid\":\"" + openid + "\",\"token\":\"" + token + "\",\"lastUid\":\"" + (lastUid ? lastUid:"") + "\",\"platform\":3}";
  88. window.localStorage.setItem(agentName, userAgent);
  89. return userAgent;
  90. }
  91. //保存userAgent1
  92. function wxSaveUserAgent1(uid, name, photo) {
  93. if(window.localStorage.getItem(agentName1)){
  94. window.localStorage.removeItem(agentName1);
  95. }
  96. var userAgent = {
  97. uid: uid,
  98. name: name,
  99. photo: photo
  100. }
  101. userAgent = JSON.stringify(userAgent);
  102. // var userAgent = "{\"uid\":" + uid + ",\"name\":\"" + name + "\",\"photo\":\"" + photo + "\"}";
  103. window.localStorage.setItem(agentName1, userAgent);
  104. return userAgent;
  105. }
  106. //保存openid
  107. function saveAgentOpenid(openid){
  108. if(window.localStorage.getItem(OpenidAgent)){
  109. window.localStorage.removeItem(OpenidAgent);
  110. }
  111. var agentOpenid = "{\"openid\":\"" + openid + "\"}";
  112. window.localStorage.setItem(OpenidAgent, agentOpenid);
  113. }
  114. //保存页面跳转值
  115. function saveAgentJudge(judge){
  116. if(window.localStorage.getItem(judgeAgent)){
  117. window.localStorage.removeItem(judgeAgent);
  118. }
  119. var agentJudge = "{\"judge\":" + judge + "}";
  120. window.localStorage.setItem(judgeAgent, agentJudge);
  121. }
  122. //保存跳转页面到agent
  123. function saveAgentPage(pageurl){
  124. if(window.localStorage.getItem(pageName)){
  125. window.localStorage.removeItem(pageName);
  126. }
  127. var agentPage = "{\"pageurl\":\"" + pageurl + "\"}";
  128. window.localStorage.setItem(pageName, agentPage);
  129. //如果页面中有code这个参数,及微信授权返回的code,将这个code保存在storage中
  130. if(pageurl.indexOf("code=") > -1){
  131. var arr = pageurl.split("code=");
  132. var code = arr[1].split("&")[0];
  133. window.localStorage.setItem("weixinCode", code);
  134. }
  135. }
  136. //清空所有的agent
  137. function clearAgent(){
  138. if(window.localStorage.getItem(agentName)){
  139. window.localStorage.removeItem(agentName);
  140. }
  141. if(window.localStorage.getItem(agentName1)){
  142. window.localStorage.removeItem(agentName1);
  143. }
  144. window.localStorage.removeItem("weixinCode"); //清楚缓存的code
  145. // if(window.localStorage.getItem(OpenidAgent)){
  146. // window.localStorage.removeItem(OpenidAgent);
  147. // }
  148. }
  149. //获取链接上的参数
  150. function GetRequest() {
  151. var url = location.search; //获取url中"?"符后的字串
  152. var theRequest = new Object();
  153. if (url.indexOf("?") != -1) {
  154. var str = url.substr(1);
  155. strs = str.split("&");
  156. for(var i = 0; i < strs.length; i ++) {
  157. theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
  158. }
  159. }
  160. //添加toName的信息
  161. if(theRequest.toName){
  162. localStorage.setItem("toName", theRequest.toName);
  163. }
  164. return theRequest;
  165. }
  166. //新的判断用户是否登录的方法,先校验openid是否一致
  167. function checkUserAgent(){
  168. var Request = new Object();
  169. Request = GetRequest();
  170. var code = Request["code"];
  171. var userAgent = window.localStorage.getItem(agentName);
  172. var agentCode = window.localStorage.getItem("weixinCode");
  173. if(code == "" || code == null || code == undefined){
  174. if(agentCode){
  175. //存在agentCode,说明一定获取openid成功过。
  176. if(!userAgent){
  177. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  178. agentOpenids = JSON.parse(agentOpenids);
  179. window.location.href = "../../home/html/zhmm-login.html?type=" + pagetype + "&openid=" + agentOpenids.openid;
  180. }else{
  181. try{
  182. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  183. if(agentOpenids){
  184. agentOpenids = JSON.parse(agentOpenids);
  185. checkCanPayOnline(agentOpenids.openid);
  186. checkCanPrescription(agentOpenids.openid);
  187. }
  188. queryInit();
  189. }catch(e){
  190. }
  191. }
  192. }else{
  193. if(!userAgent){
  194. d.close();
  195. // dialog({contentType:'tipsbox', skin:'bk-popup' , content:'授权失败',bottom:true}).show();
  196. //模板消息的情况,模板消息带上openid的值给页面
  197. var openid = Request['openid'];
  198. saveAgentOpenid(openid);
  199. window.location.href = "../../home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  200. }else{
  201. try{
  202. checkCanPayOnline(Request['openid']);
  203. checkCanPrescription(Request['openid']);
  204. queryInit();
  205. }catch(e){
  206. }
  207. }
  208. }
  209. }
  210. else{
  211. //校验code与缓存中的code是否一致,一致的话则不再向后端获取openid,因为code只能使用一次
  212. if(agentCode && (code == agentCode)){
  213. try{
  214. var agentOpenids = window.localStorage.getItem(OpenidAgent);
  215. if(agentOpenids){
  216. agentOpenids = JSON.parse(agentOpenids);
  217. checkCanPayOnline(agentOpenids.openid);
  218. checkCanPrescription(agentOpenids.openid)
  219. }
  220. queryInit();
  221. }catch(e){
  222. }
  223. }else{
  224. //校验登录的openid是否与缓存中存在的一致
  225. d.show();
  226. sendPost('weixin/getOpenidByCode', {code: code}, 'json', 'post', openidFailed, function(res){
  227. if (res.status == 200) {
  228. d.close();
  229. localStorage.setItem("weixinCode", code);
  230. var openid = res.openid,
  231. agentOpenids = window.localStorage.getItem(OpenidAgent),
  232. agentOpenid = agentOpenids && JSON.parse(agentOpenids).openid;
  233. saveAgentOpenid(openid);
  234. if( agentOpenid == openid){
  235. if(!userAgent){
  236. window.location.href = "../../home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  237. }else{
  238. try{
  239. checkCanPayOnline(openid);
  240. checkCanPrescription(openid);
  241. queryInit();
  242. }catch(e){
  243. }
  244. }
  245. }else{
  246. window.location.href = server + "wx/html/home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  247. }
  248. } else {
  249. openidFailed(res);
  250. }
  251. });
  252. }
  253. }
  254. }
  255. //判断用户是否登录
  256. function checkUserAgent1(){
  257. var userAgent = window.localStorage.getItem(agentName);
  258. if(!userAgent){
  259. var agentOpenid = window.localStorage.getItem(OpenidAgent);
  260. if(!agentOpenid||agentOpenid=="undefined"){
  261. var Request = new Object();
  262. Request = GetRequest();
  263. var code = Request["code"];
  264. if(code == "" || code == null || code == undefined){
  265. d.close();
  266. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'授权失败',bottom:true}).show();
  267. }
  268. else{
  269. d.show();
  270. var data = {};
  271. data.code = code;
  272. sendPost('weixin/getOpenidByCode', data, 'json', 'post', openidFailed, openidSuccess);
  273. }
  274. }
  275. else{
  276. var jsonstr = $.parseJSON(agentOpenid);
  277. var openid = jsonstr.openid;
  278. if((pagetype>=20&&pagetype<=27) || pagetype=='-1' || pagetype==3 || !pagetype){
  279. pagetype = 0;
  280. window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
  281. }
  282. // window.location.href = server + "wx/html/home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  283. window.location.href = "../../home/html/zhmm-login.html?type=" + pagetype //+ "&openid=" + openid;
  284. }
  285. }
  286. else{
  287. try{
  288. queryInit();
  289. }catch(e){
  290. }
  291. }
  292. }
  293. //判断openid是否在可以在线支付的白名单里面
  294. function checkCanPayOnline(id){
  295. if(id && openidList.indexOf(id)>-1){
  296. canPayOnline = true;
  297. }
  298. }
  299. //判断openid是否在可以开启处方功能的白名单中
  300. function checkCanPrescription(id){
  301. if(id && prescriptionOpenidList.indexOf(id)>-1){
  302. canPrescription = true;
  303. }
  304. }
  305. //成功
  306. function openidSuccess(res) {
  307. if (res.status == 200) {
  308. var openid = res.openid;
  309. saveAgentOpenid(openid);
  310. window.location.href = server + "wx/html/home/html/zhmm-login.html?type=" + pagetype + "&openid=" + openid;
  311. } else {
  312. openidFailed(res);
  313. }
  314. }
  315. //失败
  316. function openidFailed(res) {
  317. d.close();
  318. // if(window.localStorage.getItem(OpenidAgent)){
  319. // window.localStorage.removeItem(OpenidAgent);
  320. // }
  321. if (res && res.msg) {
  322. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  323. } else {
  324. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取认证信息失败',bottom:true}).show();
  325. }
  326. }
  327. //判断用户是否有签约
  328. function checkSign(type){
  329. d.show();
  330. var userAgent = window.localStorage.getItem(agentName);
  331. if(userAgent){
  332. var data = {};
  333. $.ajax(server + "patient/is_sign", {
  334. data: data,
  335. type: 'POST',
  336. dataType: 'json',
  337. beforeSend: function(request) {
  338. request.setRequestHeader("userAgent", userAgent);
  339. },
  340. error: function(res) {
  341. d.close();
  342. if(res.status == 999 || res.status == 998 || res.status == 997){
  343. loginUrl(res.status);
  344. return;
  345. }
  346. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'校验失败',bottom:true}).show();
  347. },
  348. success: function(res) {
  349. d.close();
  350. if(res.status == 999 || res.status == 998 || res.status == 997){
  351. loginUrl(res.status);
  352. }
  353. else if (res.status == 200) {
  354. var is_sign = res.data;//0未签约,1已签约
  355. if(is_sign == 0){
  356. dialog({
  357. title: '提示',
  358. content: '您还未签约,请先签约,谢谢!',
  359. okValue:'签约',
  360. ok: function (){
  361. window.location.href = server + "wx/html/ssgg/html/choose-region.html";
  362. },
  363. cancelValue: '不了',
  364. cancel: function () {
  365. return;
  366. }
  367. }).showModal();
  368. }else{
  369. if(type == 1){
  370. window.location.href = server + "wx/html/zxwz/html/teachers-consult-commit.html";
  371. }
  372. }
  373. } else {
  374. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  375. }
  376. }
  377. });
  378. }
  379. else{
  380. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'用户信息错误',bottom:true}).show();
  381. }
  382. }
  383. var toUsers = localStorage.getItem("toUser");
  384. var curId = localStorage.getItem("id");
  385. var toName = localStorage.getItem("toName");
  386. var consultCode = localStorage.getItem("consultCode");
  387. var pageUrl = {
  388. /**通用跳转**/ 0:function(){
  389. var pageurl = "";
  390. var agentPage = window.localStorage.getItem(pageName);
  391. if(agentPage){
  392. var jsonstr = $.parseJSON(agentPage);
  393. pageurl = jsonstr.pageurl;
  394. }
  395. return pageurl;
  396. }(),
  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. /**健康银行详情页**/ 51:"../../jkjf/html/index.html",
  445. /**健康存折详情页**/ 52:"../../jkjf/html/passbook.html",
  446. /**我的健康存折**/ 53:"../../jkjf/html/my-passbook.html",
  447. /**我的 活动**/ 54:"../../jkjf/html/my-activities.html",
  448. /**活动广场**/ 55:"../../jkjf/html/activity-square.html",
  449. /**活动详情**/ 56:"../../jkjf/html/activity-detail.html",
  450. /**健康银行默认缺省页**/ 57:"../../jkjf/html/unopened.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"));