增加微信邀请码功能 升级到one-api最新版代码 0.5.4版本

This commit is contained in:
thinker007 2023-09-15 04:48:21 +08:00
parent dd8cc364fe
commit 7b60ccb9ba
5 changed files with 28 additions and 5 deletions

View File

@ -1 +1 @@
v0.5.2
v0.5.4

View File

@ -84,8 +84,16 @@ func WeChatAuth(c *gin.Context) {
user.DisplayName = "WeChat User"
user.Role = common.RoleCommonUser
user.Status = common.UserStatusEnabled
if err := user.Insert(0); err != nil {
// 开始处理邀请码逻辑 类似 https://aiapi2d.com/login?aff=XqgY 带邀请码的链接,按照邀请码寻找邀请者。
affCode := c.Query("affCode") // this code is the inviter's code, not the user's own code
inviterId := 0
if affCode == "" {
} else {
inviterId, _ = model.GetUserIdByAffCode(affCode)
}
user.InviterId = inviterId
if err := user.Insert(inviterId); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),

BIN
one-api

Binary file not shown.

BIN
one-api.old Executable file

Binary file not shown.

View File

@ -18,7 +18,10 @@ const LoginForm = () => {
let navigate = useNavigate();
const [status, setStatus] = useState({});
const logo = getLogo();
let affCode = new URLSearchParams(window.location.search).get('aff');
if (affCode) {
localStorage.setItem('aff', affCode);
}
useEffect(() => {
if (searchParams.get('expired')) {
showError('未登录或登录已过期,请重新登录!');
@ -37,8 +40,20 @@ const LoginForm = () => {
};
const onSubmitWeChatVerificationCode = async () => {
// WeChat 渠道注册也能带上邀请码链接这里检查是否之前打开过邀请码链接通过localStorage存储来寻找
if (!affCode) {
affCode = localStorage.getItem('aff');
}
// 检查 affCode 是否有值
if (affCode) {
// 如果有值,拼接到 URL 中
var url = `/api/oauth/wechat?code=${inputs.wechat_verification_code}&affCode=${affCode}`;
} else {
// 如果没有值不拼接affCode
var url = `/api/oauth/wechat?code=${inputs.wechat_verification_code}`;
}
const res = await API.get(
`/api/oauth/wechat?code=${inputs.wechat_verification_code}`
url
);
const { success, message, data } = res.data;
if (success) {