In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what the WeChat Pay integration tool is, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
WeChat Pay integration tool
Recently, the boss arranged a new project to access WeChat Pay. I couldn't bear to look directly at the previous payment code (written by others many years ago), so I went to find the official sdk of Wechat. As a result, the official sdk is really not "object-oriented". As I usually use Aliyun more, I decided to use Aliyun's API style to write a set.
Order and payment result notification online project passed the test, other completed interfaces, simply did one or two tests, all passed. Other unfinished APIs will be selected to gradually complete github: https://github.com/BekeyChao/wxpay/tree/master
Mix on OSCHINA and bring a cloud warehouse: https://gitee.com/BekeyChao/wxpay
Start cd yourpathgit clone gitAddresscd wxpaymvn install quickly
Clone the source code locally, install it locally through mvn, and introduce it into the pom file
Xyz.bekey wxpay version
At present, the latest version is 0.0.5, and the minimum requirement of jdk is 1.8. there is not a lot of new content of java8 in the code. If you want to be compatible, you only need to modify the LocalDateTime type in the API for unified ordering.
Examples used in Spring
WeChat Pay tools are used by instantiating the WechatPay class, and it is recommended to register as a singleton in Spring for easy use.
@ Configurationpublic class WechatPayConfig {@ Value ("${mch_id}") private String mch_id; @ Value ("${key}") private String key; @ Value ("${cert_path}") private String cert_path / / the Wechat certificate path @ Bean public WechatPay wechatPay () {/ / wxConfig provides two construction methods. The default signature type is MD5, and the default WeChat Pay service address is taken from the official document WxpayConfig wxConfig = new WxpayConfig (WechatApplication.Yepaofu_Subscribe.getAppid (), mch_id, key, cert_path). / / Custom can ignore wxConfig.setConnectTimeou (10000); wxConfig.setSocketTimeout (10000); return new WechatPay (wxConfig);}}
Take the unified order issuing interface as an example to call the method.
@ Servicepublic class PayService {@ Autowired private WechatPay wechatPay; / / Unified ordering API public void toPay () {UnifiedOrderRequest request = new UnifiedOrderRequest (); request.setTotal_fee (100); request.setSpbill_create_ip ("10.10.10.10"); request.setOut_trade_no ("test123"); request.setBody ("Test order"); request.setTrade_type (TradeType.MWEB) Request.setOpenid ("openid"); request.setNotify_url ("http://mycallbak.com"); / / some else...") UnifiedOrderResponse response = wechatPay.getWechatPayResponse (request); boolean success = response.isSuccess (); if (success) {System.out.println (JSON.toJSONString (response));} else {System.out.println (response.getErr_code_des ()) }} / / callback of payment result, please obtain the xml string public void handleCallback (String xml) {try {UnifiedOrderCallback callback = wechatPay.unifiedorderCallback (xml); if (callback.isSuccess ()) {System.out.println (JSON.toJSONString (callback)) from response } else {System.out.println (callback.getErr_code_des ());}} catch (InvalidSignException e) {/ / handle signature exception e.printStackTrace ();} API completion list
Interface completed
Unified order issuing API UnifiedOrderRequest
Query order API OrderQueryRequest
Apply for refund API (certificate required) RefundRequest
Refund query API RefundQueryRequest
Notify UnifiedOrderCallback of the result of payment
Interface not completed
Close the order
Customs declaration
Download statement
Download fund bill
Transaction guarantee
Pull order evaluation data
Notification of refund result (due to the need for AES-256-ECB decryption, jdk does not support it by default and is not implemented for the time being)
Code style
There will be a lot of conversion between javabean xml map in the Wechat interface, but I deal with it casually. The conversion between xml and javabean is mainly through fastjson, because it is easy to use, so I don't care about efficiency. The overall api style design draws lessons from Aliyun SDK style, and xxxRequest corresponds to xxxResponse. This api design is very intuitive and can be called uniformly through an api API. At the parameter verification level, in order to be lazy, a large number of checks and data structure transformations are carried out in Request, so the Request class is not a simple class, and may encounter some trouble in debugging.
About what WeChat Pay integration tool is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.