|
@@ -2,15 +2,16 @@ package controllers
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- //"github.com/silenceper/wechat"
|
|
|
- //"github.com/silenceper/wechat/cache"
|
|
|
+ "github.com/silenceper/wechat"
|
|
|
+ "github.com/silenceper/wechat/cache"
|
|
|
+
|
|
|
"hongze/hongze_api/models"
|
|
|
"hongze/hongze_api/services"
|
|
|
"hongze/hongze_api/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
- //offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
|
|
|
+ offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
|
|
|
)
|
|
|
|
|
|
type WechatController struct {
|
|
@@ -152,50 +153,55 @@ func (this *WechatCommonController) WechatLogin() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-//// @Title 微信登录接口
|
|
|
-//// @Description 微信登录接口
|
|
|
-//// @Param Url query string true "url地址"
|
|
|
-//// @Success 200 {object} models.WxLoginResp
|
|
|
-//// @router /getWxSign [get]
|
|
|
-//func (this *WechatController) GetWxSign() {
|
|
|
-// br := new(models.BaseResponse).Init()
|
|
|
-// defer func() {
|
|
|
-// this.Data["json"] = br
|
|
|
-// this.ServeJSON()
|
|
|
-// }()
|
|
|
-// getUrl := this.GetString("Url")
|
|
|
-//
|
|
|
-// accessToken, err := services.WxGetAccessToken()
|
|
|
-// if err != nil {
|
|
|
-// br.Msg = "获取用户信息失败"
|
|
|
-// br.ErrMsg = "获取access_token失败,err:" + err.Error()
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// wc := wechat.NewWechat()
|
|
|
-// memory := cache.NewMemory()
|
|
|
-//
|
|
|
-// cfg := &offConfig.Config{
|
|
|
-// AppID: utils.WxAppId,
|
|
|
-// AppSecret: utils.WxAppSecret,
|
|
|
-// Token: accessToken,
|
|
|
-// Cache: memory,
|
|
|
-// }
|
|
|
-// oa := wc.GetOfficialAccount(cfg)
|
|
|
-// j:=oa.GetJs()
|
|
|
-// config,err:=j.GetConfig(getUrl)
|
|
|
-// if err!=nil {
|
|
|
-// fmt.Println("获取失败:Err:"+err.Error())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// fmt.Println(config)
|
|
|
-// resp := new(models.WxLoginResp)
|
|
|
-// br.Ret = 200
|
|
|
-// br.Success = true
|
|
|
-// br.Msg = "获取签名成功"
|
|
|
-// br.Data = resp
|
|
|
-//}
|
|
|
+
|
|
|
+// @Title 微信登录接口
|
|
|
+// @Description 微信登录接口
|
|
|
+// @Param Url query string true "url地址"
|
|
|
+// @Success 200 {object} models.WechatSign
|
|
|
+// @router /getWxSign [get]
|
|
|
+func (this *WechatController) GetWxSign() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ getUrl := this.GetString("Url")
|
|
|
+
|
|
|
+ accessToken, err := services.WxGetAccessToken()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "获取access_token失败,err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ wc := wechat.NewWechat()
|
|
|
+ memory := cache.NewMemory()
|
|
|
+
|
|
|
+ cfg := &offConfig.Config{
|
|
|
+ AppID: utils.WxAppId,
|
|
|
+ AppSecret: utils.WxAppSecret,
|
|
|
+ Token: accessToken,
|
|
|
+ Cache: memory,
|
|
|
+ }
|
|
|
+ oa := wc.GetOfficialAccount(cfg)
|
|
|
+ j:=oa.GetJs()
|
|
|
+ config,err:=j.GetConfig(getUrl)
|
|
|
+ if err!=nil {
|
|
|
+ fmt.Println("获取失败:Err:"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println(config)
|
|
|
+ resp := new(models.WechatSign)
|
|
|
+ resp.AppId=config.AppID
|
|
|
+ resp.NonceStr=config.NonceStr
|
|
|
+ resp.Timestamp=config.Timestamp
|
|
|
+ resp.Url=getUrl
|
|
|
+ resp.Signature=config.Signature
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取签名成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
|
|
|
|
|
|
|