uni-app 外部系统联登注册用户失败 no_matching_function_for_path /externalRegister

uni-app 外部系统联登注册用户失败 no_matching_function_for_path /externalRegister

我的小程序嵌入uni-im

需要在服务端打通与uni-id的用户系统。当前按照文档 外部系统对接 的步骤进行配置。

调试的报错:

{"success":false,"error":{"code":"InternalBizError","message":"no_matching_function_for_path /uni-id-co/externalRegister"}}

根据文档找不到解决方案。

访问链接是:https://fc-mp-ee363348-a386-41c7-8812-xxxxxxxx.next.bspapp.com/uni-id-co/externalRegister

我在小程序端的 cloudfunctions/common/uni-config-center/uni-id/config.json 文件里已经配置了 "requestAuthSecret": "",即 URL 化请求鉴权签名密钥。

以下是我的 Java 端代码:

// 外部系统联调-注册  
// 小程序端:已经在 cloudfunctions/common/uni-config-center/uni-id/config.json 配置 requestAuthSecret 并上传云空间  
String requestAuthSecret = "qwertyuiop111asdzxcqwertyuiop111asdzxc";  
String url = "https://fc-mp-ee363348-a386-41c7-8812-xxxxxxxx.next.bspapp.com/uni-id-co/externalRegister";  
Map<String, Object> params = new HashMap<>();  
params.put("externalUid", "ab1234");  
params.put("nickname", "测试1");  
params.put("username", "ab1234");  
params.put("avatar", "![图片](https://d187uamsy6q6zw.cloudfront.net/2020/03/27/312bbb3f-7231-4083-8ed4-d941e814e3cd.jpg)");  
params.put("gender", 0);  

Map<String, String> info = new HashMap<>();  
info.put("uniPlatform", "web");  
info.put("appId", "__UNI__A7315951");  

Map<String, Object> data = new HashMap<>();  
data.put("params", params);  
data.put("clientInfo", info);  

String nonce = RandomUtil.randomString(15);  
long timestamp = System.currentTimeMillis();  

Map<String, String> headers = new HashMap<>(3);  
headers.put(UniConstant.HEADER_NONCE, nonce);  
headers.put(UniConstant.HEADER_TIMESTAMP, String.valueOf(timestamp));  

data.put("params", info);  
data.put("uniIdToken", "");  

String signature = UniUtil.getSignature(params, nonce, timestamp, requestAuthSecret);  
headers.put(UniConstant.HEADER_SIGNATURE, signature);  

HttpRequest post = HttpUtil.createPost(url);  
HttpResponse response = post.addHeaders(headers).body(JSONUtil.toJsonStr(data)).execute();  

System.out.println(response.body());  
// 打印的还是 {"success":false,"error":{"code":"InternalBizError","message":"no_matching_function_for_path /uni-id-co/externalRegister"}}

开发环境、版本号、项目创建方式

信息项 描述
开发环境 Java
版本号 未提供
项目创建方式 使用 DCloud 提供的 uni-app 模板创建的小程序

更多关于uni-app 外部系统联登注册用户失败 no_matching_function_for_path /externalRegister的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

uni-id-co 云对象的URL化访问配置了吗

更多关于uni-app 外部系统联登注册用户失败 no_matching_function_for_path /externalRegister的实战教程也可以访问 https://www.itying.com/category-93-b0.html


嗯 没有URL化原因

解决方案记录一下
1.导入如图插件、配置好值 上传云函数 2.在web端口配置路径

然后访问即可

在处理 uni-app 中与外部系统进行联登注册用户时遇到的 no_matching_function_for_path /externalRegister 错误,通常意味着后端服务没有正确配置或处理 /externalRegister 这个路径的请求。这个问题可能涉及到后端API的设计、路由配置或者权限验证等多个方面。以下是一个基于 Express 框架的Node.js后端示例代码,展示了如何设置一个处理外部注册请求的API端点。

首先,确保你已经安装了 express 和相关的中间件(如 body-parser 用于解析请求体):

npm install express body-parser

然后,创建一个简单的Express服务器来处理 /externalRegister 请求:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;

// 使用body-parser中间件解析JSON请求体
app.use(bodyParser.json());

// 假设有一个用户服务来处理注册逻辑
const userService = {
    register: async (userData) => {
        // 这里应该是实际的注册逻辑,比如数据库操作
        console.log('Registering user:', userData);
        // 假设注册成功,返回一个模拟的响应
        return { success: true, message: 'User registered successfully!' };
    }
};

// 处理/externalRegister POST请求
app.post('/externalRegister', async (req, res) => {
    try {
        const userData = req.body; // 获取请求体中的用户数据
        const response = await userService.register(userData); // 调用注册服务
        res.status(200).json(response); // 返回注册结果
    } catch (error) {
        console.error('Error registering user:', error);
        res.status(500).json({ success: false, message: 'Internal server error' });
    }
});

// 启动服务器
app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});

确保你的前端 uni-app 发送的注册请求是针对正确的URL(在这个例子中是 http://localhost:3000/externalRegister),并且请求方法是 POST,请求体中包含正确的用户数据。

如果后端服务器部署在不同的域或需要跨域请求,你可能还需要配置CORS(跨源资源共享):

const cors = require('cors');
app.use(cors());

以上代码提供了一个基本的后端处理框架,用于响应 /externalRegister 请求。根据你的具体业务逻辑,你可能需要调整 userService.register 方法中的实现细节。如果问题仍然存在,建议检查网络请求是否正确发出,以及后端服务器是否正确接收到请求并进行了处理。

回到顶部