smtp 合并到 MS 中
添加好友 取好友列表 略有修改 接下再来 要该包类型宏 备份一下
This commit is contained in:
@@ -14,9 +14,11 @@ include_directories(${CMAKE_SOURCE_DIR}/include/rapidjson)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++/mysql)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/smtp)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MDB/imm_mysqldb)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MP)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MS/works)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MS/smtp)
|
||||
message("CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/include/libevent")
|
||||
|
||||
link_directories(${CMAKE_SOURCE_DIR}/lib/libevent)
|
||||
|
||||
@@ -28,6 +28,7 @@ mapping::mapping() {
|
||||
// 用户添加好友群组类操作
|
||||
auto improve = new IMProveController();
|
||||
map.insert({mp::MP_REQUEST_IM_ADD, improve});
|
||||
map.insert({mp::MP_REQUEST_USER_FRIENDS, improve});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
207
MS/smtp/send_email.h
Normal file
207
MS/smtp/send_email.h
Normal file
@@ -0,0 +1,207 @@
|
||||
//
|
||||
// Created by dongl on 23-5-10.
|
||||
//
|
||||
|
||||
#ifndef IM2_SEND_EMAIL_H
|
||||
#define IM2_SEND_EMAIL_H
|
||||
|
||||
#include <string>
|
||||
#include "smtp.h"
|
||||
|
||||
#define DOMAIN "smtp.163.com" //smtp服务器域名
|
||||
#define PORT 25 //smtp服务器域名
|
||||
#define DEF_SEND_EMAIL "imbaseemail@163.com" //发件人的邮箱地址
|
||||
#define DEF_SEND_EMAIL_PASS "XIALXUWEOCDPIYAC" //发件人密码
|
||||
|
||||
#define CODE_HTML_TEMPLATE(code) get_code_template(code)
|
||||
|
||||
std::string get_code_template(const std::string& code);
|
||||
|
||||
bool send_email_def(const std::string& target_email, const std::string& code) {
|
||||
Jxiepc::Smtp smtp(
|
||||
PORT, //服务器端口(默认25)
|
||||
DOMAIN, //smtp服务器域名
|
||||
DEF_SEND_EMAIL, //发件人的邮箱地址
|
||||
DEF_SEND_EMAIL_PASS, //发件人密码
|
||||
target_email, //收件人
|
||||
code + " 是你的IM验证码", //主题
|
||||
CODE_HTML_TEMPLATE(code), //内容
|
||||
"html"
|
||||
);
|
||||
return smtp.getRet();
|
||||
}
|
||||
|
||||
bool send_email_def(const std::string& send_email, const std::string& password, const std::string& target_email, const std::string& code) {
|
||||
Jxiepc::Smtp smtp(
|
||||
PORT, //服务器端口(默认25)
|
||||
DOMAIN, //smtp服务器域名
|
||||
send_email, //发件人的邮箱地址
|
||||
password, //发件人密码
|
||||
target_email, //收件人
|
||||
code + " 是你的IM验证码", //主题
|
||||
CODE_HTML_TEMPLATE(code), //内容
|
||||
"html"
|
||||
);
|
||||
return smtp.getRet();
|
||||
}
|
||||
|
||||
|
||||
std::string get_code_template(const std::string& code) {
|
||||
|
||||
std::string emaialcode[code.size()];
|
||||
for (int i = 0; i < code.size(); ++i) {
|
||||
emaialcode[i] = code[i];
|
||||
}
|
||||
|
||||
return "<!DOCTYPE html>\n"
|
||||
"<html lang=\"en\" xmlns:th=\"http://www.thymeleaf.org\">\n"
|
||||
"<head>\n"
|
||||
" <meta charset=\"UTF-8\">\n"
|
||||
" <title>邮箱验证码</title>\n"
|
||||
" <style>\n"
|
||||
" table {\n"
|
||||
" width: 700px;\n"
|
||||
" margin: 0 auto;\n"
|
||||
" }\n"
|
||||
" #top {\n"
|
||||
" width: 700px;\n"
|
||||
" border-bottom: 1px solid #ccc;\n"
|
||||
" margin: 0 auto 30px;\n"
|
||||
" }\n"
|
||||
" #top table {\n"
|
||||
" font: 12px Tahoma, Arial, 宋体;\n"
|
||||
" height: 40px;\n"
|
||||
" }\n"
|
||||
" #content {\n"
|
||||
" width: 680px;\n"
|
||||
" padding: 0 10px;\n"
|
||||
" margin: 0 auto;\n"
|
||||
" }\n"
|
||||
" #content_top {\n"
|
||||
" line-height: 1.5;\n"
|
||||
" font-size: 14px;\n"
|
||||
" margin-bottom: 25px;\n"
|
||||
" color: #4d4d4d;\n"
|
||||
" }\n"
|
||||
" #content_top strong {\n"
|
||||
" display: block;\n"
|
||||
" margin-bottom: 15px;\n"
|
||||
" }\n"
|
||||
" #content_top strong span {\n"
|
||||
" color: #f60;\n"
|
||||
" font-size: 16px;\n"
|
||||
" }\n"
|
||||
" #verificationCode {\n"
|
||||
" color: #f60;\n"
|
||||
" font-size: 24px;\n"
|
||||
" }\n"
|
||||
" #content_bottom {\n"
|
||||
" margin-bottom: 30px;\n"
|
||||
" }\n"
|
||||
" #content_bottom small {\n"
|
||||
" display: block;\n"
|
||||
" margin-bottom: 20px;\n"
|
||||
" font-size: 12px;\n"
|
||||
" color: #747474;\n"
|
||||
" }\n"
|
||||
" #bottom {\n"
|
||||
" width: 700px;\n"
|
||||
" margin: 0 auto;\n"
|
||||
" }\n"
|
||||
" #bottom div {\n"
|
||||
" padding: 10px 10px 0;\n"
|
||||
" border-top: 1px solid #ccc;\n"
|
||||
" color: #747474;\n"
|
||||
" margin-bottom: 20px;\n"
|
||||
" line-height: 1.3em;\n"
|
||||
" font-size: 12px;\n"
|
||||
" }\n"
|
||||
" #content_top strong span {\n"
|
||||
" font-size: 18px;\n"
|
||||
" color: #FE4F70;\n"
|
||||
" }\n"
|
||||
" #sign {\n"
|
||||
" text-align: right;\n"
|
||||
" font-size: 18px;\n"
|
||||
" color: #FE4F70;\n"
|
||||
" font-weight: bold;\n"
|
||||
" }\n"
|
||||
" #verificationCode {\n"
|
||||
" height: 100px;\n"
|
||||
" width: 680px;\n"
|
||||
" text-align: center;\n"
|
||||
" margin: 30px 0;\n"
|
||||
" }\n"
|
||||
" #verificationCode div {\n"
|
||||
" height: 100px;\n"
|
||||
" width: 680px;\n"
|
||||
" }\n"
|
||||
" .button {\n"
|
||||
" color: #FE4F70;\n"
|
||||
" margin-left: 10px;\n"
|
||||
" height: 80px;\n"
|
||||
" width: 80px;\n"
|
||||
" resize: none;\n"
|
||||
" font-size: 42px;\n"
|
||||
" border: none;\n"
|
||||
" outline: none;\n"
|
||||
" padding: 10px 15px;\n"
|
||||
" background: #ededed;\n"
|
||||
" text-align: center;\n"
|
||||
" border-radius: 17px;\n"
|
||||
" box-shadow: 6px 6px 12px #cccccc,\n"
|
||||
" -6px -6px 12px #ffffff;\n"
|
||||
" }\n"
|
||||
" .button:hover {\n"
|
||||
" box-shadow: inset 6px 6px 4px #d1d1d1,\n"
|
||||
" inset -6px -6px 4px #ffffff;\n"
|
||||
" }\n"
|
||||
" </style>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"<table>\n"
|
||||
" <tbody>\n"
|
||||
" <tr>\n"
|
||||
" <td>\n"
|
||||
" <div id=\"top\">\n"
|
||||
" <table>\n"
|
||||
" <tbody><tr><td></td></tr></tbody>\n"
|
||||
" </table>\n"
|
||||
" </div>\n"
|
||||
" <div id=\"content\">\n"
|
||||
" <div id=\"content_top\">\n"
|
||||
" <strong>尊敬的用户:您好!</strong>\n"
|
||||
" <strong>\n"
|
||||
" 您正在进行<span>注册账号</span>操作,请在验证码中输入以下验证码完成操作:\n"
|
||||
" </strong>\n"
|
||||
" <div id=\"verificationCode\">\n"
|
||||
" <button class=\"button\">"+emaialcode[0]+"</button>\n"
|
||||
" <button class=\"button\">"+emaialcode[1]+"</button>\n"
|
||||
" <button class=\"button\">"+emaialcode[2]+"</button>\n"
|
||||
" <button class=\"button\">"+emaialcode[3]+"</button>\n"
|
||||
" <button class=\"button\">"+emaialcode[4]+"</button>\n"
|
||||
" <button class=\"button\">"+emaialcode[5]+"</button>\n"
|
||||
" </div>\n"
|
||||
" </div>\n"
|
||||
" <div id=\"content_bottom\">\n"
|
||||
" <small>\n"
|
||||
" 注意:此操作可能会修改您的密码、登录邮箱或绑定手机。如非本人操作,请及时登录并修改密码以保证帐户安全\n"
|
||||
" <br>(工作人员不会向你索取此验证码,请勿泄漏!)\n"
|
||||
" </small>\n"
|
||||
" </div>\n"
|
||||
" </div>\n"
|
||||
" <div id=\"bottom\">\n"
|
||||
" <div>\n"
|
||||
" <p>此为系统邮件,请勿回复<br>\n"
|
||||
" 请保管好您的邮箱,避免账号被他人盗用\n"
|
||||
" </p>\n"
|
||||
" <p id=\"sign\">——IM Base Email</p>\n"
|
||||
" </div>\n"
|
||||
" </div>\n"
|
||||
" </td>\n"
|
||||
" </tr>\n"
|
||||
" </tbody>\n"
|
||||
"</table>\n"
|
||||
"</body>\n";
|
||||
}
|
||||
#endif //IM2_SEND_EMAIL_H
|
||||
60
MS/smtp/smtp.h
Normal file
60
MS/smtp/smtp.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef __JXIEPC_SMTP_H__
|
||||
#define __JXIEPC_SMTP_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unistd.h>
|
||||
#include <cerrno>
|
||||
#include <utility>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace Jxiepc {
|
||||
|
||||
class Smtp {
|
||||
|
||||
public:
|
||||
Smtp(int port, std::string domain, std::string user, std::string pwd,
|
||||
std::string t_mail, std::string title, std::string content, std::string type);
|
||||
~Smtp();
|
||||
|
||||
int init();
|
||||
int make_connect();
|
||||
|
||||
bool getRet() const;
|
||||
|
||||
private:
|
||||
void Connect(int fd, const struct sockaddr *sa, socklen_t salen);
|
||||
int Socket(int family, int type, int protocol);
|
||||
ssize_t Send(const std::string& str);
|
||||
ssize_t Recv();
|
||||
|
||||
static std::string enBase64(const std::string& src);
|
||||
private:
|
||||
int m_port;
|
||||
int m_sockfd;
|
||||
std::string m_domain;
|
||||
std::string m_user;
|
||||
std::string m_password;
|
||||
std::string m_tmail;
|
||||
std::string m_title;
|
||||
std::string m_content;
|
||||
std::string m_type;
|
||||
char m_buf[0xFFF];
|
||||
|
||||
int ret;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
#include "IMProveController.h"
|
||||
|
||||
void IMProveController::run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) {
|
||||
auto sri = service.imProve(&request->m_body);
|
||||
response->set(sri, request->m_bev);
|
||||
// 添加好友
|
||||
if (request->m_mph->mp_type() == mp::MP_REQUEST_IM_ADD) {
|
||||
auto sri = service.addFriendImProve(&request->m_body);
|
||||
response->set(sri, request->m_bev);
|
||||
}
|
||||
// 取用户好友列表
|
||||
else if(request->m_mph->mp_type() == mp::MP_REQUEST_USER_FRIENDS) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ std::tuple<bool, PoUser> UserDB::select_user(uint64_t account, const std::string
|
||||
query.storein(user);
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return {!user.empty(), user.empty() ? PoUser() :
|
||||
PoUser(user[0].account,
|
||||
user[0].phone, user[0].email,
|
||||
@@ -45,7 +45,7 @@ bool UserDB::insert_user(uint64_t account, const std::string &password, const st
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ bool UserDB::insert_user_friends(uint64_t account, uint64_t friends) {
|
||||
auto ret = q.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ bool UserDB::remove_user(uint64_t account) {
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ bool UserDB::test(uint64_t account) {
|
||||
auto ret = q.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ std::optional<uint64_t> UserDB::fetch_account() {
|
||||
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return std::strtol(ret[0][0], nullptr,0);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ bool UserDB::remove_pool_account(uint64_t account) {
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ bool UserDB::bind_email(uint64_t account, const std::string &email) {
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ bool UserDB::bind_phone(uint64_t account, const std::string &phone) {
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ char UserFriendsDB::select_add_type(uint64_t account) {
|
||||
auto ret = query.store(account)[0][0][0]; // 因为 account 唯一 所以结果 至多一个
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -24,23 +24,34 @@ char UserFriendsDB::select_add_type(uint64_t account) {
|
||||
/// friends :{
|
||||
/// uid :info { }
|
||||
/// }
|
||||
bool UserFriendsDB::add_friends(uint64_t account, uint64_t friends) {
|
||||
std::tuple<bool, std::string> UserFriendsDB::add_friends(uint64_t account, uint64_t friends) {
|
||||
conn = LinkDB::safe_grab();
|
||||
auto query = conn->query("update im_user_friends set friends="
|
||||
auto q = conn->query("select username from im_user where account=%1:account");
|
||||
q.template_defaults[1] = friends;
|
||||
q.parse();
|
||||
auto username = q.store();
|
||||
if (username.num_rows() < 1) {
|
||||
LinkDB::release(conn);
|
||||
return {false, "未查询到账户"};
|
||||
}
|
||||
std::string name = username[0][0].c_str();
|
||||
|
||||
auto query = conn->query("update im_user_friends set friends ="
|
||||
"JSON_SET(friends, '$.\"%2:friends\"', "
|
||||
"JSON_OBJECT('belong_grouping', 1, 'add_time', 10000, 'add_source', 1)"
|
||||
"JSON_OBJECT('username', '%3:username', 'belong_grouping', 1, 'add_time', 10000, 'add_source', 1)"
|
||||
")"
|
||||
"where account=%1:account");
|
||||
|
||||
query.template_defaults[1] = account;
|
||||
query.template_defaults[2] = friends;
|
||||
query.template_defaults[3] = name.c_str();
|
||||
query.parse();
|
||||
|
||||
auto ret = query.exec();
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
return ret;
|
||||
LinkDB::release(conn);
|
||||
return {ret, "添加失败"};
|
||||
}
|
||||
|
||||
void UserFriendsDB::insert_friends_to_be_added(uint64_t account, uint64_t friends) {
|
||||
@@ -48,10 +59,10 @@ void UserFriendsDB::insert_friends_to_be_added(uint64_t account, uint64_t friend
|
||||
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
}
|
||||
|
||||
std::optional<rapidjson::Document> UserFriendsDB::select_friends_all(uint64_t account) {
|
||||
std::optional<std::string> UserFriendsDB::select_friends_all(uint64_t account) {
|
||||
conn = LinkDB::safe_grab();
|
||||
auto q = conn->query("select friends from im_user_friends where account=%0:account");
|
||||
q.parse();
|
||||
@@ -64,14 +75,28 @@ std::optional<rapidjson::Document> UserFriendsDB::select_friends_all(uint64_t ac
|
||||
std::string friends;
|
||||
ret[0][0].to_string(friends);
|
||||
|
||||
rapidjson::Document document;
|
||||
document.Parse(friends.c_str());
|
||||
// for (auto mem = document.MemberBegin(); mem != document.MemberEnd(); ++mem) {
|
||||
// mem->name;
|
||||
// }
|
||||
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
return document;
|
||||
LinkDB::release(conn);
|
||||
return friends;
|
||||
}
|
||||
|
||||
std::optional<rapidjson::Document> UserFriendsDB::select_friends_all_json(uint64_t account) {
|
||||
auto temp = select_friends_all(account);
|
||||
rapidjson::Document document;
|
||||
if (temp.has_value()) {
|
||||
document.Parse(temp.value().c_str());
|
||||
return document;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::optional<rapidjson::Document>
|
||||
UserFriendsDB::select_friends_info(uint64_t account, uint64_t friends) {
|
||||
conn = LinkDB::safe_grab();
|
||||
@@ -101,7 +126,7 @@ UserFriendsDB::select_friends_info(uint64_t account, uint64_t friends) {
|
||||
|
||||
|
||||
// 放回链接
|
||||
// LinkDB::release(conn);
|
||||
LinkDB::release(conn);
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -114,3 +139,4 @@ UserFriendsDB::select_friends_info(uint64_t account, uint64_t friends) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +14,16 @@
|
||||
|
||||
class UserFriendsDB : public DB {
|
||||
public:
|
||||
// 查询添加类型
|
||||
char select_add_type(uint64_t account);
|
||||
bool add_friends(uint64_t source, uint64_t target);
|
||||
std::optional<rapidjson::Document> select_friends_all(uint64_t account);
|
||||
// 添加好友
|
||||
std::tuple<bool, std::string> add_friends(uint64_t source, uint64_t target);
|
||||
// 查询全部好友 好友列表
|
||||
std::optional<std::string> select_friends_all(uint64_t account);
|
||||
std::optional<rapidjson::Document> select_friends_all_json(uint64_t account);
|
||||
// 查询好友信息
|
||||
std::optional<rapidjson::Document> select_friends_info(uint64_t account, uint64_t friends);
|
||||
// 添加待审核好友列表
|
||||
void insert_friends_to_be_added(uint64_t account, uint64_t friends);
|
||||
};
|
||||
|
||||
|
||||
@@ -14,21 +14,23 @@ LinkDB::~LinkDB() {
|
||||
ConnectionPool* LinkDB::pool = nullptr;
|
||||
|
||||
mysqlpp::Connection* LinkDB::safe_grab() {
|
||||
static std::vector<mysqlpp::Connection*> link;
|
||||
static std::atomic<int> index;
|
||||
// static std::vector<mysqlpp::Connection*> link;
|
||||
|
||||
// static std::atomic<int> index;
|
||||
if (pool == nullptr) {
|
||||
pool = new ConnectionPool("124.221.152.192", "ims", "IMS", "WimTFC8N58kznx2k");
|
||||
index = -1;
|
||||
for (int i = 0; i < 30; ++i) {
|
||||
link.push_back(pool->safe_grab());
|
||||
}
|
||||
// index = -1;
|
||||
// for (int i = 0; i < 30; ++i) {
|
||||
// link.push_back(pool->safe_grab());
|
||||
// }
|
||||
}
|
||||
|
||||
++index;
|
||||
if (index >= link.size()) {
|
||||
index = 0;
|
||||
}
|
||||
return link[index];
|
||||
// ++index;
|
||||
// if (index >= link.size()) {
|
||||
// index = 0;
|
||||
// }
|
||||
// return link[index];
|
||||
return pool->safe_grab();
|
||||
}
|
||||
|
||||
void LinkDB::release(mysqlpp::Connection *connection) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <mysql++/connection.h>
|
||||
#include "proto/mp.sri.pb.h"
|
||||
#include "db/UserDB.h"
|
||||
#include "document.h"
|
||||
|
||||
class Service {
|
||||
public:
|
||||
@@ -29,6 +30,14 @@ protected:
|
||||
sri->clear_sri_token();
|
||||
sri->clear_sri_username();
|
||||
}
|
||||
|
||||
|
||||
std::string SerializationVector(rapidjson::Document* document) {
|
||||
uint64_t account;
|
||||
for (auto mem = document->MemberBegin(); mem != document->MemberEnd(); ++mem) {
|
||||
mem->name;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //IM2_SERVICE_H
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
UserFriendsService::~UserFriendsService() {}
|
||||
|
||||
// 好友群组 添加删除 任务组 决策接口
|
||||
mp::sri *UserFriendsService::imProve(mp::body* body) {
|
||||
mp::sri *UserFriendsService::addFriendImProve(mp::body* body) {
|
||||
sri_clear();
|
||||
if (body->target() == 0 || body->source() == 0) {
|
||||
printf("请求数据有缺\n");
|
||||
@@ -34,8 +34,8 @@ mp::sri *UserFriendsService::imProve(mp::body* body) {
|
||||
}
|
||||
|
||||
void UserFriendsService::add_friends(mp::body *body) {
|
||||
bool state1 = userFriendsDb.add_friends(body->source(), body->target());
|
||||
bool state2 = userFriendsDb.add_friends(body->target(), body->source());
|
||||
auto [state1, msg1] = userFriendsDb.add_friends(body->source(), body->target());
|
||||
auto [state2, msg2] = userFriendsDb.add_friends(body->target(), body->source());
|
||||
if (state1 && state2) {
|
||||
sri->set_sri_code((mp::MP_SRI)(mp::MP_ADD_FRIENDS | mp::MP_ADD_FRIENDS_0));
|
||||
sri->set_sri_msg("添加成功");
|
||||
@@ -71,6 +71,23 @@ mp::sri* UserFriendsService::add_contact_person(mp::body *body) {
|
||||
return sri;
|
||||
}
|
||||
|
||||
mp::sri *UserFriendsService::FetchUserFriend(uint64_t account, const std::string &data) {
|
||||
sri_clear();
|
||||
uint8_t page_begin = data.c_str()[0];
|
||||
uint8_t page_end = data.c_str()[1];
|
||||
|
||||
auto friends = userFriendsDb.select_friends_all(account);
|
||||
if (friends.has_value())
|
||||
sri->set_data(friends.value());
|
||||
sri->set_sri_msg("好友获取成功");
|
||||
sri->set_sri_code(mp::);
|
||||
|
||||
return sri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ public:
|
||||
|
||||
public:
|
||||
// 唯一对开接口
|
||||
mp::sri* imProve(mp::body* body);
|
||||
mp::sri* addFriendImProve(mp::body* body);
|
||||
mp::sri* FetchUserFriend(uint64_t account, const std::string& data);
|
||||
|
||||
private:
|
||||
mp::sri* add_contact_person(mp::body* body);
|
||||
|
||||
@@ -58,7 +58,6 @@ void UserService::login_fun(const std::string& account, const std::string& passw
|
||||
printf("登陆失败\n");
|
||||
sri->set_sri_msg("登陆失败!");
|
||||
sri->set_sri_code(mp::MP_LOGIN_FAIL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,14 +96,12 @@ mp::sri *UserService::register_(mp::MP_SUB_TYPE subType, const std::string &phon
|
||||
if (subType == mp::MP_REQUEST_REGISTER_EMAIL) {
|
||||
// 将邮箱绑定到帐号上
|
||||
state1 = userDb.bind_email(account.value(), phone_email);
|
||||
sri->set_sri_email(phone_email);
|
||||
sri->set_sri_code(mp::MP_REGISTER_SUCCESS_EMAIL);
|
||||
}
|
||||
// 手机号方式
|
||||
else {
|
||||
// 将手机绑定到帐号上
|
||||
state1 = userDb.bind_phone(account.value(), phone_email);
|
||||
sri->set_sri_phone(strtol(phone_email.c_str(), nullptr, 0));
|
||||
sri->set_sri_code(mp::MP_REGISTER_SUCCESS_PHONE);
|
||||
}
|
||||
|
||||
@@ -115,6 +112,8 @@ mp::sri *UserService::register_(mp::MP_SUB_TYPE subType, const std::string &phon
|
||||
// 注册成功就将取出的号在号池内删除
|
||||
userDb.remove_pool_account(account.value());
|
||||
}
|
||||
|
||||
sri->set_sri_account(account.value());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user