service/app/mix/controller/init.go

561 lines
40 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package controller
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
imageaudittaskproto "service/api/proto/imageaudittask/proto"
mediaproto "service/api/proto/media/proto"
"service/library/logger"
"service/library/middleware"
"time"
"github.com/gorilla/websocket"
"github.com/gin-gonic/gin"
"service/api/base"
"service/api/consts"
"service/api/errcode"
accountproto "service/api/proto/account/proto"
accountrelationproto "service/api/proto/accountrelation/proto"
2024-02-01 09:52:45 +08:00
appconfigproto "service/api/proto/app_config/proto"
2023-12-21 22:17:40 +08:00
callhistoryproto "service/api/proto/callhistory/proto"
contact_customer_serviceproto "service/api/proto/contact_customer_service/proto"
2023-12-23 22:03:53 +08:00
contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto"
daily_statementproto "service/api/proto/daily_statement/proto"
2023-12-21 22:17:40 +08:00
feedbackproto "service/api/proto/feedback/proto"
footprintproto "service/api/proto/footprint/proto"
loginproto "service/api/proto/login/proto"
momentproto "service/api/proto/moment/proto"
productproto "service/api/proto/product/proto"
realname_authenticationproto "service/api/proto/realname_authentication/proto"
streamerproto "service/api/proto/streamer/proto"
streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto"
streamerlinkproto "service/api/proto/streamerlink/proto"
textaudittaskproto "service/api/proto/textaudittask/proto"
thumbsupproto "service/api/proto/thumbsup/proto"
userwxaddcheckproto "service/api/proto/userwxaddcheck/proto"
vasproto "service/api/proto/vas/proto"
vericodeproto "service/api/proto/vericode/proto"
)
func Init(r *gin.Engine) {
r.HandleMethodNotAllowed = true
// websocket长链接
r.GET("/", ServeFile)
r.GET("/ws", HandleWs)
// Hello World!
helloWorldGroup := r.Group("/hello_world", Prepare())
//helloWorldGroup.GET("hello_world", HelloWorld)
helloWorldGroup.POST("hello_world", HelloWorld)
// gateway网关给客户端调用
//toCApiGroup := r.Group("/api", PrepareToC())
// 验证码
apiVeriCodeGroup := r.Group("/api/veri_code", PrepareToC())
apiVeriCodeGroup.POST("send", middleware.JSONParamValidator(vericodeproto.ApiSendReq{}), middleware.RequestDecryptor(), ApiSendVeriCode)
// 登录
apiLoginGroup := r.Group("/api/login", PrepareToC())
apiLoginGroup.POST("login_by_pswd", middleware.JSONParamValidator(loginproto.ApiLoginByPswdReq{}), middleware.RequestDecryptor(), ApiLoginByPswd)
apiLoginGroup.POST("login_by_veri_code", middleware.JSONParamValidator(loginproto.ApiLoginByVeriCodeReq{}), middleware.RequestDecryptor(), ApiLoginByVeriCode)
apiLoginGroup.POST("logout", middleware.JSONParamValidator(loginproto.ApiLogoutReq{}), middleware.JwtAuthenticator(), ApiLogout)
apiLoginGroup.POST("set_password", middleware.JSONParamValidator(loginproto.ApiSetPswdReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), ApiSetPassword)
apiLoginGroup.POST("reset_password", middleware.JSONParamValidator(loginproto.ApiResetPswdReq{}), middleware.RequestDecryptor(), ApiResetPassword)
apiLoginGroup.POST("update_password", middleware.JSONParamValidator(loginproto.ApiUpdatePswdReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), ApiUpdatePassword)
apiLoginGroup.POST("validate", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), ApiValidate)
// 账号,用户端支持改、查自己、查别人、经验增长,不支持增删
apiAccountGroup := r.Group("/api/account", PrepareToC())
apiAccountGroup.POST("update", middleware.JSONParamValidator(accountproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), ApiUpdateAccount)
apiAccountGroup.POST("list_by_mid", middleware.JSONParamValidator(accountproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetAccountListByMid)
//apiAccountGroup.POST("list_by_user_id", middleware.JSONParamValidator(accountproto.ApiListByUserIdReq{}), middleware.JwtAuthenticator(), ApiGetAccountListByUserId)
apiAccountGroup.POST("list_others_by_mid", middleware.JSONParamValidator(accountproto.ApiListOthersByMidReq{}), middleware.JwtAuthenticator(), ApiGetAccountListForOthersByMid)
apiAccountGroup.POST("list_others_by_mids", middleware.JSONParamValidator(accountproto.ApiListOthersByMidsReq{}), middleware.JwtAuthenticator(), ApiGetAccountListForOthersByMids)
apiAccountGroup.POST("exp_inc", middleware.JSONParamValidator(accountproto.ApiExpIncReq{}), middleware.JwtAuthenticator(), ApiAccountExpInc)
// 用户关系,用户端支持增删查,不支持改
apiAccountRelationGroup := r.Group("/api/account_relation", PrepareToC())
apiAccountRelationGroup.POST("create", middleware.JSONParamValidator(accountrelationproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateAccountRelation)
//apiAccountRelationGroup.POST("update", middleware.JSONParamValidator(accountrelationproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateAccountRelation)
apiAccountRelationGroup.POST("delete", middleware.JSONParamValidator(accountrelationproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteAccountRelation)
apiAccountRelationGroup.POST("list_follow", middleware.JSONParamValidator(accountrelationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetFollowAccountRelationList)
apiAccountRelationGroup.POST("list_is_followed", middleware.JSONParamValidator(accountrelationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetIsFollowedAccountRelationList)
apiAccountRelationGroup.POST("list_friend", middleware.JSONParamValidator(accountrelationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetFriendAccountRelationList)
apiAccountRelationGroup.POST("list_ignore", middleware.JSONParamValidator(accountrelationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetIgnoreAccountRelationList)
apiAccountRelationGroup.POST("list_able_to_access_weixin_of", middleware.JSONParamValidator(accountrelationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetAbleToAccessWeixinOfAccountRelationList)
apiAccountRelationGroup.POST("list_by_sentence", middleware.JSONParamValidator(accountrelationproto.ApiListBySentenceReq{}), middleware.JwtAuthenticator(), ApiGetAccountRelationBySentence)
apiAccountRelationGroup.POST("count", middleware.JSONParamValidator(accountrelationproto.ApiCountReq{}), middleware.JwtAuthenticator(), ApiGetAccountRelationCount)
2024-01-13 00:32:19 +08:00
// 动态
apiMomentGroup := r.Group("/api/moment", PrepareToC())
apiMomentGroup.POST("create", middleware.JSONParamValidator(momentproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateMoment)
apiMomentGroup.POST("update", middleware.JSONParamValidator(momentproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateMoment)
apiMomentGroup.POST("delete", middleware.JSONParamValidator(momentproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteMoment)
apiMomentGroup.POST("list", middleware.JSONParamValidator(momentproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetMomentList)
apiMomentGroup.POST("list_by_mid", middleware.JSONParamValidator(momentproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetMomentListByMid)
apiMomentGroup.POST("list_by_mids", middleware.JSONParamValidator(momentproto.ApiListByMidsReq{}), middleware.JwtAuthenticator(), ApiGetMomentListByMids)
apiMomentGroup.POST("thumbs_up", middleware.JSONParamValidator(momentproto.ApiThumbsUpReq{}), middleware.JwtAuthenticator(), ApiThumbsUpMoment)
2024-02-01 10:19:44 +08:00
apiMomentGroup.POST("list_by_ids", middleware.JSONParamValidator(momentproto.ApiListByIdsReq{}), middleware.JwtAuthenticator(), ApiGetMomentListByIds)
2024-01-13 00:32:19 +08:00
// 足迹
// apiFootPrintGroup := r.Group("/api/footprint", PrepareToC())
// apiFootPrintGroup.POST("create", middleware.JSONParamValidator(footprintproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateFootPrint)
// apiFootPrintGroup.POST("delete", middleware.JSONParamValidator(footprintproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteFootPrint)
// apiFootPrintGroup.POST("list_view", middleware.JSONParamValidator(footprintproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetViewFootPrintList)
// apiFootPrintGroup.POST("list_is_viewed", middleware.JSONParamValidator(footprintproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetIsViewedFootPrintList)
// apiFootPrintGroup.POST("count", middleware.JSONParamValidator(footprintproto.ApiCountReq{}), middleware.JwtAuthenticator(), ApiGetFootPrintCount)
// 点赞
apiThumbsUpGroup := r.Group("/api/thumbs_up", PrepareToC())
apiThumbsUpGroup.POST("list", middleware.JSONParamValidator(thumbsupproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetThumbsUpList)
2023-12-21 22:17:40 +08:00
// 女神认证审批,用户端支持增删查,不支持改
apiStreamerAuthApprovalGroup := r.Group("/api/streamer_auth_approval", PrepareToC())
apiStreamerAuthApprovalGroup.POST("create", middleware.JSONParamValidator(streamerauthapprovalproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateStreamerAuthApproval)
apiStreamerAuthApprovalGroup.POST("delete", middleware.JSONParamValidator(streamerauthapprovalproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteStreamerAuthApproval)
apiStreamerAuthApprovalGroup.POST("list", middleware.JSONParamValidator(streamerauthapprovalproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetStreamerAuthApprovalList)
// 主播
apiStreamerGroup := r.Group("/api/streamer", PrepareToC())
apiStreamerGroup.POST("update", middleware.JSONParamValidator(streamerproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateStreamer)
apiStreamerGroup.POST("list_by_mid", middleware.JSONParamValidator(streamerproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetStreamerListByMid)
apiStreamerGroup.POST("list_ext_by_mid", middleware.JSONParamValidator(streamerproto.ApiListExtByMidReq{}), middleware.JwtAuthenticator(), ApiGetStreamerExtListByMid)
apiStreamerGroup.POST("list_ext_by_mids", middleware.JSONParamValidator(streamerproto.ApiListExtByMidsReq{}), middleware.JwtAuthenticator(), ApiGetStreamerExtListByMids)
apiStreamerGroup.POST("list_ext_by_user_id", middleware.JSONParamValidator(streamerproto.ApiListExtByUserIdReq{}), ApiGetStreamerExtListByUserId)
apiStreamerGroup.POST("list_ext_fuzzily_by_user_id", middleware.JSONParamValidator(streamerproto.ApiListExtFuzzilyByUserIdReq{}), middleware.JwtAuthenticator(), ApiGetStreamerExtListFuzzilyByUserId)
apiStreamerGroup.POST("list_ext_fuzzily_by_name", middleware.JSONParamValidator(streamerproto.ApiListExtFuzzilyByNameReq{}), middleware.JwtAuthenticator(), ApiGetStreamerExtListFuzzilyByName)
apiStreamerGroup.POST("list_wx_id", middleware.JSONParamValidator(streamerproto.ApiListStreamerWxIdReq{}), middleware.JwtAuthenticator(), ApiGetStreamerWxId)
apiStreamerGroup.POST("recomm_list", middleware.JSONParamValidator(streamerproto.ApiRecommListReq{}), middleware.JwtAuthenticator(), ApiGetStreamerRecommList)
// 意见反馈
apiFeedbackGroup := r.Group("/api/feedback", PrepareToC())
apiFeedbackGroup.POST("create", middleware.JSONParamValidator(feedbackproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateFeedback)
// 主播链接
apiStreamerLinkGroup := r.Group("/api/streamer_link", PrepareToC())
apiStreamerLinkGroup.POST("create", middleware.JSONParamValidator(streamerlinkproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateStreamerLink)
apiStreamerLinkGroup.POST("update", middleware.JSONParamValidator(streamerlinkproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateStreamerLink)
apiStreamerLinkGroup.POST("delete", middleware.JSONParamValidator(streamerlinkproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteStreamerLink)
apiStreamerLinkGroup.POST("list_by_mid", middleware.JSONParamValidator(streamerlinkproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetStreamerLinkListByMid)
apiStreamerLinkGroup.POST("create_batch", middleware.JSONParamValidator(streamerlinkproto.ApiCreateBatchReq{}), middleware.JwtAuthenticator(), ApiCreateBatchStreamerLink)
apiStreamerLinkGroup.POST("delete_batch", middleware.JSONParamValidator(streamerlinkproto.ApiDeleteBatchReq{}), middleware.JwtAuthenticator(), ApiDeleteBatchStreamerLink)
// 用户微信添加审核
apiUserWxAddCheckGroup := r.Group("/api/user_wx_add_check", PrepareToC())
apiUserWxAddCheckGroup.POST("create", middleware.JSONParamValidator(userwxaddcheckproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateUserWxAddCheck)
apiUserWxAddCheckGroup.POST("update", middleware.JSONParamValidator(userwxaddcheckproto.ApiUpdateReq{}), middleware.JwtAuthenticator(), ApiUpdateUserWxAddCheck)
apiUserWxAddCheckGroup.POST("delete", middleware.JSONParamValidator(userwxaddcheckproto.ApiDeleteReq{}), middleware.JwtAuthenticator(), ApiDeleteUserWxAddCheck)
//todo : list
apiUserWxAddCheckGroup.POST("list", middleware.JSONParamValidator(userwxaddcheckproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetUserWxAddCheckList)
// 实名认证
apiRealNameAuthenticationGroup := r.Group("/api/realname_authentication", PrepareToC())
2024-01-10 22:01:16 +08:00
apiRealNameAuthenticationGroup.POST("create", middleware.JSONParamValidator(realname_authenticationproto.ApiCreateReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), ApiCreateRealNameAuthentication)
2023-12-21 22:17:40 +08:00
apiRealNameAuthenticationGroup.POST("list_by_mid", middleware.JSONParamValidator(realname_authenticationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetRealNameAuthenticationList)
// 联系客服
apiContactCustomerServiceGroup := r.Group("/api/contact_customer_service", PrepareToC())
2024-01-10 22:01:16 +08:00
apiContactCustomerServiceGroup.POST("create", middleware.JSONParamValidator(contact_customer_serviceproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateContactCustomerService)
apiContactCustomerServiceGroup.POST("list_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.ApiListBySessionIdReq{}), middleware.JwtAuthenticator(), ApiGetContactCustomerServiceListBySessionId)
2023-12-23 22:03:53 +08:00
// 联系客服对话表
apiContactCustomerServiceSessionGroup := r.Group("/api/contact_customer_service_session", PrepareToC())
2024-01-10 22:01:16 +08:00
apiContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateContactCustomerServiceSession)
apiContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetContactCustomerServiceSessionListByMid)
2023-12-21 22:17:40 +08:00
2024-02-01 09:52:45 +08:00
// 应用配置表
apiAppConfigGroup := r.Group("/api/app_config", PrepareToC())
apiAppConfigGroup.POST("list_by_key", middleware.JSONParamValidator(appconfigproto.ApiListByKeyReq{}), middleware.JwtAuthenticator(), ApiGetAppConfigListByKey)
2023-12-21 22:17:40 +08:00
// 主播标签
2023-12-24 15:53:20 +08:00
apiStreamerTagGroup := r.Group("/api/streamer_tag", PrepareToC())
2023-12-21 22:17:40 +08:00
apiStreamerTagGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetStreamerTagList)
// 平台icon
2023-12-24 15:53:20 +08:00
apiPlatformGroup := r.Group("/api/platform", PrepareToC())
2023-12-21 22:17:40 +08:00
apiPlatformGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetPlatformList)
// 运营微信
2023-12-24 15:53:20 +08:00
apiSupportWxIdGroup := r.Group("/api/support_wx_id", PrepareToC())
2023-12-21 22:17:40 +08:00
apiSupportWxIdGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetSupportWxIdList)
// 是否有新版本
apiVersion := r.Group("/api/version", PrepareToC())
2024-01-10 22:01:16 +08:00
apiVersion.POST("is_there_a_new_version_available", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpIsThereANewVersionAvailable)
2023-12-21 22:17:40 +08:00
2023-12-28 18:37:39 +08:00
// 上传媒体失败配置
apiUploadMediaFailConfig := r.Group("/api/upload_media_fail_config", PrepareToC())
2024-01-10 22:01:16 +08:00
apiUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetUploadMediaFailConfigList)
2023-12-28 18:37:39 +08:00
2023-12-21 22:17:40 +08:00
// =============================== 以下是服务,只允许内网调用 ===============================
// op相关直接调用服务不调用gateway
// 商品
opProductGroup := r.Group("/op/product", PrepareOp())
opProductGroup.POST("create", middleware.JSONParamValidator(productproto.OpCreateReq{}), OpCreateProduct)
opProductGroup.POST("update", middleware.JSONParamValidator(productproto.OpUpdateReq{}), OpUpdateProduct)
opProductGroup.POST("delete", middleware.JSONParamValidator(productproto.OpDeleteReq{}), OpDeleteProduct)
opProductGroup.POST("list", middleware.JSONParamValidator(productproto.OpListReq{}), OpGetProductList)
// 支付相关
vasPayGroup := r.Group("/api/vas", PrepareToC())
vasPayGroup.POST("get_coins_product_list", middleware.JSONParamValidator(vasproto.GetCoinsProductListReq{}), GetCoinsProductList)
2024-02-01 09:52:45 +08:00
vasPayGroup.POST("get_membership_product_list", middleware.JSONParamValidator(vasproto.GetMembershipProductListReq{}), GetMembershipProductList)
2023-12-29 21:30:59 +08:00
vasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), middleware.JwtAuthenticator(), CreateOrder)
2023-12-21 22:17:40 +08:00
vasPayGroup.POST("one_step_unlock", middleware.JSONParamValidator(vasproto.OneStepUnlockContactReq{}), OneStepUnlock)
vasPayGroup.POST("consumer_fill_contact", middleware.JSONParamValidator(vasproto.ConsumerFillContactReq{}), ConsumerFillContact)
vasPayGroup.POST("get_add_wechat_list", middleware.JSONParamValidator(vasproto.GetAddWechatListReq{}), GetAddWechatList)
vasPayGroup.POST("confirm_add_wechat", middleware.JSONParamValidator(vasproto.ConfirmAddWechatReq{}), ConfirmAddWechat)
vasPayGroup.POST("get_unlock_wechat_list", middleware.JSONParamValidator(vasproto.GetUnlockWechatListReq{}), GetUnlockWechatList)
vasPayGroup.POST("get_ch_list", middleware.JSONParamValidator(vasproto.GetCHListReq{}), GetCHList)
vasPayGroup.POST("update_wechat", middleware.JSONParamValidator(vasproto.UpdateWechatReq{}), UpdateWechat)
vasPayGroup.POST("query_wechat", middleware.JSONParamValidator(vasproto.QueryWechatReq{}), QueryWechat)
vasPayGroup.POST("h5_direct_unlock_wechat", middleware.JSONParamValidator(vasproto.H5DirectUnlockWechatReq{}), H5DirectUnlockWechat)
vasPayGroup.POST("h5_get_unlock_wechat_list", middleware.JSONParamValidator(vasproto.GetUnlockWechatListReq{}), GetUnlockWechatList)
2024-01-07 22:37:06 +08:00
vasPayGroup.POST("withdraw_page", middleware.JSONParamValidator(vasproto.WithdrawPageReq{}), WithdrawPage)
vasPayGroup.POST("withdraw_send_verifycode", middleware.JSONParamValidator(vasproto.WithdrawSendVerifycodeReq{}), WithdrawSendVerifycode)
2024-01-08 11:49:16 +08:00
vasPayGroup.POST("withdraw_apply", middleware.JSONParamValidator(vasproto.WithdrawApplyReq{}), WithdrawApply)
2024-01-21 12:27:34 +08:00
vasPayGroup.POST("deal_one_coin_order", middleware.JSONParamValidator(vasproto.DealOneCoinOrderReq{}), DealOneCoinOrder)
2024-02-03 17:23:08 +08:00
vasPayGroup.POST("deal_one_order", middleware.JSONParamValidator(vasproto.DealOneOrderReq{}), DealOneOrder)
2023-12-21 22:17:40 +08:00
2023-12-29 14:16:37 +08:00
extVasPayGroup := r.Group("/ext/vas")
2023-12-29 17:33:56 +08:00
extVasPayGroup.POST("alipay_callback", AlipayCallback)
2024-02-05 21:16:49 +08:00
extVasPayGroup.POST("wxpay_callback", WxpayCallback)
2023-12-29 14:16:37 +08:00
2023-12-21 22:17:40 +08:00
opVasPayGroup := r.Group("/op/vas", PrepareOp())
opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder)
2024-01-17 22:11:12 +08:00
opVasPayGroup.POST("coin_order_list", middleware.JSONParamValidator(vasproto.OpCoinOrderListReq{}), OpOrderList)
2023-12-21 22:17:40 +08:00
// 验证码
opVeriCodeGroup := r.Group("/op/veri_code", PrepareOp())
opVeriCodeGroup.POST("send", middleware.JSONParamValidator(vericodeproto.OpSendReq{}), middleware.RequestDecryptor(), OpSendVeriCode)
// 登录
opLoginGroup := r.Group("/op/login", PrepareOp())
opLoginGroup.POST("login_by_pswd", middleware.JSONParamValidator(loginproto.OpLoginByPswdReq{}), middleware.RequestDecryptor(), OpLoginByPswd)
opLoginGroup.POST("login_by_veri_code", middleware.JSONParamValidator(loginproto.OpLoginByVeriCodeReq{}), middleware.RequestDecryptor(), OpLoginByVeriCode)
opLoginGroup.POST("logout", middleware.JSONParamValidator(loginproto.OpLogoutReq{}), middleware.JwtAuthenticator(), OpLogout)
opLoginGroup.POST("set_password", middleware.JSONParamValidator(loginproto.OpSetPswdReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), OpSetPassword)
opLoginGroup.POST("reset_password", middleware.JSONParamValidator(loginproto.OpResetPswdReq{}), middleware.RequestDecryptor(), OpResetPassword)
opLoginGroup.POST("update_password", middleware.JSONParamValidator(loginproto.OpUpdatePswdReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), OpUpdatePassword)
opLoginGroup.POST("validate", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpValidate)
// 账号
opAccountGroup := r.Group("/op/account", PrepareOp())
opAccountGroup.POST("update", middleware.JSONParamValidator(accountproto.OpUpdateReq{}), middleware.JwtAuthenticator(), middleware.RequestDecryptor(), OpUpdateAccount)
opAccountGroup.POST("list_by_mid", middleware.JSONParamValidator(accountproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetAccountListByMid)
2023-12-21 22:17:40 +08:00
//opAccountGroup.POST("list_by_mids", middleware.JSONParamValidator(accountproto.OpListByMidsReq{}), middleware.JwtAuthenticator(), OpGetAccountListByMids)
opAccountGroup.POST("list_by_user_id", middleware.JSONParamValidator(accountproto.OpListByUserIdReq{}), middleware.JwtAuthenticator(), OpGetAccountListByUserId)
2023-12-21 22:17:40 +08:00
opAccountGroup.POST("list_fuzzily_by_user_id", middleware.JSONParamValidator(accountproto.OpListFuzzilyByUserIdReq{}), middleware.JwtAuthenticator(), OpGetAccountListFuzzilyByUserId)
opAccountGroup.POST("list_fuzzily_by_name", middleware.JSONParamValidator(accountproto.OpListFuzzilyByNameReq{}), middleware.JwtAuthenticator(), OpGetAccountListFuzzilyByName)
opAccountGroup.POST("list_others_by_mid", middleware.JSONParamValidator(accountproto.OpListOthersByMidReq{}), middleware.JwtAuthenticator(), OpGetAccountListForOthersByMid)
opAccountGroup.POST("list_others_by_mids", middleware.JSONParamValidator(accountproto.OpListOthersByMidsReq{}), middleware.JwtAuthenticator(), OpGetAccountListForOthersByMids)
2024-01-02 19:34:05 +08:00
opAccountGroup.POST("count", middleware.JSONParamValidator(accountproto.OpCountReq{}), middleware.JwtAuthenticator(), OpGetAccountCount)
2023-12-21 22:17:40 +08:00
// 动态
opMomentGroup := r.Group("/op/moment", PrepareOp())
opMomentGroup.POST("create", middleware.JSONParamValidator(momentproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateMoment)
opMomentGroup.POST("update", middleware.JSONParamValidator(momentproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateMoment)
opMomentGroup.POST("delete", middleware.JSONParamValidator(momentproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteMoment)
opMomentGroup.POST("list", middleware.JSONParamValidator(momentproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetMomentList)
2024-02-05 19:06:42 +08:00
opMomentGroup.POST("list_by_mid", middleware.JSONParamValidator(momentproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetMomentListByMid)
2023-12-21 22:17:40 +08:00
opMomentGroup.POST("thumbs_up", middleware.JSONParamValidator(momentproto.OpThumbsUpReq{}), middleware.JwtAuthenticator(), OpThumbsUpMoment)
2024-02-01 10:19:44 +08:00
opMomentGroup.POST("list_by_ids", middleware.JSONParamValidator(momentproto.OpListByIdsReq{}), middleware.JwtAuthenticator(), OpGetMomentListByIds)
2023-12-21 22:17:40 +08:00
// 足迹
opFootPrintGroup := r.Group("/op/footprint", PrepareOp())
opFootPrintGroup.POST("create", middleware.JSONParamValidator(footprintproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateFootPrint)
opFootPrintGroup.POST("delete", middleware.JSONParamValidator(footprintproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteFootPrint)
opFootPrintGroup.POST("list_view", middleware.JSONParamValidator(footprintproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetViewFootPrintList)
opFootPrintGroup.POST("list_is_viewed", middleware.JSONParamValidator(footprintproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetIsViewedFootPrintList)
opFootPrintGroup.POST("count", middleware.JSONParamValidator(footprintproto.OpCountReq{}), middleware.JwtAuthenticator(), OpGetFootPrintCount)
// 点赞
opThumbsUpGroup := r.Group("/op/thumbs_up", PrepareOp())
opThumbsUpGroup.POST("list", middleware.JSONParamValidator(thumbsupproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetThumbsUpList)
// 用户关系
opAccountRelationGroup := r.Group("/op/account_relation", PrepareOp())
opAccountRelationGroup.POST("list_follow", middleware.JSONParamValidator(accountrelationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetFollowAccountRelationList)
opAccountRelationGroup.POST("list_is_followed", middleware.JSONParamValidator(accountrelationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetIsFollowedAccountRelationList)
opAccountRelationGroup.POST("list_friend", middleware.JSONParamValidator(accountrelationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetFriendAccountRelationList)
opAccountRelationGroup.POST("list_ignore", middleware.JSONParamValidator(accountrelationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetIgnoreAccountRelationList)
opAccountRelationGroup.POST("list_able_to_access_weixin_of", middleware.JSONParamValidator(accountrelationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetAbleToAccessWeixinOfAccountRelationList)
opAccountRelationGroup.POST("list_by_sentence", middleware.JSONParamValidator(accountrelationproto.OpListBySentenceReq{}), middleware.JwtAuthenticator(), OpGetAccountRelationBySentence)
opAccountRelationGroup.POST("count", middleware.JSONParamValidator(accountrelationproto.OpCountReq{}), middleware.JwtAuthenticator(), OpGetAccountRelationCount)
// 女神认证审批,后台支持查、审批,增删改均不支持
opStreamerAuthApprovalGroup := r.Group("/op/streamer_auth_approval", PrepareOp())
//opStreamerAuthApprovalGroup.POST("create", middleware.JSONParamValidator(streamerauthapprovalproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateStreamerAuthApproval)
//opStreamerAuthApprovalGroup.POST("update", middleware.JSONParamValidator(streamerauthapprovalproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateStreamerAuthApproval)
//opStreamerAuthApprovalGroup.POST("delete_batch", middleware.JSONParamValidator(streamerauthapprovalproto.OpDeleteBatchReq{}), middleware.JwtAuthenticator(), OpDeleteBatchStreamerAuthApproval)
opStreamerAuthApprovalGroup.POST("list", middleware.JSONParamValidator(streamerauthapprovalproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetStreamerAuthApprovalList)
opStreamerAuthApprovalGroup.POST("approve", middleware.JSONParamValidator(streamerauthapprovalproto.OpApproveReq{}), middleware.JwtAuthenticator(), OpApproveStreamerAuthApproval)
// 主播
opStreamerGroup := r.Group("/op/streamer", PrepareOp())
//opStreamerGroup.POST("create", middleware.JSONParamValidator(streamerproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateStreamer)
opStreamerGroup.POST("update", middleware.JSONParamValidator(streamerproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateStreamer)
//opStreamerGroup.POST("delete", middleware.JSONParamValidator(streamerproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteStreamer)
opStreamerGroup.POST("list_by_mid", middleware.JSONParamValidator(streamerproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetStreamerListByMid)
opStreamerGroup.POST("list_ext_by_mid", middleware.JSONParamValidator(streamerproto.OpListExtByMidReq{}), middleware.JwtAuthenticator(), OpGetStreamerExtListByMid)
opStreamerGroup.POST("list_ext_by_mids", middleware.JSONParamValidator(streamerproto.OpListExtByMidsReq{}), middleware.JwtAuthenticator(), OpGetStreamerExtListByMids)
opStreamerGroup.POST("list_ext_by_user_id", middleware.JSONParamValidator(streamerproto.OpListExtByUserIdReq{}), OpGetStreamerExtListByUserId)
opStreamerGroup.POST("list_ext_fuzzily_by_user_id", middleware.JSONParamValidator(streamerproto.OpListExtFuzzilyByUserIdReq{}), middleware.JwtAuthenticator(), OpGetStreamerExtListFuzzilyByUserId)
opStreamerGroup.POST("list_ext_fuzzily_by_name", middleware.JSONParamValidator(streamerproto.OpListExtFuzzilyByNameReq{}), middleware.JwtAuthenticator(), OpGetStreamerExtListFuzzilyByName)
opStreamerGroup.POST("list_wx_id", middleware.JSONParamValidator(streamerproto.OpListStreamerWxIdReq{}), middleware.JwtAuthenticator(), OpGetStreamerWxId)
opStreamerGroup.POST("recomm_list", middleware.JSONParamValidator(streamerproto.OpRecommListReq{}), middleware.JwtAuthenticator(), OpGetStreamerRecommList)
// 意见反馈
opFeedbackGroup := r.Group("/op/feedback", PrepareOp())
//opFeedbackGroup.POST("create", middleware.JSONParamValidator(feedbackproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateFeedback)
opFeedbackGroup.POST("update", middleware.JSONParamValidator(feedbackproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateFeedback)
//opFeedbackGroup.POST("delete", middleware.JSONParamValidator(feedbackproto.OpDeleteReq{}),middleware.JwtAuthenticator(), OpDeleteFeedback)
opFeedbackGroup.POST("list", middleware.JSONParamValidator(feedbackproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetFeedbackList)
// 通话记录
opCallHistoryGroup := r.Group("/op/call_history", PrepareOp())
opCallHistoryGroup.POST("create", middleware.JSONParamValidator(callhistoryproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateCallHistory)
//opCallHistoryGroup.POST("update", middleware.JSONParamValidator(callhistoryproto.OpUpdateReq{}),middleware.JwtAuthenticator(), OpUpdateCallHistory)
//opCallHistoryGroup.POST("delete", middleware.JSONParamValidator(callhistoryproto.OpDeleteReq{}),middleware.JwtAuthenticator(), OpDeleteCallHistory)
opCallHistoryGroup.POST("list", middleware.JSONParamValidator(callhistoryproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetCallHistoryList)
opCallHistoryGroup.POST("list_call_evaluation", middleware.JSONParamValidator(callhistoryproto.OpCallEvaluationListReq{}), middleware.JwtAuthenticator(), OpGetCallEvaluationList)
opCallHistoryGroup.POST("count", middleware.JSONParamValidator(callhistoryproto.OpCountReq{}), middleware.JwtAuthenticator(), OpGetCallHistoryCount)
// 主播链接
opStreamerLinkGroup := r.Group("/op/streamer_link", PrepareOp())
opStreamerLinkGroup.POST("list_by_mid", middleware.JSONParamValidator(streamerlinkproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetStreamerLinkListByMid)
// 用户微信添加审核
opUserWxAddCheckGroup := r.Group("/op/user_wx_add_check", PrepareOp())
opUserWxAddCheckGroup.POST("create", middleware.JSONParamValidator(userwxaddcheckproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateUserWxAddCheck)
opUserWxAddCheckGroup.POST("update", middleware.JSONParamValidator(userwxaddcheckproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateUserWxAddCheck)
opUserWxAddCheckGroup.POST("delete", middleware.JSONParamValidator(userwxaddcheckproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteUserWxAddCheck)
opUserWxAddCheckGroup.POST("list", middleware.JSONParamValidator(userwxaddcheckproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetUserWxAddCheckList)
// 实名认证
opRealNameAuthenticationGroup := r.Group("/op/realname_authentication", PrepareOp())
//opRealNameAuthenticationGroup.POST("create", middleware.JSONParamValidator(realname_authenticationproto.OpCreateReq{}), middleware.RequestDecryptor(), OpCreateRealNameAuthentication)
//opRealNameAuthenticationGroup.POST("update", middleware.JSONParamValidator(realname_authenticationproto.OpUpdateReq{}), middleware.RequestDecryptor(), OpUpdateRealNameAuthentication)
//opRealNameAuthenticationGroup.POST("delete_batch", middleware.JSONParamValidator(realname_authenticationproto.OpDeleteBatchReq{}), OpDeleteBatchRealNameAuthentication)
2024-01-10 22:01:16 +08:00
opRealNameAuthenticationGroup.POST("list", middleware.JSONParamValidator(realname_authenticationproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetRealNameAuthenticationList)
2023-12-21 22:17:40 +08:00
opRealNameAuthenticationGroup.POST("approve", middleware.JSONParamValidator(realname_authenticationproto.OpApproveReq{}), middleware.JwtAuthenticator(), OpApproveRealNameAuthentication)
//opRealNameAuthenticationGroup.POST("list_by_mid", middleware.JSONParamValidator(realname_authenticationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetRealNameAuthenticationList)
// 联系客服
opContactCustomerServiceGroup := r.Group("/op/contact_customer_service", PrepareOp())
2024-01-10 22:01:16 +08:00
opContactCustomerServiceGroup.POST("create", middleware.JSONParamValidator(contact_customer_serviceproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateContactCustomerService)
opContactCustomerServiceGroup.POST("update_by_ids", middleware.JSONParamValidator(contact_customer_serviceproto.OpUpdateByIdsReq{}), middleware.JwtAuthenticator(), OpUpdateContactCustomerServiceByIds)
2023-12-21 22:17:40 +08:00
//opContactCustomerServiceGroup.POST("delete", middleware.JSONParamValidator(contact_customer_serviceproto.OpDeleteReq{}), OpDeleteContactCustomerService)
2024-01-10 22:01:16 +08:00
opContactCustomerServiceGroup.POST("list_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.OpListBySessionIdReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceListBySessionId)
opContactCustomerServiceGroup.POST("list_unread_group_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.OpListUnreadReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceListUnreadGroupByMid)
2023-12-23 22:03:53 +08:00
// 联系客服对话表
opContactCustomerServiceSessionGroup := r.Group("/op/contact_customer_service_session", PrepareOp())
2024-01-10 22:01:16 +08:00
opContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateContactCustomerServiceSession)
opContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionListByMid)
opContactCustomerServiceSessionGroup.POST("list", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionList)
2023-12-21 22:17:40 +08:00
// 图片审核任务
opImageAuditTaskGroup := r.Group("/op/image_audit_task", PrepareOp())
opImageAuditTaskGroup.POST("list", middleware.JSONParamValidator(imageaudittaskproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetImageAuditTaskList)
opImageAuditTaskGroup.POST("pass_batch", middleware.JSONParamValidator(imageaudittaskproto.OpPassBatchReq{}), middleware.JwtAuthenticator(), OpPassImageAuditTaskBatch)
// 文字审核任务
opTextAuditTaskGroup := r.Group("/op/text_audit_task", PrepareOp())
opTextAuditTaskGroup.POST("list", middleware.JSONParamValidator(textaudittaskproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetTextAuditTaskList)
opTextAuditTaskGroup.POST("pass_batch", middleware.JSONParamValidator(textaudittaskproto.OpPassBatchReq{}), middleware.JwtAuthenticator(), OpPassTextAuditTaskBatch)
// 媒体相关
mediaGroup := r.Group("/api/media", PrepareToC())
mediaGroup.POST("auth", middleware.JSONParamValidator(mediaproto.MediaAuthReq{}), middleware.JwtAuthenticator(), MediaAuth)
mediaGroup.POST("c_upload", middleware.JSONParamValidator(mediaproto.CUploadReq{}), middleware.JwtAuthenticator(), CUpload)
// 主播标签
opStreamerTagGroup := r.Group("/op/streamer_tag", PrepareOp())
opStreamerTagGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetStreamerTagList)
// 平台icon
opPlatformGroup := r.Group("/op/platform", PrepareOp())
opPlatformGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetPlatformList)
// 运营微信
opSupportWxIdGroup := r.Group("/op/support_wx_id", PrepareOp())
opSupportWxIdGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetSupportWxIdList)
2023-12-28 18:37:39 +08:00
// 上传媒体失败配置
opUploadMediaFailConfig := r.Group("/op/upload_media_fail_config", PrepareOp())
2024-01-10 22:01:16 +08:00
opUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetUploadMediaFailConfigList)
2023-12-28 18:37:39 +08:00
// 每日报表表
opDailyStatementGroup := r.Group("/op/daily_statement", PrepareOp())
2024-01-03 22:53:53 +08:00
opDailyStatementGroup.POST("list", middleware.JSONParamValidator(daily_statementproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetDailyStatementList)
2024-02-01 09:52:45 +08:00
// 应用配置表
opAppConfigGroup := r.Group("/op/app_config", PrepareOp())
opAppConfigGroup.POST("update", middleware.JSONParamValidator(appconfigproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateAppConfig)
opAppConfigGroup.POST("list_by_key", middleware.JSONParamValidator(appconfigproto.OpListByKeyReq{}), middleware.JwtAuthenticator(), OpGetAppConfigListByKey)
2023-12-21 22:17:40 +08:00
// 账号相关
//accountGroup := r.Group("/account")
// =============================== 以上是服务,只允许内网调用 ===============================
}
func ServeFile(ctx *gin.Context) {
ctx.File("/Users/erwin/wishpal/wishpal-live-service/app/mix/conf/index.html")
}
func ReplyOk(ctx *gin.Context, data any) {
ctx.JSON(http.StatusOK, base.BaseResponse{
Ret: consts.RetCodeSuccess,
ErrCode: consts.ErrorCodeSuccess,
Data: data,
})
}
func ReplyErrorMsg(ctx *gin.Context, msg string) {
ctx.AbortWithStatusJSON(http.StatusOK, base.BaseResponse{
Ret: consts.RetCodeFail,
ErrCode: consts.ErrorCodeFail,
Msg: msg,
})
}
func ReplyErrCodeMsg(ctx *gin.Context, ec errcode.ErrCode) {
ctx.AbortWithStatusJSON(http.StatusOK, base.BaseResponse{
Ret: consts.RetCodeFail,
ErrCode: ec,
Msg: errcode.ErrCodeMsgMap[ec],
})
}
func ReplyJsonError(ctx *gin.Context, code int, msg string) {
ctx.AbortWithStatusJSON(code, base.BaseResponse{
Ret: consts.RetCodeFail,
Msg: msg,
})
}
func PrepareOp() gin.HandlerFunc {
return func(ctx *gin.Context) {
2023-12-25 01:14:14 +08:00
//if ctx.ClientIP() != "127.0.0.1" {
// ReplyJsonError(ctx, http.StatusBadRequest, fmt.Sprintf("not localhost, ip: %s", ctx.ClientIP()))
// return
//}
2023-12-21 22:17:40 +08:00
// if !wsign.CheckSignature(ctx) {
// ReplyErrCodeMsg(ctx, errcode.ErrCodeCheckSignatureFail)
// return
// }
var bodyParam map[string]interface{}
buf, err := ioutil.ReadAll(ctx.Request.Body)
err = json.Unmarshal(buf, &bodyParam)
if err != nil {
logger.Error("arg parse fail: %v", err)
ReplyJsonError(ctx, http.StatusBadRequest, "参数解析失败")
return
}
buf, err = json.Marshal(&bodyParam)
ctx.Set(gin.BodyBytesKey, buf)
}
}
func Prepare() gin.HandlerFunc {
return func(ctx *gin.Context) {
if ctx.ClientIP() != "127.0.0.1" {
ReplyJsonError(ctx, http.StatusBadRequest, fmt.Sprintf("not localhost, ip: %s", ctx.ClientIP()))
return
}
var bodyParam map[string]interface{}
buf, err := ioutil.ReadAll(ctx.Request.Body)
err = json.Unmarshal(buf, &bodyParam)
if err != nil {
logger.Error("arg parse fail: %v", err)
ReplyJsonError(ctx, http.StatusBadRequest, "参数解析失败")
return
}
buf, err = json.Marshal(&bodyParam)
ctx.Set(gin.BodyBytesKey, buf)
}
}
func PrepareToC() gin.HandlerFunc {
return func(ctx *gin.Context) {
// if !wsign.CheckSignature(ctx) {
// ReplyErrCodeMsg(ctx, errcode.ErrCodeCheckSignatureFail)
// return
// }
var bodyParam map[string]interface{}
buf, err := ioutil.ReadAll(ctx.Request.Body)
err = json.Unmarshal(buf, &bodyParam)
if err != nil {
logger.Error("arg parse fail: %v", err)
ReplyJsonError(ctx, http.StatusBadRequest, "参数解析失败")
return
}
buf, err = json.Marshal(&bodyParam)
ctx.Set(gin.BodyBytesKey, buf)
}
}
2023-12-29 14:16:37 +08:00
func PrepareExt() gin.HandlerFunc {
return func(ctx *gin.Context) {
var bodyParam map[string]interface{}
buf, err := ioutil.ReadAll(ctx.Request.Body)
err = json.Unmarshal(buf, &bodyParam)
if err != nil {
logger.Error("arg parse fail: %v", err)
ReplyJsonError(ctx, http.StatusBadRequest, "参数解析失败")
return
}
buf, err = json.Marshal(&bodyParam)
ctx.Set(gin.BodyBytesKey, buf)
}
}
2023-12-21 22:17:40 +08:00
var upGrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
}
func WsHandle(c *gin.Context) {
//升级get请求为webSocket协议
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
c.Writer.Write([]byte(err.Error()))
return
}
defer ws.Close()
for {
//读取ws中的数据
mt, message, err := ws.ReadMessage()
if err != nil {
c.Writer.Write([]byte(err.Error()))
break
}
fmt.Println("client message " + string(message))
//写入ws数据
err = ws.WriteMessage(mt, []byte(time.Now().String()))
if err != nil {
break
}
fmt.Println("system message " + time.Now().String())
}
}