收藏
回答

wxlog:Error:set token fail, errCode:4, errLog:wx t

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小程序 Bug iOS iOS14.1 iPhone SE 7.0.18

使用微信SDK授权登录时, 在调试日志看到报错wxlog:Error:set token fail, errCode:4, errLog:wx token[] or contextId[(null). 界面上是跳转到微信后立马返回到自己的界面, Universal Links

是校验通过了的, 当写入错误的Universal Link时会直接报通用链接错误的提示框, 可以排除Universal Link的问题, Universal Link我复制到备忘录里长按能跳转到我自己的APP, 用Safari浏览器也是有应用打开标识. 这个问题卡了我四天, 试过百度出来的方法, 也试过了这个问题在微信开放社区的解决方法, 都没能解决. 目前在在手机微信那里上传下日志, 上传了日志, 微信号HB520XQ1314,上传时间点是2020-11-23 16:30-16:45.很着急, 希望能尽快处理!

static NSString *WXappId = @"wxdf7dfa46f3877319"; static NSString *WXappLink = @"https://duupie.meibbc.com/app/link/"; @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = [[ViewController alloc] init];; [self.window makeKeyAndVisible]; [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) { NSLog(@"WeChatSDK: %@", log); }]; [WXApi registerApp:WXappId universalLink:WXappLink]; //调用自检函数 [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) { NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion); }]; //检测报错->wxlog:Error:set token fail, errCode:4, errLog:wx token[] or contextId[(null)] is nil! return YES; } - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler { return [WXApi handleOpenUniversalLink:userActivity delegate:self]; } - (void)onReq:(BaseReq *)req { } - (void)onResp:(BaseResp *)resp { } //检查微信是否已被用户安装 if ([WXApi isWXAppInstalled]) { //获取到code SendAuthReq* req = [[SendAuthReq alloc] init]; req.scope = @"snsapi_userinfo"; req.state = @"WeChatLogin"; req.openID = @"wxdf7dfa46f3877319"; //第三方向微信终端发送一个SendAuthReq消息结构 if (![WXApi isWXAppInstalled]) { UIWindow *w = [[UIApplication sharedApplication].windows firstObject]; UINavigationController *nav = (UINavigationController *) w.rootViewController; // [WXApi sendAuthReq:req viewController:self delegate:self completion:nil]; } else { [WXApi sendReq:req completion:nil]; } }
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签