1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package utils
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"gin-vue-admin/utils/wx"
)
func WxUserLogin(req request.MobileLogin) (error, *wx.LoginResponse) {
var loginRes *wx.LoginResponse
var err error
//获取openid、phone ,union_id
if req.UserType == 1 {
loginRes, err = wx.GetWxLoginRes(global.GVA_CONFIG.Wx.Appid, global.GVA_CONFIG.Wx.Appsecret,
req.WxCode, req.EncryptedDate, req.Iv)
} else if req.UserType == 2 {
loginRes, err = wx.GetWxLoginRes(global.GVA_CONFIG.Bkwx.Appid, global.GVA_CONFIG.Bkwx.Appsecret,
req.WxCode, req.EncryptedDate, req.Iv)
}
if err != nil {
fmt.Println("WxUserLogin ERR:", err)
return err, &wx.LoginResponse{}
}
return nil, loginRes
}
func GetOpenid(req request.MobileLogin) (error, string) {
var openId string
var err error
//获取openid、phone ,union_id
if req.UserType == 1 {
openId, err = wx.GetOpenId(global.GVA_CONFIG.Wx.Appid, global.GVA_CONFIG.Wx.Appsecret,
req.WxCode)
} else if req.UserType == 2 {
openId, err = wx.GetOpenId(global.GVA_CONFIG.Bkwx.Appid, global.GVA_CONFIG.Bkwx.Appsecret,
req.WxCode)
}
if err != nil {
fmt.Println(444)
fmt.Println(err)
return err, ""
}
return nil, openId
}