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