weixin_common.js 21 KB

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