|
@@ -2,16 +2,11 @@ package controllers
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "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"
|
|
|
)
|
|
|
|
|
|
type WechatController struct {
|
|
@@ -175,29 +170,26 @@ func (this *WechatController) GetWxSign() {
|
|
|
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)
|
|
|
+ ticket, err := services.GetWxTicket(accessToken)
|
|
|
if err != nil {
|
|
|
- fmt.Println("获取失败:Err:" + err.Error())
|
|
|
+ br.Msg = "获取Ticket失败,请联系客服"
|
|
|
+ br.ErrMsg = "获取Ticket失败,Err" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println(config)
|
|
|
+ if ticket == "" {
|
|
|
+ br.Msg = "获取Ticket失败,请联系客服"
|
|
|
+ br.ErrMsg = "ticket为空" + ticket
|
|
|
+ return
|
|
|
+ }
|
|
|
+ nonceStr := utils.GetRandStringNoSpecialChar(16)
|
|
|
+ signature, nonceString, timestamp := services.GetWxSignature(ticket, getUrl, nonceStr)
|
|
|
+
|
|
|
resp := new(models.WechatSign)
|
|
|
- resp.AppId = config.AppID
|
|
|
- resp.NonceStr = config.NonceStr
|
|
|
- resp.Timestamp = config.Timestamp
|
|
|
+ resp.AppId = utils.WxAppId
|
|
|
+ resp.NonceStr = nonceString
|
|
|
+ resp.Timestamp = timestamp
|
|
|
resp.Url = getUrl
|
|
|
- resp.Signature = config.Signature
|
|
|
+ resp.Signature = signature
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取签名成功"
|
|
@@ -205,6 +197,5 @@ func (this *WechatController) GetWxSign() {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
-$app->bag('api/wechat/getWxSign',"WechatController@getWxSign");
|
|
|
$app->bag('api/wechat/check', "WechatController@check");
|
|
|
*/
|