+
95
-

回答

openinstall是收费的,如果想要免费的话,直接在分享的h5中自动将分享吗复制到剪贴板,然后安装打开app从剪贴板中获取邀请的参数即可。

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />

</head>

<body>
    <input class="mytxt" id="xmid" value="" readonly="readonly" unselectable="on" style="z-index: -100;"></input>
    <img src="//repo.bfw.wiki/bfwrepo/icon/650d0ddcf2334.png" width="100%" height="100%"BfwOnclick="copyNum()" style="z-index: 999;margin-top: -20px;">
    <script type="text/javascript">
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("=");
        }
        document.getElementById('xmid').value= "youappshare:"+strs[1];
 
        function copyNum() {
            var NumClip = document.getElementById("xmid");
            var NValue = NumClip.value;
            var valueLength = NValue.length;
            selectText(NumClip, 0, valueLength);
            if (document.execCommand('copy', false, null)) {
                document.execCommand('copy', false, null) // 执行浏览器复制命令
                openApp();
            } else {
                alert("不兼容");
            }
        }
        // input自带的select()方法在苹果端无法进行选择,所以需要自己去写一个类似的方法
        // 选择文本。createTextRange(setSelectionRange)是input方法
        function selectText(textbox, startIndex, stopIndex) {
            if (textbox.createTextRange) { //ie
                var range = textbox.createTextRange();
                range.collapse(true);
                range.moveStart('character', startIndex); //起始光标
                range.moveEnd('character', stopIndex - startIndex); //结束光标
                range.select(); //不兼容苹果
            } else { //firefox/chrome
                textbox.setSelectionRange(startIndex, stopIndex);
                textbox.focus();
            }
}

 
        //打开(下载)App
        function openApp(){
 
            var ua = window.navigator.userAgent.toLowerCase();
            //微信
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                window.location.href='******';//应用宝下载链接
            }else{//非微信浏览器
                if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
                    window.location = 'taobao://';
                    var ifr = document.createElement("iframe");
                    ifr.src = "****://"; /***打开app的协议,ios提供***/
                    ifr.style.display = "none";
                    document.body.appendChild(ifr);
                    window.setTimeout(function(){
                        document.body.removeChild(ifr);
                        window.location.href = "http://itunes.apple.com/cn/app/****";             
                        /***下载app的地址***/
                    },2000);
 
                }else if (navigator.userAgent.match(/android/i)) {
 
                    var state = null;
                    try {
                        window.location = 'taobao://';//安卓下载地址
                        setTimeout(function(){
                            window.location= "https://*******"; //android下载地址
 
                        },2000);
                    } catch(e) {}
                }
            }
        }
    </script>
</body>

</html>

uniapp端获取剪贴板内容,可放在app的onlanch里面,不要使用官方的

uni.setClipboardData({
	data: 'hello',
	success: function () {
		console.log('success');
	}
});
uni.getClipboardData({
	success: function (res) {
		console.log(res.data);
	}
});

这个获取不到别的地方复制到前铁板的内容,只能获取uni.setClipboardData的数据

所以我们使用Native.js 去获取系统剪贴板内容 这个比较好用 也可以监听到其他地方复制的内容,但是只支持app安卓

function copyToClip(){
	var Context = plus.android.importClass("android.content.Context");
	var main = plus.android.runtimeMainActivity();
	var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
// plus.android.invoke(clip,"setText","I'm copy from Native.js");  
	return plus.android.invoke(clip,"getText");
}
ios 
var UIPasteboard = plus.ios.importClass("UIPasteboard");
var generalPasteboard = UIPasteboard.generalPasteboard();
// 设置/获取文本内容:
//generalPasteboard.setValueforPasteboardType("testValue", "public.utf8-plain-text");
var value = generalPasteboard.valueForPasteboardType("public.utf8-plain-text");

网友回复

我知道答案,我要回答