| 
 | |
| import login from '@/api/modules/login' | |
| // import config from "../config.js" | |
| import jWeixin from './lib/jweixin-module.js' | |
| import Vue from 'vue' | |
| 
 | |
| function share() { //微信分享 | |
| 	//获取签名 | |
| 	let data = { | |
| 		// location.href.split('#')[0]) | |
| 		// url: Vue.prototype.$config.redirect + '/#/' | |
| 		url: location.href.split('#')[0] | |
| 	} | |
| 	login.getSignPackage(data).then(res => { | |
| 		if (res.code == 200) { | |
| 			let { | |
| 				appId, | |
| 				nonceStr, | |
| 				signature, | |
| 				timestamp | |
| 			} = res.result | |
| 			console.log(appId); | |
| 			jWeixin.config({ | |
| 				// debug: true, | |
| 				debug: false, | |
| 				appId: appId, | |
| 				nonceStr: nonceStr, | |
| 				signature: signature, | |
| 				timestamp: timestamp, | |
| 				jsApiList: [ | |
| 					'updateTimelineShareData', | |
| 					'updateAppMessageShareData', | |
| 					'onMenuShareWeibo', | |
| 					'getLocation', | |
| 					'chooseWXPay', | |
| 					'requestMerchantTransfer', | |
| 					'checkJsApi', | |
| 					'scanQRCode', | |
| 				], | |
| 				success: function () { | |
| 					console.log('配置成功'); | |
| 				} | |
| 			}); | |
| 
 | |
| 			jWeixin.ready(function () { | |
| 				// 微信分享的数据 | |
| 				var shareData = { | |
| 					"link": addQueryParams(data.url), | |
| 					"desc": "四零语境", | |
| 					"title": "四零语境,温柔呵护每一刻!", | |
| 					imgUrl: uni.getStorageSync('login_logo'), | |
| 					success: function () { | |
| 						//分享成功可以做相应的数据处理 | |
| 						console.log('注册分享成功'); | |
| 						// uni.showToast({ | |
| 						// 	mask: true, | |
| 						// 	duration: 1000, | |
| 						// 	title: '注册分享成功', | |
| 						// }); | |
| 					}, | |
| 					fail : function (e){ | |
| 						console.log(e); | |
| 					} | |
| 				}; | |
| 				//分享微信朋友圈内容设置 | |
| 				jWeixin.updateTimelineShareData(shareData); | |
| 				//分享给朋友内容设置 | |
| 				jWeixin.updateAppMessageShareData(shareData); | |
| 				//分享到微博内容设置 | |
| 				jWeixin.onMenuShareWeibo(shareData); | |
| 			}); | |
| 
 | |
| 			jWeixin.error(function (err) { | |
| 				console.error(err); | |
| 				// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 | |
| 			}) | |
| 		} | |
| 	}) | |
| } | |
| 
 | |
| function addQueryParams(url) { | |
| 	try{ | |
|         if (url) { | |
|             //获取用户id | |
|             let userInfo = uni.getStorageSync('userInfo') | |
|             if (userInfo?.id) { | |
|                 url += `?inviter=${userInfo.id}` | |
|             } | |
|         } | |
| 	    return url | |
|     }catch(e){ | |
|         console.log(e); | |
|         return url | |
|     } | |
| } | |
| 
 | |
| export default share
 |