René's URL Explorer Experiment


Title: 公众号开发永久下载图片和声音的接口 materialImageOrVoiceDownload 无法正常刷新 AccessToken · Issue #3196 · binarywang/WxJava · GitHub

Open Graph Title: 公众号开发永久下载图片和声音的接口 materialImageOrVoiceDownload 无法正常刷新 AccessToken · Issue #3196 · binarywang/WxJava

X Title: 公众号开发永久下载图片和声音的接口 materialImageOrVoiceDownload 无法正常刷新 AccessToken · Issue #3196 · binarywang/WxJava

Description: 第一次提Issue 暂时不会提PR 麻烦修复一下这个BUG 简要描述 请简单概括描述下你所遇到的问题。 模块版本情况 WxJava 模块名: weixin-java-mp WxJava 版本号: 4.5.0 具体的包名:me.chanjar.weixin.mp.util.requestexecuter.material 详细描述 正常刷新Token的逻辑:只有抛出异常了,才会去刷新 AccessToken public T execute(RequestE...

Open Graph Description: 第一次提Issue 暂时不会提PR 麻烦修复一下这个BUG 简要描述 请简单概括描述下你所遇到的问题。 模块版本情况 WxJava 模块名: weixin-java-mp WxJava 版本号: 4.5.0 具体的包名:me.chanjar.weixin.mp.util.requestexecuter.material 详细描述 正常刷新Token的逻辑:只有抛出异常了,才会去刷新 Acce...

X Description: 第一次提Issue 暂时不会提PR 麻烦修复一下这个BUG 简要描述 请简单概括描述下你所遇到的问题。 模块版本情况 WxJava 模块名: weixin-java-mp WxJava 版本号: 4.5.0 具体的包名:me.chanjar.weixin.mp.util.requestexecuter.material 详细描述 正常刷新Token的逻辑:只有抛出异常了,才会去刷新 Acce...

Opengraph URL: https://github.com/binarywang/WxJava/issues/3196

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"公众号开发永久下载图片和声音的接口 materialImageOrVoiceDownload 无法正常刷新 AccessToken","articleBody":"## 第一次提Issue 暂时不会提PR 麻烦修复一下这个BUG\r\n\r\n### 简要描述\r\n__请简单概括描述下你所遇到的问题。__\r\n\r\n### 模块版本情况\r\n* WxJava 模块名:  weixin-java-mp\r\n* WxJava 版本号:  4.5.0\r\n具体的包名:me.chanjar.weixin.mp.util.requestexecuter.material\r\n\r\n### 详细描述\r\n正常刷新Token的逻辑:只有抛出异常了,才会去刷新 AccessToken \r\n\r\n```\r\n  public \u003cT, E\u003e T execute(RequestExecutor\u003cT, E\u003e executor, String uri, E data) throws WxErrorException {\r\n    int retryTimes = 0;\r\n    do {\r\n      try {\r\n        return this.executeInternal(executor, uri, data, false);\r\n      } catch (WxErrorException e) {\r\n        WxError error = e.getError();\r\n        // -1 系统繁忙, 1000ms后重试\r\n        if (error.getErrorCode() == -1) {\r\n          // 判断是否已经超了最大重试次数\r\n          if (retryTimes + 1 \u003e this.maxRetryTimes) {\r\n            log.warn(\"重试达到最大次数【{}】\", maxRetryTimes);\r\n            //最后一次重试失败后,直接抛出异常,不再等待\r\n            throw new WxRuntimeException(\"微信服务端异常,超出重试次数\");\r\n          }\r\n\r\n          int sleepMillis = this.retrySleepMillis * (1 \u003c\u003c retryTimes);\r\n          try {\r\n            log.warn(\"微信系统繁忙,{} ms 后重试(第{}次)\", sleepMillis, retryTimes + 1);\r\n            Thread.sleep(sleepMillis);\r\n          } catch (InterruptedException e1) {\r\n            throw new WxRuntimeException(e1);\r\n          }\r\n        } else {\r\n          throw e;\r\n        }\r\n      }\r\n    } while (retryTimes++ \u003c this.maxRetryTimes);\r\n\r\n    log.warn(\"重试达到最大次数【{}】\", this.maxRetryTimes);\r\n    throw new WxRuntimeException(\"微信服务端异常,超出重试次数\");\r\n  }\r\n```\r\n这三个是下载永久 声音和图片的实现类\r\n```\r\n  public static RequestExecutor\u003cInputStream, String\u003e create(RequestHttp requestHttp, File tmpDirFile) {\r\n    switch (requestHttp.getRequestType()) {\r\n      case APACHE_HTTP:\r\n        return new MaterialVoiceAndImageDownloadApacheHttpRequestExecutor(requestHttp, tmpDirFile);\r\n      case JODD_HTTP:\r\n        return new MaterialVoiceAndImageDownloadJoddHttpRequestExecutor(requestHttp, tmpDirFile);\r\n      case OK_HTTP:\r\n        return new MaterialVoiceAndImageDownloadOkhttpRequestExecutor(requestHttp, tmpDirFile);\r\n      default:\r\n        return null;\r\n    }\r\n  }\r\n\r\n```\r\n问题发生在 获取微信IO流的时候,没有正确判断ContentType 导致没有及时报错导致的:\r\nMaterialVoiceAndImageDownloadOkhttpRequestExecutor\r\n```\r\n  @Override\r\n  public InputStream execute(String uri, String materialId, WxType wxType) throws WxErrorException, IOException {\r\n    logger.debug(\"MaterialVoiceAndImageDownloadOkhttpRequestExecutor is running\");\r\n    OkHttpClient client = requestHttp.getRequestHttpClient();\r\n\r\n    RequestBody requestBody = RequestBody.create(MediaType.parse(\"application/json\"),\r\n      WxGsonBuilder.create().toJson(ImmutableMap.of(\"media_id\", materialId)));\r\n    Request request = new Request.Builder().url(uri).get().post(requestBody).build();\r\n    Response response = client.newCall(request).execute();\r\n    String contentTypeHeader = response.header(\"Content-Type\");\r\n    // 问题发生在这个判断,没有及时抛出 微信异常,导致的,因为微信返回的ContentType 是application/json; encoding=utf-8\r\n    if (\"text/plain\".equals(contentTypeHeader)) {\r\n      String responseContent = response.body().string();\r\n      throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));\r\n    }\r\n    \r\n    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BufferedSink sink = Okio.buffer(Okio.sink(outputStream))) {\r\n      sink.writeAll(response.body().source());\r\n      return new ByteArrayInputStream(outputStream.toByteArray());\r\n    }\r\n  }\r\n```\r\n代码修复 只需要增加 这个application/json判断即可 \r\n\r\n\r\n\r\n\r\n### ApiPost 返回\r\n![image](https://github.com/Wechat-Group/WxJava/assets/26403954/fae2f11d-8976-4f68-8d87-4b7477dca6c9)\r\n\r\n![image](https://github.com/Wechat-Group/WxJava/assets/26403954/ecdf81e5-0de6-4b3b-9281-7b230420ca1d)\r\n\r\n\r\n \r\n","author":{"url":"https://github.com/shenliuming","@type":"Person","name":"shenliuming"},"datePublished":"2023-12-26T12:19:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/3196/WxJava/issues/3196"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:eccf220b-d68e-b7e4-da41-901e5899f919
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBAE8:107FBB:40AD796:5613F6F:6964AD4A
html-safe-noncec4d43d6e043558531a65d40b901aa890981a0123d4046575cf48ae3ec7741f7b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUU4OjEwN0ZCQjo0MEFENzk2OjU2MTNGNkY6Njk2NEFENEEiLCJ2aXNpdG9yX2lkIjoiNjc1NTYwNDA3NjU0MDc2NzU2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac6b2f6a2cb9666284b500e9461a255e1d3a390509cd81cd6263686b52f8be46a9
hovercard-subject-tagissue:2056360766
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/binarywang/WxJava/3196/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d6a0e7aec34c2da6d1726f4c9c08494252dbe4900d5f340b8cf99711a242d970/binarywang/WxJava/issues/3196
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d6a0e7aec34c2da6d1726f4c9c08494252dbe4900d5f340b8cf99711a242d970/binarywang/WxJava/issues/3196
og:image:alt第一次提Issue 暂时不会提PR 麻烦修复一下这个BUG 简要描述 请简单概括描述下你所遇到的问题。 模块版本情况 WxJava 模块名: weixin-java-mp WxJava 版本号: 4.5.0 具体的包名:me.chanjar.weixin.mp.util.requestexecuter.material 详细描述 正常刷新Token的逻辑:只有抛出异常了,才会去刷新 Acce...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameshenliuming
hostnamegithub.com
expected-hostnamegithub.com
None15579c46431b7fd25941c3b09010f74fd1890c7a35226839bbbf40ce70fb3057
turbo-cache-controlno-preview
go-importgithub.com/binarywang/WxJava git https://github.com/binarywang/WxJava.git
octolytics-dimension-user_id1343140
octolytics-dimension-user_loginbinarywang
octolytics-dimension-repository_id49122742
octolytics-dimension-repository_nwobinarywang/WxJava
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49122742
octolytics-dimension-repository_network_root_nwobinarywang/WxJava
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release499abb347cb197601d399c346cfeb4b3fa135d5c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/binarywang/WxJava/issues/3196#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbinarywang%2FWxJava%2Fissues%2F3196
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbinarywang%2FWxJava%2Fissues%2F3196
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=binarywang%2FWxJava
Reloadhttps://github.com/binarywang/WxJava/issues/3196
Reloadhttps://github.com/binarywang/WxJava/issues/3196
Reloadhttps://github.com/binarywang/WxJava/issues/3196
binarywang https://github.com/binarywang
WxJavahttps://github.com/binarywang/WxJava
Please reload this pagehttps://github.com/binarywang/WxJava/issues/3196
Notifications https://github.com/login?return_to=%2Fbinarywang%2FWxJava
Fork 9k https://github.com/login?return_to=%2Fbinarywang%2FWxJava
Star 32.4k https://github.com/login?return_to=%2Fbinarywang%2FWxJava
Code https://github.com/binarywang/WxJava
Issues 17 https://github.com/binarywang/WxJava/issues
Pull requests 4 https://github.com/binarywang/WxJava/pulls
Discussions https://github.com/binarywang/WxJava/discussions
Actions https://github.com/binarywang/WxJava/actions
Wiki https://github.com/binarywang/WxJava/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/binarywang/WxJava/security
Please reload this pagehttps://github.com/binarywang/WxJava/issues/3196
Insights https://github.com/binarywang/WxJava/pulse
Code https://github.com/binarywang/WxJava
Issues https://github.com/binarywang/WxJava/issues
Pull requests https://github.com/binarywang/WxJava/pulls
Discussions https://github.com/binarywang/WxJava/discussions
Actions https://github.com/binarywang/WxJava/actions
Wiki https://github.com/binarywang/WxJava/wiki
Security https://github.com/binarywang/WxJava/security
Insights https://github.com/binarywang/WxJava/pulse
New issuehttps://github.com/login?return_to=https://github.com/binarywang/WxJava/issues/3196
New issuehttps://github.com/login?return_to=https://github.com/binarywang/WxJava/issues/3196
#3197https://github.com/binarywang/WxJava/pull/3197
公众号开发永久下载图片和声音的接口 materialImageOrVoiceDownload 无法正常刷新 AccessTokenhttps://github.com/binarywang/WxJava/issues/3196#top
#3197https://github.com/binarywang/WxJava/pull/3197
https://github.com/shenliuming
https://github.com/shenliuming
shenliuminghttps://github.com/shenliuming
on Dec 26, 2023https://github.com/binarywang/WxJava/issues/3196#issue-2056360766
https://private-user-images.githubusercontent.com/26403954/292867212-fae2f11d-8976-4f68-8d87-4b7477dca6c9.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjgyMDU5NDIsIm5iZiI6MTc2ODIwNTY0MiwicGF0aCI6Ii8yNjQwMzk1NC8yOTI4NjcyMTItZmFlMmYxMWQtODk3Ni00ZjY4LThkODctNGI3NDc3ZGNhNmM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAxMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMTEyVDA4MTQwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYwMmUzZDFjNjVmNDUwZDk3ZTZmMzczMDgxZDJiYThjMGJiZTU1ZjZlMDRlNjQzMDMzZWMzODkwZjcxMjBiYjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.1y4uK6EIdqfS-QqB89mcuFj4O4pfhWRSNzutf1zBZQ4
https://private-user-images.githubusercontent.com/26403954/292867246-ecdf81e5-0de6-4b3b-9281-7b230420ca1d.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjgyMDU5NDIsIm5iZiI6MTc2ODIwNTY0MiwicGF0aCI6Ii8yNjQwMzk1NC8yOTI4NjcyNDYtZWNkZjgxZTUtMGRlNi00YjNiLTkyODEtN2IyMzA0MjBjYTFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAxMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMTEyVDA4MTQwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNkZGIyMTY5MjU0M2ZmYzNiOTFlZGMxZTMzMWMzZTRlZmE5MmM1YzliZGMyMTc5YWNjMzY1NTYzMDQwYWE4MGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2OcE7tnQ7oT85iBDgKmRcq6VzxMuO5rLX0gmUhEPP-w
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.