自建Tomcat完成Android App Links实践

搭建Tomcat服务器(支持SSL)

申请外网域名

使用nat123获得(外网映射tomcat本地网)

为域名申请阿里SSL证书

申请流程
此处域名验证方式使用文件验证
拿到pfx文件后接下步骤

修改conf/server.xml

http默认80端口,https默认443端口,App Links需要使用https
修改原端口8080为80,8443为443

certificateKeystoreFile为ssl证书文件保存地址
certificateKeystorePassword为ssl证书密码

    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />
	
	<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
            maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
                <Certificate certificateKeystoreFile="D:\xxx\apache-tomcat-xxx\conf\cert\xxx.pfx"
                        certificateKeystoreType="PKCS12" 
                        certificateKeystorePassword="z4NY3u6u"/>
        </SSLHostConfig>
    </Connector>
修改conf/web.xml

添加如下代码可以使http请求自动跳https请求

<login-config>  
    <!-- Authorization setting for SSL -->  
    <auth-method>CLIENT-CERT</auth-method>  
    <realm-name>Client Cert Users-only Area</realm-name>  
</login-config>  
<security-constraint>  
    <!-- Authorization setting for SSL -->  
    <web-resource-collection >  
        <web-resource-name >SSL</web-resource-name>  
        <url-pattern>/*</url-pattern>  
    </web-resource-collection>  
    <user-data-constraint>  
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>  
    </user-data-constraint>  
</security-constraint>

按照androidstudio AppLinks Assist指引配置

其中一步将assetlinks.json文件放进webapps/.well-known文件夹下

需要cmd使用rm命令创建.well-known文件夹

真机验证

使用网址直接打开应用

猜你喜欢

转载自blog.csdn.net/weixin_40855673/article/details/119005226