如何生成跳转支付宝红包短链接浏览网页自动跳转打开支付宝代码JS代码

最近一段时间,支付宝的赏金红包十分火爆,各种微信群内都是这种红包口令。这种口令需要复制后,在打开支付宝才能领取红包。然后,也出现一种黑科技,直接在微信里面点击url,自动跳转到支付宝,并且红包是直接领取的。下面我就来讲下这个是怎么实现的。如何生成跳转支付宝红包短链接浏览网页自动跳转打开支付宝代码JS代码

原理

在ios9后,ios提供了一个新特性,叫做Universal Links,这个技术的作用是,每个app可以向ios系统注册自己监控的url,当在其他应用打开这个url时,会到对应的App打开这个链接。
目前微信已经和谐这个功能,QQ还可以

实现

1.获取红包code

在支付宝把你到红包二维码发送到电脑上,然后用微信去扫,你会看到一个url

https://qr.alipay.com/c1x***************wya7a

最后面那个/后面到就是你的红包code

2.建立网页

网页这一块我也是从网上抓包来到,毕竟自己也不熟悉微信API,直接贴代码

index.html

<html lang="zh-cmn-hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge, chrome=1">
<title>正在打开支付宝,请稍候……</title>
</head>
<body>
<script src="kouling.js"></script>
</body>
</html>

kouling.js


<span class="hljs-keyword">var</span> _0 = <span class="hljs-string">"https://qr.alipay.com/c1x***************wya7a"</span>;
<span class="hljs-keyword">var</span> _1 = <span class="hljs-string">"https://qr.alipay.com/c1x***************wya7a"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">is_weixin</span>() </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/MicroMessenger/i</span>.test(navigator.userAgent)) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">is_android</span>() </span>{
    <span class="hljs-keyword">var</span> ua = navigator.userAgent.toLowerCase();
    <span class="hljs-keyword">if</span> (ua.match(<span class="hljs-regexp">/(Android|SymbianOS)/i</span>)) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">is_ios</span>() </span>{
    <span class="hljs-keyword">var</span> ua = navigator.userAgent.toLowerCase();
    <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/iphone|ipad|ipod/</span>.test(ua)) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">android_auto_jump</span>() </span>{
    WeixinJSBridge.invoke(<span class="hljs-string">"jumpToInstallUrl"</span>, {}, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) </span>{});
    <span class="hljs-built_in">window</span>.close();
    WeixinJSBridge.call(<span class="hljs-string">"closeWindow"</span>)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ios_auto_jump</span>() </span>{
    <span class="hljs-keyword">if</span> (_0 != <span class="hljs-string">""</span>) {
        location.href = _0
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">window</span>.close();
        WeixinJSBridge.call(<span class="hljs-string">"closeWindow"</span>)
    }
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onAutoinit</span>() </span>{
    <span class="hljs-keyword">if</span> (is_android()) {
        android_auto_jump();
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
    <span class="hljs-keyword">if</span> (is_ios()) {
        ios_auto_jump();
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
    }
}
<span class="hljs-keyword">if</span> (is_weixin()) {
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> WeixinJSBridge == <span class="hljs-string">"undefined"</span>) {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">document</span>.addEventListener) {
            <span class="hljs-built_in">document</span>.addEventListener(<span class="hljs-string">"WeixinJSBridgeReady"</span>, onAutoinit, <span class="hljs-literal">false</span>)
        } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-built_in">document</span>.attachEvent) {
            <span class="hljs-built_in">document</span>.attachEvent(<span class="hljs-string">"WeixinJSBridgeReady"</span>, onAutoinit);
            <span class="hljs-built_in">document</span>.attachEvent(<span class="hljs-string">"onWeixinJSBridgeReady"</span>, onAutoinit)
        }
    } <span class="hljs-keyword">else</span> {
        onAutoinit()
    }
} <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">if</span> (_1 != <span class="hljs-string">""</span>) {
        location.href = _1
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">window</span>.close()
    }
}

把js第1,2行的code改成你自己的

3.搭建服务器

PS:你需要有自己的域名和服务器,没有域名生成不了短链接
我用的是openresty也就是nginx来搭建服务器
openresty的安装,请看http://openresty.org/en/
安装完openresty后,进入/usr/local/openresty/nginx/conf目录,新建一个配置alipay.conf


user root;
worker_processes  <span class="hljs-number">1</span>;
error_log logs/error.<span class="hljs-built_in">log</span>;
events {
        worker_connections <span class="hljs-number">1024</span>;
}
http{
        include       mime.types;
        default_type  application/octet-stream;
        server {
                listen  <span class="hljs-number">80</span>;
                server_name  alipay.shengchaojie.com;
                root /root/html;
                location /scj{
                }
        }
}

然后建立文件夹/root/html/scj,这个你可以自定义
把index.html还有kouling.js放到文件夹下面
进入/usr/local/openresty/nginx/sbin目录,运行指令./nginx -c conf/alipay.conf

现在静态资源部署好了,把你的域名指向这台服务器,这步就不讲了。
你可以通过http://ip/scj或者http://domain/scj来访问这个页面,如果是在微信里面,那么已经跳转到支付宝领取红包了

打赏
微信 OR 支付宝 扫描二维码
为本文作者 打个赏
pay_weixin
pay_weixin
金额随意 快来“打”我呀~

未经允许不得转载:网赚培训|网络赚钱|国外网赚培训-信言网赚博客 » 如何生成跳转支付宝红包短链接浏览网页自动跳转打开支付宝代码JS代码

赞 (0)

评论 0

评论前必须登录!

登陆 注册