Ver código fonte

关注公众号消息推送

hsun 1 dia atrás
pai
commit
d133458ebf

+ 2 - 2
controllers/user.go

@@ -113,7 +113,7 @@ func (this *UserController) GetVerifyCode() {
 		var pars services.SmsApiPars
 		pars.PhoneList = append(pars.PhoneList, req.Phone)
 		pars.ServiceProvider = services.SmsApiServiceProviderDefault
-		pars.SmsContent = fmt.Sprintf("【金瑞期货】您的短信验证码是%s,有效期15分钟", code)
+		pars.SmsContent = fmt.Sprintf("您的短信验证码是%s,有效期15分钟", code)
 		pars.Sender = "金瑞小程序"
 		pars.Department = "信息技术部"
 		pars.Purpose = "小程序登录短信验证码"
@@ -302,7 +302,7 @@ func (this *UserController) SendSms() {
 	var pars services.SmsApiPars
 	pars.PhoneList = append(pars.PhoneList, req.Phone)
 	pars.ServiceProvider = services.SmsApiServiceProviderDefault
-	pars.SmsContent = fmt.Sprintf("【金瑞期货】您的短信验证码是%s,有效期15分钟", code)
+	pars.SmsContent = fmt.Sprintf("您的短信验证码是%s,有效期15分钟", code)
 	pars.Sender = "金瑞小程序"
 	pars.Department = "信息技术部"
 	pars.Purpose = "小程序登录短信验证码"

+ 59 - 0
controllers/wechat.go

@@ -2,9 +2,11 @@ package controllers
 
 import (
 	"encoding/json"
+	"encoding/xml"
 	"eta/eta_mini_api/models"
 	"eta/eta_mini_api/models/request"
 	"eta/eta_mini_api/models/response"
+	"eta/eta_mini_api/services"
 	"eta/eta_mini_api/services/wx_app"
 	"eta/eta_mini_api/utils"
 	"fmt"
@@ -91,3 +93,60 @@ func (this *WechatController) Login() {
 	br.Success = true
 	br.Ret = 200
 }
+
+// Notify
+// @Title 微信公众号消息通知
+// @Description 微信公众号消息通知
+// @Param   echostr   query   string  true "加密字符串"
+// @Success 200 {object} models.WechatSign
+// @router /notify [get,post]
+func (this *WechatController) Notify() {
+	echostr := this.GetString("echostr")
+	method := this.Ctx.Input.Method()
+
+	if method == "POST" {
+		body := this.Ctx.Input.RequestBody
+		utils.FileLog.Info("wechat notify:" + string(body))
+		item := new(request.Notify)
+		err := xml.Unmarshal(body, &item)
+		if err != nil {
+			utils.FileLog.Info("xml.Unmarshal:" + err.Error())
+		}
+		contactMsg := "感谢您的关注"
+
+		var openId, returnResult string
+		if item.MsgType != "" {
+			openId = item.FromUserName
+		}
+		xmlTpl := `<xml>
+		<ToUserName><![CDATA[%s]]></ToUserName>
+		<FromUserName><![CDATA[%s]]></FromUserName>
+		<CreateTime>%s</CreateTime>
+		<MsgType><![CDATA[text]]></MsgType>
+		<Content><![CDATA[%s]]></Content>
+		</xml>`
+		createTime := strconv.FormatInt(time.Now().Unix(), 10)
+		xmlTpl = fmt.Sprintf(xmlTpl, openId, utils.WX_ORIGIN_ID, createTime, contactMsg)
+
+		if item.MsgType == "event" {
+			switch item.Event {
+			case "subscribe":
+				fmt.Println("关注")
+				go services.WechatSubscribe(openId)
+			case "unsubscribe":
+				fmt.Println("取消关注")
+				go services.WechatUnsubscribe(openId)
+			case "CLICK":
+				returnResult = xmlTpl
+			default:
+				utils.FileLog.Info("wechat notify event:" + item.Event)
+			}
+			this.Ctx.WriteString(xmlTpl)
+		} else {
+			returnResult = xmlTpl
+		}
+		this.Ctx.WriteString(returnResult)
+	} else {
+		this.Ctx.WriteString(echostr)
+	}
+}

+ 10 - 0
models/request/wechat.go

@@ -7,3 +7,13 @@ type SendTemplateMsgRep struct {
 type WeChatLoginReq struct {
 	Code string `description:"用户code"`
 }
+
+type Notify struct {
+	ToUserName   string `xml:"ToUserName"`
+	FromUserName string `xml:"FromUserName"`
+	CreateTime   int    `xml:"CreateTime"`
+	MsgType      string `xml:"MsgType"`
+	Event        string `xml:"Event"`
+	EventKey     string `xml:"EventKey"`
+	Content      string `xml:"Content"`
+}

+ 12 - 3
models/user_record.go

@@ -21,9 +21,12 @@ type UserRecord struct {
 	RealName      string    `description:"用户姓名"`
 	Gender        int       `description:"性别"`
 	Avatar        string    `description:"用户头像"`
-	//SessionKey    string    `description:"微信小程序会话密钥"`
-	CreateTime time.Time `description:"创建时间"`
-	ModifyTime time.Time `description:"更新时间"`
+	Province      string    `description:"普通用户个人资料填写的省份"`
+	City          string    `description:"普通用户个人资料填写的城市"`
+	Country       string    `description:"国家,如中国CN"`
+	SessionKey    string    `description:"微信小程序会话密钥"`
+	CreateTime    time.Time `description:"创建时间"`
+	ModifyTime    time.Time `description:"更新时间"`
 }
 
 func (m *UserRecord) TableName() string {
@@ -41,6 +44,9 @@ type UserRecordCols struct {
 	RealName      string
 	Gender        string
 	Avatar        string
+	Province      string
+	City          string
+	Country       string
 	SessionKey    string
 	CreateTime    string
 	ModifyTime    string
@@ -58,6 +64,9 @@ func (m *UserRecord) Cols() UserRecordCols {
 		RealName:      "real_name",
 		Gender:        "gender",
 		Avatar:        "avatar",
+		Province:      "province",
+		City:          "city",
+		Country:       "country",
 		SessionKey:    "session_key",
 		CreateTime:    "create_time",
 		ModifyTime:    "modify_time",

+ 1 - 0
models/users.go

@@ -203,6 +203,7 @@ func (m *Users) Format2Item() (item *UsersItem) {
 		expiredTime := m.RegisterTime.Add(3 * 24 * time.Hour)
 		if expiredTime.Before(time.Now().Local()) {
 			item.TrialExpired = true
+			item.AuthStatus = AuthStatusClose
 		}
 	}
 	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, m.CreateTime)

+ 9 - 0
routers/commentsRouter.go

@@ -115,4 +115,13 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:WechatController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:WechatController"],
+        beego.ControllerComments{
+            Method: "Notify",
+            Router: `/notify`,
+            AllowHTTPMethods: []string{"get","post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
 }

+ 29 - 19
services/user.go

@@ -93,7 +93,7 @@ func BindUser(unionId, openId, phone, areaCode string) (userItem *models.UsersIt
 		users.Mobile = phone
 		users.AreaCode = areaCode
 		users.Status = models.UserStatusTrial
-		//users.AuthStatus = models.AuthStatusOpen
+		users.AuthStatus = models.AuthStatusOpen
 		users.IsRegistered = models.UserRegistered
 		users.RegisterTime = time.Now().Local()
 		users.OpenId = openId
@@ -121,23 +121,33 @@ func BindUser(unionId, openId, phone, areaCode string) (userItem *models.UsersIt
 	userItem = users.Format2Item()
 
 	// 绑定UserId
-	//userRecord, e := models.GetUserRecordByUnionId(unionId)
-	//if e != nil && e.Error() != utils.ErrNoRow() {
-	//	err = fmt.Errorf("获取微信用户记录失败, %v", e)
-	//	return
-	//}
-	//if users.Subscribe == models.UserNoSubscribe && userRecord != nil {
-	//	users.Subscribe = models.UserSubscribed
-	//	if e := users.Update([]string{users.Cols().Subscribe}); e != nil {
-	//		err = fmt.Errorf("更新用户关注状态失败, %v", e)
-	//		return
-	//	}
-	//
-	//	userRecord.UserId = users.UserId
-	//	if e := userRecord.Update([]string{userRecord.Cols().UserId}); e != nil {
-	//		err = fmt.Errorf("更新用户绑定状态失败, %v", e)
-	//		return
-	//	}
-	//}
+	userRecord := new(models.UserRecord)
+	{
+		cond := fmt.Sprintf(` AND %s = ?`, userRecord.Cols().UnionId)
+		pars := make([]interface{}, 0)
+		pars = append(pars, unionId)
+		ur, e := userRecord.GetItemByCondition(cond, pars, "")
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取订阅记录失败, %v", e)
+			return
+		}
+		if ur != nil && ur.UserRecordId > 0 {
+			userRecord = ur
+		}
+	}
+	if userRecord != nil && userRecord.UserRecordId > 0 {
+		users.Subscribe = userRecord.Subscribe
+		users.ModifyTime = time.Now().Local()
+		if e := users.Update([]string{users.Cols().Subscribe, users.Cols().ModifyTime}); e != nil {
+			err = fmt.Errorf("更新用户关注状态失败, %v", e)
+			return
+		}
+
+		userRecord.UserId = users.UserId
+		if e := userRecord.Update([]string{userRecord.Cols().UserId}); e != nil {
+			err = fmt.Errorf("更新订阅记录绑定状态失败, %v", e)
+			return
+		}
+	}
 	return
 }

+ 206 - 0
services/wechat.go

@@ -1 +1,207 @@
 package services
+
+import (
+	"eta/eta_mini_api/models"
+	"eta/eta_mini_api/services/wechat"
+	"eta/eta_mini_api/utils"
+	"fmt"
+	"time"
+)
+
+// WechatSubscribe 关注公众号
+func WechatSubscribe(openId string) {
+	var err error
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("WechatSubscribe, OpenId: %s, ErrMsg: %v", openId, err)
+			utils.FileLog.Info(tips)
+			fmt.Println(tips)
+		}
+	}()
+	if openId == "" {
+		err = fmt.Errorf("OpenId为空")
+		return
+	}
+
+	// 获取订阅信息
+	userRecord := new(models.UserRecord)
+	{
+		cond := fmt.Sprintf(` AND %s = ?`, userRecord.Cols().OpenId)
+		pars := make([]interface{}, 0)
+		pars = append(pars, openId)
+		record, e := userRecord.GetItemByCondition(cond, pars, "")
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取订阅记录失败, %v", e)
+			return
+		}
+		if record != nil && record.UserRecordId > 0 {
+			userRecord = record
+		}
+	}
+
+	// 获取unionId
+	var unionId string
+	wechatUser, e := wechat.GetUserInfo(openId)
+	if e != nil {
+		err = fmt.Errorf("获取公众号用户信息失败, %v", e)
+		return
+	}
+	if wechatUser.UnionID == "" {
+		err = fmt.Errorf("UnionId有误")
+		return
+	}
+	unionId = wechatUser.UnionID
+
+	// 订阅信息不存在那么新增
+	if userRecord.UserRecordId == 0 {
+		userRecord.OpenId = openId
+		userRecord.UnionId = unionId
+		userRecord.Subscribe = models.UserSubscribed
+		userRecord.SubscribeTime = time.Now().Local()
+		userRecord.NickName = wechatUser.Nickname
+		userRecord.Gender = int(wechatUser.Sex)
+		userRecord.Avatar = wechatUser.Headimgurl
+		//userRecord.Province = wechatUser.Province
+		//userRecord.City = wechatUser.City
+		//userRecord.Country = wechatUser.Country
+		userRecord.CreateTime = time.Now().Local()
+		userRecord.ModifyTime = time.Now().Local()
+		if e := userRecord.Create(); e != nil {
+			err = fmt.Errorf("新增订阅记录失败, %v", e)
+			return
+		}
+	}
+
+	// 查询是否有小程序用户
+	users := new(models.Users)
+	if userRecord.UserId > 0 {
+		u, e := users.GetItemById(userRecord.UserId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取用户信息失败, %v", e)
+			return
+		}
+		if u != nil && u.UserId > 0 {
+			users = u
+		}
+	} else {
+		cond := fmt.Sprintf(` AND %s = ?`, users.Cols().UnionId)
+		pars := make([]interface{}, 0)
+		pars = append(pars, unionId)
+		u, e := users.GetItemByCondition(cond, pars, "")
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("UnionId获取用户信息失败, %s, %v", unionId, e)
+			return
+		}
+		if u != nil && u.UserId > 0 {
+			users = u
+		}
+	}
+
+	// 更新订阅记录
+	var hasUsers bool
+	updateCols := []string{userRecord.Cols().UnionId, userRecord.Cols().Subscribe, userRecord.Cols().SubscribeTime, userRecord.Cols().ModifyTime}
+	if users.UserId > 0 {
+		userRecord.UserId = users.UserId
+		updateCols = append(updateCols, userRecord.Cols().UserId)
+		hasUsers = true
+	}
+	userRecord.UnionId = unionId
+	userRecord.Subscribe = models.UserSubscribed
+	userRecord.SubscribeTime = time.Now().Local()
+	userRecord.ModifyTime = time.Now().Local()
+	if e := userRecord.Update(updateCols); e != nil {
+		err = fmt.Errorf("更新订阅记录失败, %v", e)
+		return
+	}
+
+	// 更新用户信息
+	if !hasUsers {
+		return
+	}
+	users.UnionId = unionId
+	users.Subscribe = userRecord.Subscribe
+	users.ModifyTime = time.Now().Local()
+	updateCols = []string{users.Cols().Subscribe, users.Cols().ModifyTime}
+	if e := users.Update(updateCols); e != nil {
+		err = fmt.Errorf("UnionId绑定用户失败, %v", e)
+		return
+	}
+}
+
+// WechatUnsubscribe 取消关注公众号
+func WechatUnsubscribe(openId string) {
+	var err error
+	defer func() {
+		if err != nil {
+			tips := fmt.Sprintf("WechatUnsubscribe, OpenId: %s, ErrMsg: %v", openId, err)
+			utils.FileLog.Info(tips)
+			fmt.Println(tips)
+		}
+	}()
+	if openId == "" {
+		err = fmt.Errorf("OpenId为空")
+		return
+	}
+
+	userRecord := new(models.UserRecord)
+	{
+		cond := fmt.Sprintf(` AND %s = ?`, userRecord.Cols().OpenId)
+		pars := make([]interface{}, 0)
+		pars = append(pars, openId)
+		record, e := userRecord.GetItemByCondition(cond, pars, "")
+		if e != nil {
+			if e.Error() == utils.ErrNoRow() {
+				err = fmt.Errorf("订阅信息不存在")
+				return
+			}
+			err = fmt.Errorf("获取订阅记录失败, %v", e)
+			return
+		}
+		userRecord = record
+	}
+	userRecord.Subscribe = models.UserNoSubscribe
+	userRecord.SubscribeTime = time.Now().Local()
+	userRecord.ModifyTime = time.Now().Local()
+	updateCols := []string{userRecord.Cols().Subscribe, userRecord.Cols().SubscribeTime, userRecord.Cols().ModifyTime}
+	if e := userRecord.Update(updateCols); e != nil {
+		err = fmt.Errorf("更新订阅记录失败, %v", e)
+		return
+	}
+
+	// 更新用户表
+	users := new(models.Users)
+	if userRecord.UserId > 0 {
+		u, e := users.GetItemById(userRecord.UserId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取用户信息失败, %v", e)
+			return
+		}
+		if u != nil && u.UserId > 0 {
+			users = u
+		}
+	}
+	if users.UserId == 0 && userRecord.UnionId != "" {
+		cond := fmt.Sprintf(` AND %s = ?`, users.Cols().UnionId)
+		pars := make([]interface{}, 0)
+		pars = append(pars, userRecord.UnionId)
+		u, e := users.GetItemByCondition(cond, pars, "")
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = fmt.Errorf("获取用户信息失败, %v", e)
+			return
+		}
+		if u != nil && u.UserId > 0 {
+			users = u
+		}
+	}
+	if users.UserId == 0 {
+		err = fmt.Errorf("用户信息不存在")
+		return
+	}
+	users.Subscribe = userRecord.Subscribe
+	users.ModifyTime = time.Now().Local()
+	updateCols = []string{users.Cols().Subscribe, users.Cols().ModifyTime}
+	if e := users.Update(updateCols); e != nil {
+		err = fmt.Errorf("更新用户关注状态失败, %v", e)
+	}
+	return
+}

+ 59 - 106
services/wechat/wechat.go

@@ -1,91 +1,60 @@
 package wechat
 
 import (
+	"eta/eta_mini_api/models"
+	"eta/eta_mini_api/utils"
 	"fmt"
+	"github.com/silenceper/wechat/v2"
+	"github.com/silenceper/wechat/v2/cache"
 	"github.com/silenceper/wechat/v2/credential"
-)
-
-//var (
-//	WxAppId     string
-//	WxAppSecret string
-//)
+	"github.com/silenceper/wechat/v2/officialaccount/user"
+	"time"
 
-//type WechatAccessToken struct {
-//}
+	"github.com/silenceper/wechat/v2/officialaccount"
+	"github.com/silenceper/wechat/v2/officialaccount/config"
+)
 
-//func GetWxChat() (officialAccount *officialaccount.OfficialAccount) {
-//	wc := wechat.NewWechat()
-//	memory := cache.NewMemory()
-//	conf := &config.Config{
-//		AppID:          utils.WX_APPID,
-//		AppSecret:      utils.WX_APP_SECRET,
-//		Token:          "",
-//		EncodingAESKey: "",
-//		Cache:          memory,
-//	}
-//	officialAccount = wc.GetOfficialAccount(conf)
-//	wechatAccessToken := &WechatAccessToken{}
-//	officialAccount.SetAccessTokenHandle(wechatAccessToken)
-//	return
-//}
+type WechatAccessToken struct{}
 
-//var DefaultKey = "zcmRedis"
+func GetWxChat() (officialAccount *officialaccount.OfficialAccount) {
+	wc := wechat.NewWechat()
+	memory := cache.NewMemory()
+	conf := &config.Config{
+		AppID:          utils.WX_APPID,
+		AppSecret:      utils.WX_APP_SECRET,
+		Token:          "",
+		EncodingAESKey: "",
+		Cache:          memory,
+	}
+	officialAccount = wc.GetOfficialAccount(conf)
+	wechatAccessToken := &WechatAccessToken{}
+	officialAccount.SetAccessTokenHandle(wechatAccessToken)
+	return
+}
 
 // GetAccessToken 获取accessToken
-//func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error) {
-//	wxToken, err := models.GetWxTokenById()
-//	if err != nil && err.Error() != utils.ErrNoRow() {
-//		return
-//	}
-//	//如果300s就要过期了,那么就去刷新accessToken
-//	if wxToken.ExpiresIn < time.Now().Unix()+300 {
-//		tmpAccessToken, expires, tmpErr := getTokenFromServer(utils.WX_APPID, utils.WX_APP_SECRET)
-//		if tmpErr != nil {
-//			err = tmpErr
-//			return
-//		}
-//
-//		var updateCols = []string{"access_token", "expires_in"}
-//		wxToken.AccessToken = tmpAccessToken
-//		wxToken.ExpiresIn = time.Now().Unix() + expires - 600 //快过期前10分钟就刷新掉
-//		wxToken.Update(updateCols)
-//	}
-//	accessToken = wxToken.AccessToken
-//	return
-//}
+func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error) {
+	wxToken, err := models.GetWxTokenById()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	//如果300s就要过期了,那么就去刷新accessToken
+	if wxToken.ExpiresIn < time.Now().Unix()+300 {
+		tmpAccessToken, expires, tmpErr := getTokenFromServer(utils.WX_APPID, utils.WX_APP_SECRET)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
 
-// accessToken, err = utils.Redis.Get(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_DW).Result()
-// // wxToken, err := models.GetWxTokenById()
-// if err != nil && err != redis.Nil {
-// 	return
-// }
+		var updateCols = []string{"access_token", "expires_in"}
+		wxToken.AccessToken = tmpAccessToken
+		wxToken.ExpiresIn = time.Now().Unix() + expires - 600 //快过期前10分钟就刷新掉
+		wxToken.Update(updateCols)
+	}
+	accessToken = wxToken.AccessToken
+	return
+}
 
-// models.GetWxTokenById()
-// minConf, _ := models.GetMiniConf()
-// // 缓存中没有取到数据,那么就需要强制刷新的accessToken
-// tmpAccessToken, expires, tmpErr := getTokenFromServer(minConf["WxAppId"], minConf["WxAppSecret"])
-//
-//	if tmpAccessToken == "" {
-//		err = errors.New("获取微信token失败,Err:" + tmpErr.Error())
-//		return
-//	}
-//
-// redisTimeExpire := time.Duration(expires-600) * time.Second
-// err = utils.Redis.SetEX(context.TODO(), utils.CACHE_WX_ACCESS_TOKEN_DW, tmpAccessToken, redisTimeExpire).Err()
-//
-//	if err != nil {
-//		return
-//	}
-//
-// err = utils.Redis.HSet(context.TODO(), DefaultKey, utils.CACHE_WX_ACCESS_TOKEN_DW, true).Err()
-// // err = utils.Redis.Put(utils.CACHE_WX_ACCESS_TOKEN_HZ, tmpAccessToken, redisTimeExpire)
-//
-//	if err != nil {
-//		err = errors.New("更新微信token失败")
-//		return
-//	}
-//
-// return
 // getTokenFromServer 服务端获取accessToken
 func getTokenFromServer(appid, wxSecret string) (accessToken string, expires int64, err error) {
 	apiUrl := "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
@@ -100,37 +69,21 @@ func getTokenFromServer(appid, wxSecret string) (accessToken string, expires int
 }
 
 // GetUserInfo 获取微信用户详情
-//func GetUserInfo(openid string) (userInfo *user.Info, err error) {
-//	wechatClient := GetWxChat()
-//	userClient := wechatClient.GetUser()
-//	userInfo, err = userClient.GetUserInfo(openid)
-//	return
-//}
-
-// GetSession 获取用户详情
-// func GetSession(code string) (userInfo auth.ResCode2Session, err error) {
-// 	wechatClient := GetWxChat()
-// 	userClient := wechatClient.GetUser()
-// 	userInfo, err = authClient.Code2Session(code)
-// 	return
-// }
-
-// GetJsConfig 获取公众号jsConfig
-//func GetJsConfig(signUrl string) (jsConf *js.Config, err error) {
-//	wechatClient := GetWxChat()
-//	j := wechatClient.GetJs()
-//	jsConf, err = j.GetConfig(signUrl)
-//	return
-//}
+func GetUserInfo(openid string) (userInfo *user.Info, err error) {
+	wechatClient := GetWxChat()
+	userClient := wechatClient.GetUser()
+	userInfo, err = userClient.GetUserInfo(openid)
+	return
+}
 
-//type WxUserInfo struct {
-//	OpenId       string `json:"openid"`
-//	AccessToken  string `json:"access_token"`
-//	RefreshToken string `json:"refresh_token"`
-//	Scope        string `json:"scope"`
-//	ErrCode      int
-//	ErrMsg       string
-//}
+type WxUserInfo struct {
+	OpenId       string `json:"openid"`
+	AccessToken  string `json:"access_token"`
+	RefreshToken string `json:"refresh_token"`
+	Scope        string `json:"scope"`
+	ErrCode      int
+	ErrMsg       string
+}
 
 //func GetWxUserInfo(code string) (info *WxUserInfo, err error) {
 //	httpUrl := `https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code`

+ 6 - 6
utils/config.go

@@ -44,9 +44,9 @@ var AlarmMsgUrl string // 报警地址
 var (
 	WX_MINI_APPID      string
 	WX_MINI_APP_SECRET string
-	//WX_ORIGIN_ID       string
-	//WX_APPID           string
-	//WX_APP_SECRET      string
+	WX_ORIGIN_ID       string
+	WX_APPID           string
+	WX_APP_SECRET      string
 )
 
 var SmsApiUrl string // 金瑞短信API调用地址
@@ -88,9 +88,9 @@ func init() {
 	WX_MINI_APPID = config["wx_mini_appid"]
 	WX_MINI_APP_SECRET = config["wx_mini_app_secret"]
 
-	//WX_ORIGIN_ID = config["wx_origin_id"]
-	//WX_APPID = config["wx_appid"]
-	//WX_APP_SECRET = config["wx_app_secret"]
+	WX_ORIGIN_ID = config["wx_origin_id"]
+	WX_APPID = config["wx_appid"]
+	WX_APP_SECRET = config["wx_app_secret"]
 
 	SmsApiUrl = config["sms_api_url"]