Ver código fonte

update

master
dengbiao 4 meses atrás
pai
commit
f8fa228180
2 arquivos alterados com 16 adições e 9 exclusões
  1. +11
    -5
      app/hdl/hdl_wx_open.go
  2. +5
    -4
      app/lib/wechat/wechat_api.go

+ 11
- 5
app/hdl/hdl_wx_open.go Ver arquivo

@@ -148,8 +148,7 @@ func GetPreAuthCode(c *gin.Context) {
return
}

var w http.ResponseWriter
w.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
redirectURI := "http://super.admin.izhyin.com/Wx/getAuthUrlCallBack"
// 对redirectURI进行URL编码
encodedRedirectURI := url.QueryEscape(redirectURI)
@@ -163,14 +162,21 @@ func GetPreAuthCode(c *gin.Context) {
query.Add("auth_type", "1")

// 将查询参数附加到基础URL
urlStr := baseURL + "?" + query.Encode()
authURL := baseURL + "?" + query.Encode()

// 设置JavaScript重定向
fmt.Fprintf(w, `
c.Header("Content-Type", "text/html") //TODO::必须指定相应内容为 text/html, 否则浏览器不能正确解析
c.String(200, `

<script>

window.onload = function () {

window.location.href = '%s';

};
</script>`, urlStr)

</script>`, authURL)
}

func WechatMsgRecieve(c *gin.Context) {


+ 5
- 4
app/lib/wechat/wechat_api.go Ver arquivo

@@ -31,9 +31,10 @@ func NewWxApiService(masterId, componentAppid, componentAppsecret string) (wxApi
}
cacheKey := fmt.Sprintf(md.MasterComponentVerifyTicket, wxApiService.MasterId)
cacheComponentVerifyTicket, _ := cache.GetString(cacheKey)
if cacheComponentVerifyTicket != "" {
if cacheComponentVerifyTicket == "" {
return wxApiService, errors.New("微信验证票据ticket未获取到")
}
wxApiService.ComponentVerifyTicket = cacheComponentVerifyTicket
return
}

@@ -41,14 +42,14 @@ func NewWxApiService(masterId, componentAppid, componentAppsecret string) (wxApi
func (wxApiService *WxApiService) GetComponentAccessToken() (cacheComponentAccessToken string, err error) { // set方法
cacheKey := fmt.Sprintf(md.MasterComponentAccessToken, wxApiService.MasterId)
cacheComponentAccessToken, _ = cache.GetString(cacheKey)
if cacheComponentAccessToken != "" {
if cacheComponentAccessToken == "" {
url := "https://api.weixin.qq.com/cgi-bin/component/api_component_token"
params := map[string]string{
"component_appid": wxApiService.ComponentAppid,
"component_appsecret": wxApiService.ComponentAppsecret,
"component_verify_ticket": wxApiService.ComponentVerifyTicket,
}
postBody, err1 := utils.CurlPost(url, params, nil)
postBody, err1 := utils.CurlPost(url, utils.SerializeStr(params), nil)
if err1 != nil {
return cacheComponentAccessToken, err1
}
@@ -91,7 +92,7 @@ func (wxApiService *WxApiService) GetPreAuthCode() (preAuthCode string, err erro
params := map[string]string{
"component_appid": wxApiService.ComponentAppid,
}
postBody, err := utils.CurlPost(url, params, nil)
postBody, err := utils.CurlPost(url, utils.SerializeStr(params), nil)
if err != nil {
return
}


Carregando…
Cancelar
Salvar