Java realizes wechat payment through jsapi
To use jsapi for wechat payment, you must first obtain a prepay from wechat_ ID, and then complete the payment by calling the JS API of wechat. The return result of the JS API is get_ brand_ wcpay_ Request: OK is returned only when the user successfully completes the payment. Because the front-end interaction is complex, get_ brand_ wcpay_ Request: cancel or get_ brand_ wcpay_ Request: fail can be handled in a unified way, which means that users encounter errors or give up voluntarily, and there is no need to refine the distinction. The example code is as follows:
The parameter package passed in above is prepay_ id
The following is about obtaining parameters to call jsapi. When calling jsapi, we must obtain the user's openid (trade_type = jsapi, openid is a required parameter). First, define a requested object:
Because some parameters are required and some parameters are optional. And sign can't be calculated until all parameters are passed in, so the builder mode is used here. About builder mode.
We use httpclient for network transmission.
Then our main entrance:
The returned XML is:
return_ Code and result_ When the codes are success, the required prepay will be returned_ id。。。, Then use it in the JS API..
This article has been sorted into JavaScript wechat development skills summary, Android wechat development tutorial summary and Java wechat development tutorial summary. You are welcome to learn and read.
I would like to recommend a wechat applet tutorial with high attention: wechat applet development tutorial is carefully compiled for you. I hope you like it.