1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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.split('#')[0]); // 当前地址
- 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);
- }
- })
- },
- //在需要定位页面调用
- 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)
- },
- });
- });
- });
- }
- }
|