How does java borrow a third party (IJPay) to quickly develop payment functions
Data required for WeChat payment
Official Account/Merchant Account
- WeChat official account application, select service account or enterprise account as the type, subscription account does not support WeChat payment function
- WeChat merchant account application (requires review)
The appid of the WeChat public account and the mchid of the merchant account can be obtained above
- v3 certificate
https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay6_0.shtmlWechatpay/wechatpay6_0.shtmlWeChatpay
provides a certificate download tool for the WeChat payment platform , and downloads the certificate according to the required merchant number and company name (red envelope/enterprise payment/ Refund and other operations need to use the WeChat payment API certificate)
above can obtain the certificate
- api secret key and apiv3 secret key (in the download platform certificate interface and callback notification of WeChat payment APIv3, in order to prevent the message from being maliciously tampered with by others, the server will encrypt the data. After receiving the message, the merchant must decrypt the plaintext , the key used in the decryption process is the APIv3 key)
Log in to the WeChat payment merchant platform, enter [Account Center] -> [Account Settings] -> [API Security] -> [APIv3 Key] and set the
above to get the API key and apiv3 key
maven, project configuration, configuration files
Note : All implementations of the project are based on the IJPay-Demo-SpringBoot project of IJpay source code
resources
Create a cert file and place the downloaded three certificate files under cert
pom.xml
The following attaches the dependencies that have been applied to the production environment in my project (including eureka, oauth2, etc.)
<dependencies>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<!-- sqlserver -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/sqljdbc4-4.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-dts</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.dachao.parameter</groupId>
<artifactId>parameter</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<!-- // 扩展包-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.2.0</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.16</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--SpringBoot集成redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- IJPay -->
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-All</artifactId>
<version>${ijapy.version}</version>
</dependency>
<dependency>
<groupId>com.github.xkzhangsan</groupId>
<artifactId>xk-time</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>com.youxuewang</groupId>
<artifactId>yxwApi</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
<!-- hutool工具 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier><!-- jdk版本 -->
</dependency>
</dependencies>
IJPay source code
https://gitee.com/javen205/IJPay
can download the source code and read it to understand the implementation principle. It encapsulates the API for calling WeChat and needs to be downloaded. Paste a part of the code from the source code for modification
First complete the preparatory work, put the wxpay_v3.properties in the source code IJPay-Demo-SpringBoot under resources in your own project.
The domain is the domain name authorized by WeChat. For details, please refer to the official document WeChat payment development document
v3.appId=公众号id
v3.keyPath=key.pem(resources文件下cert该文件的绝对路径,建议本地完成以后,放在服务器文件夹下访问)
v3.certPath=cert.pem (如上)
v3.certP12Path=cert.p12(如上)
v3.platformCertPath=wx_cert.pem(调用 WxPayV3Controller 中的 get接口生成)
v3.mchId=商户id
v3.apiKey3= 自定义 apiv3 秘钥
v3.apiKey= 自定义 apiv 秘钥
v3.domain= 微信授权域名
Configure some data such as appid and mchid obtained above here, and take WxPayV3Bean over
Code
WxPayV3Controller
- Generate platformCert.pem
Copy the com.ijpay.demo.controller.wxpay.WxPayV3Controller file under the source code to your own project, configure dependencies to make the project run,
and call the get method to generate the platformCert.pem file.
Order via JSAPI (official account)
JSAPI payment means that merchants call the JSAPI interface provided by WeChat payment, and call the WeChat payment module in the payment scenario to complete the collection.
Randomly take an openid and call the /v3/jsApiPay interface under the project.
The return result is the official document ( jaspi order ) send a description and return the result.
The following is the return result adjusted by my production environment.
The data returned by this interface can make the foreground call to invoke the payment jsapi to invoke the payment
Native order
Merchant's Native payment order interface, the WeChat background system returns the link parameter code_url, the merchant's background system generates a QR code image from the code_url value, and the user scans the code with the WeChat client to initiate payment.
Call the v3/nativePay interface
According to the official document description, as long as the following information is returned, the native interface is called successfully. The
following is the returned result adjusted by my production environment.
After finishing Sahua, all payments can be made according to this logic.
IJpay includes a series of payments such as WeChat payment, JD payment, and Alipay payment.