In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use Java to achieve the Wechat official account to obtain temporary QR code function. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The details are as follows:
1. Get access_token. I won't repeat it after I wrote the last article.
two。 Get the QR code ticket according to access_token, and get the QR code ticket is basically successful.
3. To get a QR code through ticket is actually splicing url and ticket.
Public class WeChatQRCodeTest {public static void main (String [] args) {String qrcodeUrl = ""; try {String accessToken = "15_Yws71Wr-Fk9DW5acDWvyn3YWTfp_jkuBxCl8Hue5hRrB064FVrYSPZgNqdxpw1WKVbp0c7DIerwzGa2iuJDI2er3q7ntf" + "WNteHZbpSXwCLnUh0p16UQvUhisKKqTrPAMQQdHXklTywmQ6L8MVKNiAJAAPS"; JSONObject jsonObject = new JSONObject (); jsonObject.put ("expire_seconds", 2592000); jsonObject.put ("action_name", "QR_STR_SCENE"); JSONObject actionInfo = new JSONObject (); JSONObject scene = new JSONObject () Scene.put ("scene_str", "information carried in QR code"); actionInfo.put ("scene", scene); jsonObject.put ("action_info", actionInfo); String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + accessToken; String result = HttpClientUtil.doPostJson (url, jsonObject.toJSONString ()); JSONObject resultJson = JSONObject.parseObject (result) String ticket = resultJson.getString ("ticket"); / * in practical applications, the server can store ticket * / Integer expire_seconds = resultJson.getInteger ("expire_seconds") according to the expiration time; qrcodeUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + URLEncoder.encode (ticket," UTF-8 ");} catch (UnsupportedEncodingException e) {e.printStackTrace () } System.out.println (qrcodeUrl);}}
The code is as above, where the HttpClientUtil, that is, the HttpClientUtil,access_token of the previous blog, is obtained and written, and the single-interface test can be obtained using the web test tool provided by Wechat.
The corresponding value in scene_str is the information we need to carry in the QR code.
Thank you for reading! On "how to use Java to achieve Wechat official account to obtain temporary QR code function" this article shares here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.