config.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * desc: 环境的配置与检测
  3. * author: wangyang
  4. * date: 2015-04-11
  5. */
  6. // define(['wx', 'ctk'], function(wx, ctk) {
  7. // define(['require', 'wx'], function(require) {
  8. define(function (require) {
  9. var apiPath,
  10. appVersion = '2.0',
  11. o2oVersion = '2015121601',
  12. test = true,
  13. isAndroid = false,
  14. isIOS = false,
  15. isChubao = false,
  16. isWX = false;
  17. var uri = location.href;
  18. if (uri.indexOf('common.yiguanjia.club') > -1) {
  19. test = false;
  20. apiPath = 'http://api.yiguanjia.club';
  21. } else if (uri.indexOf('commontest.yiguanjia.club') > -1) {
  22. apiPath = 'http://apitest.yiguanjia.club';
  23. } else if (uri.indexOf('admin.yiguanjiadev.me') > -1) {
  24. apiPath = 'http://admin.yiguanjiadev.me';
  25. } else if (uri.indexOf('common.yiguanjiadev.me') > -1) {
  26. apiPath = 'http://common.yiguanjiadev.me';
  27. }
  28. var ua = navigator.userAgent.toLowerCase();
  29. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  30. isWX = true;
  31. require(['http://res.wx.qq.com/open/js/jweixin-1.0.0.js'], function(wx) {
  32. if (typeof wx === 'undefined') return;
  33. var wxSignObject = document.getElementById('wxMain');
  34. if (wxSignObject) {
  35. var wxConfig = JSON.parse(wxSignObject.getAttribute('data-sign'));
  36. wx.config({
  37. debug: false,
  38. appId: wxConfig.appId,
  39. timestamp: wxConfig.timestamp,
  40. nonceStr: wxConfig.nonceStr,
  41. signature: wxConfig.signature,
  42. jsApiList: [
  43. 'checkJsApi',
  44. 'onMenuShareTimeline',
  45. 'onMenuShareAppMessage',
  46. 'onMenuShareQQ',
  47. 'onMenuShareWeibo',
  48. 'hideMenuItems',
  49. 'showMenuItems',
  50. 'hideAllNonBaseMenuItem',
  51. 'showAllNonBaseMenuItem',
  52. 'translateVoice',
  53. 'startRecord',
  54. 'stopRecord',
  55. 'onRecordEnd',
  56. 'playVoice',
  57. 'pauseVoice',
  58. 'stopVoice',
  59. 'uploadVoice',
  60. 'downloadVoice',
  61. 'chooseImage',
  62. 'previewImage',
  63. 'uploadImage',
  64. 'downloadImage',
  65. 'getNetworkType',
  66. 'openLocation',
  67. 'getLocation',
  68. 'hideOptionMenu',
  69. 'showOptionMenu',
  70. 'closeWindow',
  71. 'scanQRCode',
  72. 'chooseWXPay',
  73. 'openProductSpecificView',
  74. 'addCard',
  75. 'chooseCard',
  76. 'openCard'
  77. ]
  78. });
  79. // 获取用户坐标
  80. wx.ready(function () {
  81. wx.getLocation({
  82. success: function (res) {
  83. var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
  84. var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
  85. //var speed = res.speed; // 速度,以米/每秒计
  86. //var accuracy = res.accuracy; // 位置精度
  87. userLocation = latitude + ',' + longitude;
  88. localStorage.setItem('userLocation', userLocation);
  89. },
  90. cancel: function (res) {
  91. alert('用户拒绝授权获取地理位置');
  92. }
  93. });
  94. wx.onMenuShareTimeline({
  95. title: '家政服务,首选壹管家APP',
  96. link: 'http://common.yiguanjia.club/o2o/web/index',
  97. imgUrl: 'http://pics.yiguanjia.club/4-1-01.png'
  98. });
  99. wx.onMenuShareAppMessage({
  100. title: '家政服务,首选壹管家APP',
  101. desc: '足不出户,就能享受专业保洁师为您提供的贴心服务!',
  102. link: 'http://common.yiguanjia.club/o2o/web/index',
  103. imgUrl: 'http://pics.yiguanjia.club/4-1-01.png'
  104. });
  105. });
  106. }
  107. });
  108. }
  109. // 判断触宝客户端UA
  110. if (ua.match(/cootekservice/i) == 'cootekservice') {
  111. isChubao = true;
  112. require(['../../common/js/ctk-1.0.0'], function(ctk){
  113. var appkey = '7168071009412968',
  114. serviceId = 'mall.cootekservice.com',
  115. timestamp = Math.floor((+new Date()) / 1000),
  116. charset = 'UTF-8',
  117. signType = 'MD5',
  118. host = '183.136.223.43',
  119. jsApiList = ['logged', 'login', 'show', 'dismiss', 'select', 'pay', 'getLocation'],
  120. // jsApiList = ['getDefaultAddress'],
  121. sign = 'mock-sign';
  122. if (test) {
  123. appkey = '7168244618702012';
  124. serviceId = '183.136.223.45:30007';
  125. }
  126. ctk.config(appkey, serviceId, timestamp, charset, signType, host, jsApiList, sign);
  127. ctk.ready(function() {
  128. ctk.checkJsApi({
  129. jsApiList: jsApiList,//需要判断是否支持的api名称列表
  130. success: function(res) {
  131. //判断支持之后之后的回调函数,res是结果字典,包含errMsg和result
  132. //示例:{"errMsg": "check_success!", "result" : {"logged" : true, "login" : true}}
  133. if (res.errMsg) {
  134. // alert(res.errMsg);
  135. return;
  136. }
  137. ctk.getLocation({
  138. success: function(res) {
  139. // alert(JSON.stringify(res));
  140. //定位之后的回调函数,res包含四个key:city,address,latitude,longitude,
  141. //分别代表定位城市,文字地址,纬度,经度
  142. //如{"city" : "上海", "address" : "上海市徐汇区虹梅路2007号", "latitude" : 31.17 ,"longitude" : 121.38}
  143. }
  144. });
  145. }
  146. });
  147. });
  148. });
  149. }
  150. var newCheck = true;
  151. //新的方式判断客户端环境,新版本稳定一段时间后切换判断方式
  152. if (newCheck) {
  153. var userAgent = navigator.userAgent;
  154. if (userAgent.indexOf('Client/1') > -1) {
  155. isIOS = true;
  156. } else if (userAgent.indexOf('Client/2') > -1) {
  157. isAndroid = true;
  158. }
  159. var re = /Version\/[0-9.]+/g;
  160. r = re.exec(userAgent);
  161. if (r !== null) {
  162. appVersion = r[0].replace('Version/', '');
  163. }
  164. } else {
  165. var isWin = (navigator.platform == 'Win32') || (navigator.platform == 'Windows');
  166. var isMac = (navigator.platform == 'Mac68K') || (navigator.platform == 'MacPPC') || (navigator.platform == 'Macintosh') || (navigator.platform == 'MacIntel');
  167. if (!isWin && !isMac) {
  168. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  169. isIOS = true;
  170. } else {
  171. isAndroid = true;
  172. }
  173. }
  174. }
  175. return {
  176. test: test,
  177. apiPath: apiPath,
  178. isAndroid: isAndroid,
  179. isIOS: isIOS,
  180. isWX: isWX,
  181. isChubao: isChubao,
  182. o2oVersion: o2oVersion,
  183. appVersion: appVersion
  184. }
  185. })