MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / WeChatBind

Function WeChatBind

controller/wechat.go:123–168  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

121}
122
123func WeChatBind(c *gin.Context) {
124 if !common.WeChatAuthEnabled {
125 c.JSON(http.StatusOK, gin.H{
126 "message": "管理员未开启通过微信登录以及注册",
127 "success": false,
128 })
129 return
130 }
131 code := c.Query("code")
132 wechatId, err := getWeChatIdByCode(code)
133 if err != nil {
134 c.JSON(http.StatusOK, gin.H{
135 "message": err.Error(),
136 "success": false,
137 })
138 return
139 }
140 if model.IsWeChatIdAlreadyTaken(wechatId) {
141 c.JSON(http.StatusOK, gin.H{
142 "success": false,
143 "message": "该微信账号已被绑定",
144 })
145 return
146 }
147 session := sessions.Default(c)
148 id := session.Get("id")
149 user := model.User{
150 Id: id.(int),
151 }
152 err = user.FillUserById()
153 if err != nil {
154 common.ApiError(c, err)
155 return
156 }
157 user.WeChatId = wechatId
158 err = user.Update(false)
159 if err != nil {
160 common.ApiError(c, err)
161 return
162 }
163 c.JSON(http.StatusOK, gin.H{
164 "success": true,
165 "message": "",
166 })
167 return
168}

Callers

nothing calls this directly

Calls 7

FillUserByIdMethod · 0.95
UpdateMethod · 0.95
IsWeChatIdAlreadyTakenFunction · 0.92
ApiErrorFunction · 0.92
getWeChatIdByCodeFunction · 0.85
ErrorMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected