Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
772f2bdff4 Add HTTP proxy support for WeChat API requests
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
2026-03-11 15:35:59 +00:00
copilot-swe-agent[bot]
44349e944e Initial plan 2026-03-11 15:26:36 +00:00
2 changed files with 16 additions and 9 deletions

View File

@@ -411,6 +411,9 @@ func isProxyProviderType(providerType string) bool {
"Twitter",
"Uber",
"Yahoo",
"WeChat",
"WeChat Mini Program",
"WeCom",
}
for _, v := range providerTypes {
if strings.EqualFold(v, providerType) {
@@ -1363,7 +1366,7 @@ func (c *ApiController) GetQRCode() {
return
}
code, ticket, err := idp.GetWechatOfficialAccountQRCode(provider.ClientId2, provider.ClientSecret2, providerId)
code, ticket, err := idp.GetWechatOfficialAccountQRCode(provider.ClientId2, provider.ClientSecret2, providerId, proxy.ProxyHttpClient)
if err != nil {
c.ResponseError(err.Error())
return

View File

@@ -248,15 +248,17 @@ func BuildWechatOpenIdKey(appId string) string {
return fmt.Sprintf("wechat_openid_%s", appId)
}
func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (string, string, error) {
func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string, httpClient *http.Client) (string, string, error) {
accessTokenUrl := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", clientId, clientSecret)
request, err := http.NewRequest("GET", accessTokenUrl, nil)
if err != nil {
return "", "", err
}
client := new(http.Client)
resp, err := client.Do(request)
if httpClient == nil {
httpClient = new(http.Client)
}
resp, err := httpClient.Do(request)
if err != nil {
return "", "", err
}
@@ -281,8 +283,12 @@ func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (
return data.AccessToken, data.Errmsg, nil
}
func GetWechatOfficialAccountQRCode(clientId string, clientSecret string, providerId string) (string, string, error) {
accessToken, errMsg, err := GetWechatOfficialAccountAccessToken(clientId, clientSecret)
func GetWechatOfficialAccountQRCode(clientId string, clientSecret string, providerId string, httpClient *http.Client) (string, string, error) {
if httpClient == nil {
httpClient = new(http.Client)
}
accessToken, errMsg, err := GetWechatOfficialAccountAccessToken(clientId, clientSecret, httpClient)
if err != nil {
return "", "", err
}
@@ -291,8 +297,6 @@ func GetWechatOfficialAccountQRCode(clientId string, clientSecret string, provid
return "", "", fmt.Errorf("Fail to fetch WeChat QRcode: %s", errMsg)
}
client := new(http.Client)
weChatEndpoint := "https://api.weixin.qq.com/cgi-bin/qrcode/create"
qrCodeUrl := fmt.Sprintf("%s?access_token=%s", weChatEndpoint, accessToken)
params := fmt.Sprintf(`{"expire_seconds": 3600, "action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": "%s"}}}`, providerId)
@@ -303,7 +307,7 @@ func GetWechatOfficialAccountQRCode(clientId string, clientSecret string, provid
return "", "", err
}
resp, err := client.Do(request)
resp, err := httpClient.Do(request)
if err != nil {
return "", "", err
}