123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /**
- * desc: 环境的配置与检测
- * author: wangyang
- * date: 2015-04-11
- */
- // define(['wx', 'ctk'], function(wx, ctk) {
- // define(['require', 'wx'], function(require) {
- define(function (require) {
- var apiPath,
- appVersion = '2.0',
- o2oVersion = '2015121601',
- test = true,
- isAndroid = false,
- isIOS = false,
- isChubao = false,
- isWX = false;
- var uri = location.href;
- if (uri.indexOf('common.yiguanjia.club') > -1) {
- test = false;
- apiPath = 'http://api.yiguanjia.club';
- } else if (uri.indexOf('commontest.yiguanjia.club') > -1) {
- apiPath = 'http://apitest.yiguanjia.club';
- } else if (uri.indexOf('admin.yiguanjiadev.me') > -1) {
- apiPath = 'http://admin.yiguanjiadev.me';
- } else if (uri.indexOf('common.yiguanjiadev.me') > -1) {
- apiPath = 'http://common.yiguanjiadev.me';
- }
- var ua = navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
- isWX = true;
- require(['http://res.wx.qq.com/open/js/jweixin-1.0.0.js'], function(wx) {
- if (typeof wx === 'undefined') return;
- var wxSignObject = document.getElementById('wxMain');
- if (wxSignObject) {
- var wxConfig = JSON.parse(wxSignObject.getAttribute('data-sign'));
- wx.config({
- debug: false,
- appId: wxConfig.appId,
- timestamp: wxConfig.timestamp,
- nonceStr: wxConfig.nonceStr,
- signature: wxConfig.signature,
- jsApiList: [
- 'checkJsApi',
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'onMenuShareQQ',
- 'onMenuShareWeibo',
- 'hideMenuItems',
- 'showMenuItems',
- 'hideAllNonBaseMenuItem',
- 'showAllNonBaseMenuItem',
- 'translateVoice',
- 'startRecord',
- 'stopRecord',
- 'onRecordEnd',
- 'playVoice',
- 'pauseVoice',
- 'stopVoice',
- 'uploadVoice',
- 'downloadVoice',
- 'chooseImage',
- 'previewImage',
- 'uploadImage',
- 'downloadImage',
- 'getNetworkType',
- 'openLocation',
- 'getLocation',
- 'hideOptionMenu',
- 'showOptionMenu',
- 'closeWindow',
- 'scanQRCode',
- 'chooseWXPay',
- 'openProductSpecificView',
- 'addCard',
- 'chooseCard',
- 'openCard'
- ]
- });
- // 获取用户坐标
- wx.ready(function () {
- wx.getLocation({
- success: function (res) {
- var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
- var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
- //var speed = res.speed; // 速度,以米/每秒计
- //var accuracy = res.accuracy; // 位置精度
- userLocation = latitude + ',' + longitude;
- localStorage.setItem('userLocation', userLocation);
- },
- cancel: function (res) {
- alert('用户拒绝授权获取地理位置');
- }
- });
- wx.onMenuShareTimeline({
- title: '家政服务,首选壹管家APP',
- link: 'http://common.yiguanjia.club/o2o/web/index',
- imgUrl: 'http://pics.yiguanjia.club/4-1-01.png'
- });
- wx.onMenuShareAppMessage({
- title: '家政服务,首选壹管家APP',
- desc: '足不出户,就能享受专业保洁师为您提供的贴心服务!',
- link: 'http://common.yiguanjia.club/o2o/web/index',
- imgUrl: 'http://pics.yiguanjia.club/4-1-01.png'
- });
- });
- }
- });
- }
- // 判断触宝客户端UA
- if (ua.match(/cootekservice/i) == 'cootekservice') {
- isChubao = true;
- require(['../../common/js/ctk-1.0.0'], function(ctk){
- var appkey = '7168071009412968',
- serviceId = 'mall.cootekservice.com',
- timestamp = Math.floor((+new Date()) / 1000),
- charset = 'UTF-8',
- signType = 'MD5',
- host = '183.136.223.43',
- jsApiList = ['logged', 'login', 'show', 'dismiss', 'select', 'pay', 'getLocation'],
- // jsApiList = ['getDefaultAddress'],
- sign = 'mock-sign';
- if (test) {
- appkey = '7168244618702012';
- serviceId = '183.136.223.45:30007';
- }
- ctk.config(appkey, serviceId, timestamp, charset, signType, host, jsApiList, sign);
- ctk.ready(function() {
- ctk.checkJsApi({
- jsApiList: jsApiList,//需要判断是否支持的api名称列表
- success: function(res) {
- //判断支持之后之后的回调函数,res是结果字典,包含errMsg和result
- //示例:{"errMsg": "check_success!", "result" : {"logged" : true, "login" : true}}
- if (res.errMsg) {
- // alert(res.errMsg);
- return;
- }
- ctk.getLocation({
- success: function(res) {
- // alert(JSON.stringify(res));
- //定位之后的回调函数,res包含四个key:city,address,latitude,longitude,
- //分别代表定位城市,文字地址,纬度,经度
- //如{"city" : "上海", "address" : "上海市徐汇区虹梅路2007号", "latitude" : 31.17 ,"longitude" : 121.38}
- }
- });
- }
- });
- });
- });
- }
- var newCheck = true;
- //新的方式判断客户端环境,新版本稳定一段时间后切换判断方式
- if (newCheck) {
- var userAgent = navigator.userAgent;
- if (userAgent.indexOf('Client/1') > -1) {
- isIOS = true;
- } else if (userAgent.indexOf('Client/2') > -1) {
- isAndroid = true;
- }
- var re = /Version\/[0-9.]+/g;
- r = re.exec(userAgent);
- if (r !== null) {
- appVersion = r[0].replace('Version/', '');
- }
- } else {
- var isWin = (navigator.platform == 'Win32') || (navigator.platform == 'Windows');
- var isMac = (navigator.platform == 'Mac68K') || (navigator.platform == 'MacPPC') || (navigator.platform == 'Macintosh') || (navigator.platform == 'MacIntel');
- if (!isWin && !isMac) {
- if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
- isIOS = true;
- } else {
- isAndroid = true;
- }
- }
- }
- return {
- test: test,
- apiPath: apiPath,
- isAndroid: isAndroid,
- isIOS: isIOS,
- isWX: isWX,
- isChubao: isChubao,
- o2oVersion: o2oVersion,
- appVersion: appVersion
- }
- })
|