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

Function getWeChatIdByCode

controller/wechat.go:23–52  ·  view source on GitHub ↗
(code string)

Source from the content-addressed store, hash-verified

21}
22
23func getWeChatIdByCode(code string) (string, error) {
24 if code == "" {
25 return "", errors.New("无效的参数")
26 }
27 req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/wechat/user?code=%s", common.WeChatServerAddress, code), nil)
28 if err != nil {
29 return "", err
30 }
31 req.Header.Set("Authorization", common.WeChatServerToken)
32 client := http.Client{
33 Timeout: 5 * time.Second,
34 }
35 httpResponse, err := client.Do(req)
36 if err != nil {
37 return "", err
38 }
39 defer httpResponse.Body.Close()
40 var res wechatLoginResponse
41 err = json.NewDecoder(httpResponse.Body).Decode(&res)
42 if err != nil {
43 return "", err
44 }
45 if !res.Success {
46 return "", errors.New(res.Message)
47 }
48 if res.Data == "" {
49 return "", errors.New("验证码错误或已过期")
50 }
51 return res.Data, nil
52}
53
54func WeChatAuth(c *gin.Context) {
55 if !common.WeChatAuthEnabled {

Callers 2

WeChatAuthFunction · 0.85
WeChatBindFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected