作者 tangxvhui
... ... @@ -33,12 +33,17 @@ func main() {
// 服务初始化
opts := make([]rest.RunOption, 0)
opt := rest.WithCustomCors(func(header http.Header) {
opts = append(opts, rest.WithCustomCors(func(header http.Header) {
header.Set("Access-Control-Allow-Headers", "*")
}, func(writer http.ResponseWriter) {
})
opts = append(opts, opt)
}))
opts = append(opts, rest.WithUnauthorizedCallback(func(w http.ResponseWriter, r *http.Request, err error) {
if err != nil {
logx.Debugf("unauthorized: %s \n", err.Error())
}
}))
server := rest.MustNewServer(c.RestConf, opts...)
defer server.Stop()
ctx := svc.NewServiceContext(c)
... ... @@ -73,6 +78,7 @@ func systemSetup(c config.Config) {
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
})
// 系统成功应答包装
httpx.SetOkHandler(func(ctx context.Context, a any) any {
return result.Success(a)
... ...
... ... @@ -15,6 +15,7 @@ type Config struct {
MiniAuth config.Auth
Migrate bool `json:",optional,default=true"`
ApiAuth ApiService
DebugSmsCode string `json:",optional,default=999512"`
}
type ApiService struct {
... ...
... ... @@ -32,7 +32,9 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("type", msgType))
WithKV("type", msgType).
WithKV("companyId", userToken.CompanyId).
WithKV("recipientId", userToken.UserId))
if err != nil {
return nil, err
}
... ...
... ... @@ -121,8 +121,12 @@ func (c WxClientLogin) PhoneSmsCodeLogin(phone string, code string) (*domain.Log
var (
users []*domain.User
err error
skipCheckSmsCode bool = false
)
if _, err = c.l.svcCtx.SmsService.CheckSmsCode(c.l.ctx, smslib.RequestCheckSmsCode{Phone: phone, Code: code}); err != nil {
if c.l.svcCtx.Config.DebugSmsCode != "" && c.l.svcCtx.Config.DebugSmsCode == code {
skipCheckSmsCode = true
}
if _, err = c.l.svcCtx.SmsService.CheckSmsCode(c.l.ctx, smslib.RequestCheckSmsCode{Phone: phone, Code: code}); err != nil && !skipCheckSmsCode {
return nil, xerr.NewErrMsgErr(err.Error(), err)
}
conn := c.l.svcCtx.DefaultDBConn()
... ...
-- 用户表
-- (公司ID)索引
CREATE INDEX IF NOT EXISTS idx_user_company_id ON "public"."user" USING btree(company_id);
-- (手机号)索引
CREATE INDEX IF NOT EXISTS idx_user_phone ON "public"."user" USING btree(phone);
-- 用户关注表
-- (发起人)索引
CREATE INDEX IF NOT EXISTS idx_user_follow_from_user_id on "public".user_follow USING btree(from_user_id);
-- 角色表
-- (公司ID)索引
CREATE INDEX IF NOT EXISTS idx_role_company_id ON "public"."role" USING btree(company_id);
\ No newline at end of file
... ...