You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							67 lines
						
					
					
						
							2.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							67 lines
						
					
					
						
							2.2 KiB
						
					
					
				
								import {
							 | 
						|
									sandBox
							 | 
						|
								} from './sandBox.js';
							 | 
						|
								
							 | 
						|
								var jweixin = require('jweixin-module');
							 | 
						|
								let setings = "updateTimelineShareData updateAppMessageShareData onMenuShareQQ onMenuShareWeibo onMenuShareQZone startRecord stopRecord onVoiceRecordEnd playVoice pauseVoice stopVoice onVoicePlayEnd uploadVoice downloadVoice chooseImage previewImage uploadImage downloadImage translateVoice getNetworkType openLocation getLocation hideOptionMenu showOptionMenu hideMenuItems showMenuItems hideAllNonBaseMenuItem showAllNonBaseMenuItem closeWindow scanQRCode chooseWXPay openProductSpecificView addCard chooseCard openCard";
							 | 
						|
								export default {
							 | 
						|
									//判断是否在微信中  
							 | 
						|
									isWechat: function() {
							 | 
						|
										var ua = window.navigator.userAgent.toLowerCase();
							 | 
						|
										if (ua.match(/micromessenger/i) == 'micromessenger') {
							 | 
						|
											return true;
							 | 
						|
										} else {
							 | 
						|
											return false;
							 | 
						|
										}
							 | 
						|
									},
							 | 
						|
									//初始化sdk配置  
							 | 
						|
									initJssdk: function(callback) {
							 | 
						|
										//服务端进行签名 ,可使用uni.request替换。 签名算法请看文档
							 | 
						|
										var uri = encodeURIComponent(window.location.href);
							 | 
						|
										  sandBox.get({
							 | 
						|
											  api: 'api/wechat/jssdkconfig',
							 | 
						|
											  data: {
							 | 
						|
												  url:uri
							 | 
						|
											  }
							 | 
						|
										  }).then(res => {
							 | 
						|
												  res = res.data;
							 | 
						|
												  if (res.appId) {
							 | 
						|
													  jweixin.config({
							 | 
						|
													  	debug: false,
							 | 
						|
													  	appId: res.appId,
							 | 
						|
													  	timestamp: res.timestamp,
							 | 
						|
													  	nonceStr: res.nonceStr,
							 | 
						|
													  	signature: res.signature,
							 | 
						|
													  	jsApiList: setings.split(" ")
							 | 
						|
													  });
							 | 
						|
													  //配置完成后,再执行分享等功能  
							 | 
						|
													  if (callback) {
							 | 
						|
													  	callback(res);
							 | 
						|
													  }
							 | 
						|
												  }
							 | 
						|
										  }) 
							 | 
						|
									},
							 | 
						|
									//在需要自定义分享的页面中调用  
							 | 
						|
									share: function(data, url) {
							 | 
						|
										url = url ? url : window.location.href;
							 | 
						|
										if (!this.isWechat()) {
							 | 
						|
											return;
							 | 
						|
										}
							 | 
						|
										//每次都需要重新初始化配置,才可以进行分享  
							 | 
						|
										this.initJssdk(function(signData) {
							 | 
						|
											
							 | 
						|
											jweixin.ready(function() {
							 | 
						|
												var shareData = {
							 | 
						|
													title: data && data.title ? data.title : signData.site_name,
							 | 
						|
													desc: data && data.desc ? data.desc : signData.site_description,
							 | 
						|
													link:url,
							 | 
						|
													imgUrl: data && data.img ? data.img : signData.site_logo,
							 | 
						|
												};
							 | 
						|
												//分享给朋友接口  
							 | 
						|
												jweixin.updateAppMessageShareData(shareData);
							 | 
						|
												//分享到朋友圈接口  
							 | 
						|
												/* jweixin.updateTimelineShareData(shareData); */
							 | 
						|
											});
							 | 
						|
										},url);
							 | 
						|
									}
							 | 
						|
								}
							 |