


Detailed explanation of WeChat public account payment development (java) examples
In the past, payment in the company's project development was done using Alibaba's payment, which was called simple and casual; sadly, now the company has developed a WeChat official account, so I stepped into the WeChat payment development that is full of pitfalls. . .
Business process:
This WeChat official website explains it in great detail (portal:).
The general process is: the user clicks a payment button-->Backend processing (actually, it encapsulates the necessary data for payment and obtains prepay_id, and then combines it with Some necessary parameters are encapsulated and passed to the front desk)-->The front desk receives the data and calls WeChat's js to process the data and call payment-->The user sees an interface for entering a password, including the amount and other information--> After the user enters the password, a successful payment page will appear. At the same time, WeChat will call back our interface to notify us of the payment result (this part of the process is completed by WeChat itself, we don’t need to worry about it) --> Return to the system itself page.
Development Steps:
1. Set up the payment directory
This official document is very disgusting. I was confused and a little dizzy after reading it. Although I can’t understand it, I think it looks awesome! Portal:
2. Set the authorized domain name
These 2 steps Once you're done, you can take a break because the big pit is coming. . .
3. The merchant server calls the unified ordering interface to request an order
What does this do? When I first started doing it, I was confused, but who calls the WeChat payment team nb? How can they show their sophistication without adding some things that you don’t understand? . . If you don’t understand, just follow the document.
Portal:, WeChat official gave a detailed explanation of the parameters. After looking at it for a long time, I summarized it by encapsulating some necessary parameters and then accessing this interface to obtain data. The following are several commonly used parameters. Directly copy other people’s introduction in detail:


Problem summary (problems I encountered during this process): 1 (Important) appid and openid must match, in other words, the user's openid must be under the current official account Users (we have several public accounts, you may not encounter this problem, but it is very important, let me talk about it first) 2
<span style="text-decoration: underline; color: #ff0000">第二步,生成签名并返回到前台</span><span style="color: #ff0000">这个过程中一定要注意参数一定要写对了,大小写,是否有空格,我在这上面掉了一个大坑,界面调用支付时一直闪退,注意.<br><br></span>




1) Parse the passed flow information and verify the information contained in the flow by re-signing Correctness. It is to determine whether this information is sent by WeChat
2) If return_code and result_code are both SUCCESS, handle the merchant's own business logic. It’s just the payment status of the order and some other information.
3) Tell WeChat that I have received your return value. No need to post again.
Without further ado, let’s just post the code!
public String return_data(HttpServletRequest request, HttpServletResponse response) throws Exception { logger.info("微信支付请求回调了"); String resXml = ""; Map<string> backxml = new HashMap<string>(); InputStream inStream;try { inStream = request.getInputStream(); ByteArrayOutputStream outSteam = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while ((len = inStream.read(buffer)) != -1) { outSteam.write(buffer, 0, len); } outSteam.close(); inStream.close(); String result = new String(outSteam.toByteArray(), "utf-8");// 获取微信调用我们notify_url的返回信息Map<string> map = WXPayUtil.xmlToMap(result);if (map.get("result_code").toString().equalsIgnoreCase("SUCCESS")) {if (WXPayUtil.isSignatureValid(map, PayConfigUtil.API_KEY)) { logger.info("微信支付-签名验证成功");// backxml.put("return_code", "SUCCESS");// backxml.put("return_msg", "OK");// String toXml = WXPayUtil.mapToXml(backxml);// response.getWriter().write(toXml);resXml = "<xml>" + "<return_code></return_code>"+ "<return_msg></return_msg>" + "</xml> ";//业务处理开始 //业务处理结束 } BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());out.write(resXml.getBytes());out.flush();out.close(); } } catch (IOException e) { e.printStackTrace(); }return resXml; }</string></string></string>
##attach parameter? It is very convenient to bring business data here
#
The above is the detailed content of Detailed explanation of WeChat public account payment development (java) examples. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor