首页 > 其他分享 >uniapp iOS微信分享要求分享图必须小于20k限制的解决

uniapp iOS微信分享要求分享图必须小于20k限制的解决

时间:2022-12-28 17:24:58浏览次数:39  
标签:iurl uniapp success liveInfo 微信 https fail uni 分享

//分享给朋友
	wxManShare(){
				
		if(this.$platform=='android'){
			let iurl=this.liveInfo.limg
			uni.share({
			    provider: "weixin",
			    scene: "WXSceneSession",
			    type: 0,
			    href: `https://m.xxx.com/lives/room/${this.roomid}`,
			    title: this.liveInfo.ltitle,
			    summary: descInfo,
			    imageUrl: iurl,
			    success: ()=>{},
			    fail: ()=>{}
			});
			this.$refs.sharePopup.close()
		}else{
			let iurl = "https://img-12xxx8.file.myqcloud.com/other/logo/live_app.png"  //默认准备一张备用分享图
			let that = this  //需要改变指向
			uni.downloadFile({  //网上图片资源转为本地
				url: that.liveInfo.limg,
				success: (res) => {
					if (res.statusCode == 200) {
						let imgType=that.liveInfo.limg.split(".").pop()  //获取图片类型,只有jpg类型图片才支持图片质量quality参数
						uni.compressImage({  //压缩图片
							src: res.tempFilePath,
							quality: 20,
							width: imgType=="jpg"?"200px":"120px",
							height: "auto",
							success: ret => {
								uni.getFileInfo({  //获取图片信息
									filePath: ret.tempFilePath,
									success: imgInfo => {
										if(imgInfo.size/1024<20){  //判断图片大小,小于20k才有效
											iurl = ret.tempFilePath
										}
									},
									complete: () => {
										uni.share({
										    provider: "weixin",
										    scene: "WXSceneSession",
										    type: 0,
										    href: `https://m.kxxxe.com/lives/room/${that.roomid}`,
										    title: that.liveInfo.ltitle,
										    summary: descInfo,
										    imageUrl: iurl,
										    success: ()=>{},
										    fail: ()=>{}
										});
										that.$refs.sharePopup.close()
									} 
								})
							},
							fail: () => {
								uni.share({
								    provider: "weixin",
								    scene: "WXSceneSession",
								    type: 0,
								    href: `https://m.kxxxe.com/lives/room/${that.roomid}`,
								    title: that.liveInfo.ltitle,
								    summary: descInfo,
								    imageUrl: iurl,
								    success: ()=>{},
								    fail: ()=>{}
								});
								that.$refs.sharePopup.close()
							}
						})
					}
				},
				fail: ()=>{
					uni.share({
					    provider: "weixin",
					    scene: "WXSceneSession",
					    type: 0,
					    href: `https://m.kxxx.com/lives/room/${that.roomid}`,
					    title: that.liveInfo.ltitle,
					    summary: descInfo,
					    imageUrl: iurl,
					    success: ()=>{},
					    fail: ()=>{}
					});
					that.$refs.sharePopup.close()
				}
			});
		}
	},

标签:iurl,uniapp,success,liveInfo,微信,https,fail,uni,分享
From: https://www.cnblogs.com/huihuihero/p/17010810.html

相关文章