Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to realize the function of obtaining temporary QR code by Wechat official account

2025-04-10 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report