我认为你必须建立一个后端服务。一种方法可能是用Node JS构建一个Rest Api。你可以定义像邀请用户这样的路线,它需要一个用户ID和组ID。在路由功能中,您可以将组ID添加到用户ID后面的用户的邀请中。其他路线可以是接受邀请,您可以在其中发送用户ID和组ID。在该功能中,您检查用户是否有该组的邀请,以及他是否将他添加到组中。但这只是近千种可能方式的建议。你也可以在你的应用程序中添加这些功能。而不是使用我上面提到的API函数作为API路径,直接让它们在应用程序中。但是,如果数据库中存在新的邀请记录,那么您必须通知用户可能使用推送通知。但我会建议建立一个小服务器。
可以看看这里一个基本的休息mSQL的节点JS教程https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/你会在这里这样定义
function inviteUser(req,res) {
pool.getConnection(function(err,connection){
if (err) {
connection.release();
res.json({"code" : 100, "status" : "Error in connection database"});
return;
}
console.log('connected as id ' + connection.threadId);
connection.query("select req.body.userId from user",function(err,rows){
connection.release();
if(!err) {
//ADD Group id to the user access the id with req.body.groupId
res.json(rows);
}
});
connection.on('error', function(err) {
res.json({"code" : 100, "status" : "Error in connection database"});
return;
});
});
}
function acceptInvitation(req,res){
pool.getConnection(function(err,connection){
if (err) {
connection.release();
res.json({"code" : 100, "status" : "Error in connection database"});
return;
}
console.log('connected as id ' + connection.threadId);
connection.query("select req.body.groupId from groups",function(err,rows){
connection.release();
if(!err) {
//ADD user id to the group access the id with req.body.userId
res.json(rows);
}
});
connection.on('error', function(err) {
res.json({"code" : 100, "status" : "Error in connection database"});
return;
});
});
}
}
app.get("https://stackoverflow.com/users/invite",function(req,res){-
inviteUser(req,res);
});
app.get("https://stackoverflow.com/users/accept",function(req,res){-
acceptInvitation(req,res);
});
路线从应用程序,你会在你的服务器的URL发送HTTP请求像http://localhost:8080/users/invite与{用户id的身体: xxxxx,groupId:xxxxx}
我很感谢你的回答,它给了我一些研究。我一直在研究一两天,而不是提出任何看起来可行的事情。 –
我加了一些提示可能会帮助你,对不起我的英文不好 – Sprotte
不用担心我很欣赏帮助 –