config.js 6.2 KB

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