推广app免填邀请码,替代Shareinstall和openinstall开发方案

1,459 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

app推广邀请好友,为了避免增添用户反感,一般都会采取免填邀请码的方式,让用户在点击了邀请链接之后,进入app之后自动成为被推广对象。

市面上的推广辅助工具相对来说Shareinstall和openinstall很不错,但是对于资金并不是很充裕的个人开发者或者微小型公司来说,动辄三四万一年的使用费用还是非常高昂的。

老七也遇到了这么一档子烦心事,去年使用费用3000多,各种服务。。。总之你去用,他们是各种满足你的要求,为了节约开发时间,老七对接了他们的sdk。时光荏苒岁月如梭啊,一年过去了,到期了服务停了,这下可慌神了。没招咱得用啊,打电话不接,微信回复爱答不理。就是从去年的3000多一下跳跃到现在的小4w。而且没的商量,就是一句公司调整收费标准,那意思你爱用不用,不用拉倒!顿时一万只草泥马,不知道你们在过去的一年中经历了什么让你们变得如此牛批。算了你们牛归你们,咱穷还是事实,咱自己办法解决还不行?

说了一堆废话,言归正传。说白了,就是用户点击链接会携带一个参数,这个参数在打开app的时候会被识别,根据这个参数来处理当前登录用户的绑定关系就可以了。咱没有那么强的技术,咱用剪贴板来替代总行啊。

不说了,直接上h5页面代码

<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<title></title>
	<link  type="text/css" href="/Application/Home/Static/css/download.css" rel="stylesheet" />
</head>
<body>
 
<div class="web_bg">
<a href='javascript:void(0);' id='downloadButton' style="display: block;">
	<input class="mytxt" id="xmid" value="" readonly="readonly" unselectable="on" style="z-index: -100;"></input>
	<img src="http://********/*****.jpg" width="100%" height="100%" onclick="copyNum()" style="z-index: 999;margin-top: -20px;">
 
</a>
</div>	
 
<block name="js">
	<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
	<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= "*&TJLANG&IYAK"+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 = 'dslangya://';
                    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 = '****://';//安卓兄弟提供
                        setTimeout(function(){
                            window.location= "https://*******"; //android下载地址
 
                        },2000);
                    } catch(e) {}
                }
            }
        }
	</script>
</body>
</html>

是不是很简单是不是很熟悉,其中可以拆分出来三种可以平常用的案例,在老七的博文中都有哈,喜欢的小伙伴可以查看,日期很相似,如下:

1.js实现点击复制当前文本到剪贴板功能(兼容所有浏览器,代码经过测试完全可用)

blog.csdn.net/u010991531/…

2.js判断手机是否安装app,未安装则安装,已安装则打开app(兼容Android、ios,亲测可用)

blog.csdn.net/u010991531/…

3.js获取h5链接中的参数(亲测可用)

blog.csdn.net/u010991531/…

至此剩下的事情就是安卓和ios兄弟们的工作了,他们将剪贴板中的数据(加密哦)获得并解密后就可以实现类似的功能了。

喜欢老七的小伙伴,请加个关注点个赞,同时欢迎大佬批评指正!!!