ss 1 rok pred
commit
3f1603d930
1 zmenil súbory, kde vykonal 85 pridanie a 0 odobranie
  1. 85 0
      common/util/wechat.js

+ 85 - 0
common/util/wechat.js

@@ -0,0 +1,85 @@
+var jweixin = require('./jweixin.js');
+
+var serverUrl = "https://mdyg.sdmingde.cn/api/h5/";
+
+export default {
+    //判断是否在微信中
+    isWechat: function() {
+        var ua = window.navigator.userAgent.toLowerCase();
+        if (ua.match(/micromessenger/i) == 'micromessenger') {
+            // console.log('是微信客户端')
+            return true;
+        } else {
+            // console.log('不是微信客户端')
+            return false;
+        }
+    },
+    initJssdk:function(callback){
+		var surl = encodeURIComponent(window.location.href); // 当前地址
+		uni.request({
+		    url: serverUrl + 'Oauth/jssdk',
+			data: {url:surl},
+			method: 'POST',
+			header: {
+				'content-type': 'application/x-www-form-urlencoded'
+			},
+		    success: function (res) {
+		        console.log(res)
+		        if(res.data.code == 0) {					
+					jweixin.config({
+					    debug: res.data.data.debug,
+					    appId: res.data.data.appId,
+					    timestamp: res.data.data.timestamp,
+					    nonceStr: res.data.data.nonceStr,
+					    signature: res.data.data.signature,
+					    jsApiList: res.data.data.jsApiList,
+					});
+					//配置完成后,再执行分享等功能
+					if (callback) {
+					    callback(res.data);
+					}
+		        }
+		    },
+			fail: function (err) {
+				console.log(err);
+			}
+		})
+    },
+	// 获取微信对象
+	getWx: function(callback) {
+	    if (!this.isWechat()) {
+	        console.log('不是微信客户端')
+	        return;
+	    }
+	
+	    this.initJssdk(function(res) {
+	        jweixin.ready(function() {
+	            callback(jweixin);
+	        });
+	    });
+	},
+    //在需要定位页面调用
+    location: function(callback) {
+        if (!this.isWechat()) {
+            console.log('不是微信客户端')
+            return;
+        }
+
+        this.initJssdk(function(res) {
+            jweixin.ready(function() {
+                console.info('定位ready')
+                jweixin.getLocation({
+                    type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
+                    success: function (res) {
+                        console.log(res);
+                        callback(res)
+                    },
+                    fail:function(res){
+                        console.log(res)
+                    },
+                });
+            });
+        });
+    },
+	
+}