Android端app拉起微信小程序跳转提示“跳转失败” 不知道为何?
发布于 6 年前 作者 fujie 3655 次浏览 来自 官方Issues

IWXAPI api = WXAPIFactory.createWXAPI(context, appId, false);
            WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
            req.userName = userId;
            if (TextUtils.isEmpty(path)) {
                req.path = “”;
            } else {
                req.path = path;
            }
            if (TextUtils.isEmpty(mini)) {
                req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;
            } else {
                req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;
            }
            api.sendReq(req);
            
            
微信版本7.0.6

appId: wx516f09ef989c1298
userId,req.userName: gh_b52e04a0100c   
path="";
mini="";
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;       

compile ‘com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+’  
            
           

3 回复

我也遇这个问题,但确认appid没用错, 应用签名,大小写都试过,帮我看原因

package com.example.myapplication3;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
 
import androidx.appcompat.app.AppCompatActivity;
 
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
 
 
public class MainActivity extends AppCompatActivity {
    public static final String TAG = MainActivity.class.getSimpleName();
 
    // APP_ID 替换为你的应用从官方网站申请到的合法appID
    private static final String APP_ID = "wx82d0****fe25eb40";
 
    // IWXAPI 是第三方app和微信通信的openApi接口
    private IWXAPI api;
 
    private BroadcastReceiver broadcastReceiver;
 
    private void regToWx() {
        // 通过WXAPIFactory工厂,获取IWXAPI的实例
        api = WXAPIFactory.createWXAPI(this, APP_ID, true);
 
        // 将应用的appId注册到微信
        api.registerApp(APP_ID);
 
        broadcastReceiver = new BroadcastReceiver() {
            [@Override](/user/Override)
            public void onReceive(Context context, Intent intent) {
 
                // 将该app注册到微信
                api.registerApp(APP_ID);
            }
        };
 
        //建议动态监听微信启动广播进行注册到微信
        registerReceiver(broadcastReceiver, new IntentFilter(ConstantsAPI.ACTION_REFRESH_WXAPP));
 
    }
 
    // 调启我的小程序
    private void goMiniProgram(){
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = "wxbd6534d10790****"; // 填小程序原始id
        req.path = "pages/index/index"; //拉起小程序页面的可带参路径,不填默认拉起小程序首页
        req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE; //.MINIPTOGRAM_TYPE_RELEASE; // 可选打开 开发版,体验版和正式版
        api.sendReq(req);
    }
 
    [@Override](/user/Override)
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // 注册到微信
        this.regToWx();
    }
 
    public void clickToWX(View view){
        Log.i(TAG,TAG+"clickToWX");
        Toast.makeText(this, "点击跳转到小程序", Toast.LENGTH_LONG).show();
        this.goMiniProgram();
    }
 
    [@Override](/user/Override)
    protected void onDestroy() {
        super.onDestroy();
 
        Log.i(TAG,TAG+"onDestroy***********************************************");
        if(broadcastReceiver!= null){
            unregisterReceiver(broadcastReceiver);
        }
 
    }
}

我这边解决了 appid用错了

Android端应该用应用appid而不是小程序appid来WXAPIFactory.createWXAPI(context, appId, false); 

但是ios端只需要小程序原始id 这两个appid(应用appid和小程序appid)都不需要用到

但是什么错误提示都没有!!!就提示一个“跳转失败”!!!

这点设计的真的太次了!!!

回到顶部