你知道我是谁了 發表於 2023-6-21 19:23:00

uni-app开发的APP跳转到微信小程序

<svg xmlns="http://www.w3.org/2000/svg" style="display: none">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"></path>
                  </svg>
                  <p>uni-app开发的APP跳转到微信小程序需要调用H5+的原生界面控件。</p>
<p><strong>注意事项:</strong></p>
<ul><li>用到了分享功能,在打包原生应用时,需要注意:首先勾选权限配置,manifest.json-&gt;App 模块权限配置-&gt;Share。然后,manifest.json-&gt;App SDK 配置-&gt;分享,按照提示填写微信分享的信息(微信开放平台,不是微信公众平台)。</li><li>因为涉及到第三方 SDK 的配置,需要打包自定义基座进行测试。真机运行自定义基座包使用说明</li><li>需要在微信开放平台开启APP跳转小程序,并管理相应的小程序<br> <img src="https://img-blog.csdnimg.cn/2019041816473523.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N1cGVybG92ZXJf,size_16,color_FFFFFF,t_70"></li></ul>
<h4>跳转到微信小程序的代码:</h4>
<pre><code>&lt;template&gt;
        &lt;view class="center"&gt;
                &lt;view class="text"@click="checkWeChat"&gt;跳转到小程序&lt;/view&gt;
        &lt;/view&gt;
&lt;/template&gt;
&lt;script&gt;
export default {
        data() {
                return {
                        sweixin: null
                }
        },
        onLoad() {
                this.getPlus()
        },
        methods: {
                getPlus() {
                        //获取当前显示的webview
                        var pages = getCurrentPages()
                        var page = pages
                        var currentWebview = page.$getAppWebview()
                        //调用H5+APP的扩展API
                        var shares=null;
                        let that = this
                        var pusher = plus.share.getServices(function(s){
                                shares={};
                                for(var i in s){
                                        var t=s;
                                        shares=t;
                                }
                                that.sweixin=shares['weixin'];
                        }, function(e){
                                console.log("获取分享服务列表失败:"+e.message);
                        });
                        //放入当前的webview
                        currentWebview.append(pusher);
                },
                checkWeChat() {
                        //调用微信小程序
                        this.sweixin.launchMiniProgram({
                                id:'gh_244-------' //要跳转小程序的原始ID
                        })
                }
        }
}
&lt;/script&gt;
</code></pre>
<h4>小程序原始ID获取方法:</h4>
<p>登录微信公众平台,设置-&gt;基本设置,最下边为原始ID<br> <img src="https://img-blog.csdnimg.cn/20190418163908245.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N1cGVybG92ZXJf,size_16,color_FFFFFF,t_70"><br> <img src="https://img-blog.csdnimg.cn/20190418164018863.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N1cGVybG92ZXJf,size_16,color_FFFFFF,t_70"><br> 参考资料:<br> App端跳转小程序方式<br> uni-app中如何使用5+的原生界面控件</p><br><br>
来源:https://www.cnblogs.com/xiao-lang/p/17707734.html
頁: [1]
查看完整版本: uni-app开发的APP跳转到微信小程序