service/app/mix/controller/init.go

515 lines
35 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"
callhistoryproto "service/api/proto/callhistory/proto"
contact_customer_serviceproto "service/api/proto/contact_customer_service/proto"
contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto"
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)
// 女神认证审批,用户端支持增删查,不支持改
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())
apiRealNameAuthenticationGroup.POST("create", middleware.JSONParamValidator(realname_authenticationproto.ApiCreateReq{}), middleware.RequestDecryptor(), ApiCreateRealNameAuthentication)
apiRealNameAuthenticationGroup.POST("list_by_mid", middleware.JSONParamValidator(realname_authenticationproto.ApiListReq{}), middleware.JwtAuthenticator(), ApiGetRealNameAuthenticationList)
// 联系客服
apiContactCustomerServiceGroup := r.Group("/api/contact_customer_service", PrepareToC())
apiContactCustomerServiceGroup.POST("create", middleware.JSONParamValidator(contact_customer_serviceproto.ApiCreateReq{}), ApiCreateContactCustomerService)
apiContactCustomerServiceGroup.POST("list_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.ApiListBySessionIdReq{}), ApiGetContactCustomerServiceListBySessionId)
// 联系客服对话表
apiContactCustomerServiceSessionGroup := r.Group("/api/contact_customer_service_session", PrepareToC())
apiContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCreateReq{}), ApiCreateContactCustomerServiceSession)
apiContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiListByMidReq{}), ApiGetContactCustomerServiceSessionListByMid)
// 主播标签
apiStreamerTagGroup := r.Group("/api/streamer_tag", PrepareToC())
apiStreamerTagGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetStreamerTagList)
// 平台icon
apiPlatformGroup := r.Group("/api/platform", PrepareToC())
apiPlatformGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetPlatformList)
// 运营微信
apiSupportWxIdGroup := r.Group("/api/support_wx_id", PrepareToC())
apiSupportWxIdGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetSupportWxIdList)
// 是否有新版本
apiVersion := r.Group("/api/version", PrepareToC())
apiVersion.POST("is_there_a_new_version_available", middleware.JSONParamValidator(base.BaseRequest{}), OpIsThereANewVersionAvailable)
// 上传媒体失败配置
apiUploadMediaFailConfig := r.Group("/api/upload_media_fail_config", PrepareToC())
apiUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), OpGetUploadMediaFailConfigList)
// =============================== 以下是服务,只允许内网调用 ===============================
// 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)
vasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.CreateOrderReq{}), middleware.JwtAuthenticator(), CreateOrder)
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)
extVasPayGroup := r.Group("/ext/vas")
extVasPayGroup.POST("alipay_callback", AlipayCallback)
opVasPayGroup := r.Group("/op/vas", PrepareOp())
opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder)
opVasPayGroup.POST("order_list")
// 验证码
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)
//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)
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)
// 动态
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)
opMomentGroup.POST("thumbs_up", middleware.JSONParamValidator(momentproto.OpThumbsUpReq{}), middleware.JwtAuthenticator(), OpThumbsUpMoment)
// 足迹
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("create", middleware.JSONParamValidator(thumbsupproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateThumbsUp)
opThumbsUpGroup.POST("delete", middleware.JSONParamValidator(thumbsupproto.OpDeleteReq{}), middleware.JwtAuthenticator(), OpDeleteThumbsUp)
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)
opRealNameAuthenticationGroup.POST("list", middleware.JSONParamValidator(realname_authenticationproto.OpListReq{}), OpGetRealNameAuthenticationList)
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())
opContactCustomerServiceGroup.POST("create", middleware.JSONParamValidator(contact_customer_serviceproto.OpCreateReq{}), OpCreateContactCustomerService)
opContactCustomerServiceGroup.POST("update_by_ids", middleware.JSONParamValidator(contact_customer_serviceproto.OpUpdateByIdsReq{}), OpUpdateContactCustomerServiceByIds)
//opContactCustomerServiceGroup.POST("delete", middleware.JSONParamValidator(contact_customer_serviceproto.OpDeleteReq{}), OpDeleteContactCustomerService)
opContactCustomerServiceGroup.POST("list_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.OpListBySessionIdReq{}), OpGetContactCustomerServiceListBySessionId)
opContactCustomerServiceGroup.POST("list_unread_group_by_session_id", middleware.JSONParamValidator(contact_customer_serviceproto.OpListUnreadReq{}), OpGetContactCustomerServiceListUnreadGroupByMid)
// 联系客服对话表
opContactCustomerServiceSessionGroup := r.Group("/op/contact_customer_service_session", PrepareOp())
opContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCreateReq{}), OpCreateContactCustomerServiceSession)
opContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListByMidReq{}), OpGetContactCustomerServiceSessionListByMid)
opContactCustomerServiceSessionGroup.POST("list", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListReq{}), OpGetContactCustomerServiceSessionList)
// 图片审核任务
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)
// 上传媒体失败配置
opUploadMediaFailConfig := r.Group("/op/upload_media_fail_config", PrepareToC())
opUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), OpGetUploadMediaFailConfigList)
// 账号相关
//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) {
//if ctx.ClientIP() != "127.0.0.1" {
// ReplyJsonError(ctx, http.StatusBadRequest, fmt.Sprintf("not localhost, ip: %s", ctx.ClientIP()))
// return
//}
// 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)
}
}
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)
}
}
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())
}
}