SpringBoot style Alipay, wechat Pay development kit

SpringBoot style Alipay, wechat Pay development kit

2022-09-02 0 564
Resource Number 38019 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends a SpringBoot style wechat and Alipay payment development kit——Payment Spring Boot。

SpringBoot style Alipay, wechat Pay development kit插图

Most Java Web projects use Spring, especially Spring Boot. So the project authors chose a payment development kit built directly on top of Spring dependencies. When the project began to realize wechat Pay, the API version V3 of wechat Pay was announced. Compared to the V2 version:

  • Follow a unified Restful design style
  • Use JSON as the format for data interaction instead of XML
  • Use the SHA256-RSA digital signature algorithm based on asymmetric keys, and do not use MD5 or HMAC-SHA256
  • HTTPS client certificates are no longer required
  • Use AES-256-GCM to encrypt key information in callbacks

This development experience is far better than the previous V2, so we chose wechat Pay V3.

Currently supported channels

  • Wechat Pay V3 full support, and support multi-tenant at the same time to meet the mobile application App, public accounts, small programs and other payment scenarios
  • Alipay integrated SDK, made a simple adaptation

function

  • Realize multi-merchant wechat payment
  • Integrate Alipay SDK and quickly access Spring Boot
  • Implement wechat Pay V3 basic payment
  • Implement wechat Pay V3 combined payment
  • Implement wechat Pay V3 voucher
  • Realize wechat Pay V3 wechat pay points
  • Implement wechat Pay V3 premium card
  • Implement wechat payment V3 merchant vouchers
  • Implement wechat Pay V3 batch transfer to change

technique used

It only relies on what Spring already has, making it low dependency.

  • Spring
  • Jackson
  • Ali-pay-sdk

Core API architecture

SpringBoot style Alipay, wechat Pay development kit插图1

Fast access

1. Maven rely on

<dependency>
    <groupId>cn.felord</groupId>
    <artifactId>payment-spring-boot-starter</artifactId>
    <version>1.0.11.RELEASE</version>
</dependency>

2. Spring Boot Version adaptation

To clone the project, modify the following configuration items in pom.xml in the root directory:

<properties>
        <!--  Change to your corresponding Spring Boot version number -->
        <spring-boot.version>2.4.0</spring-boot.version>
    </properties>

3. install

Integrate into the project in the form of Spring Boot Starter. Pull the release branch from the GitHub project address to the local environment integration using one of the following two methods:

  • mvn install Install to local
  • mvn deploy Deploy to Maven repository

Then reference the Maven coordinates, noting that ${
payment-spring-boot-starter.version} Be consistent with what you installed.

<dependency>
            <groupId>cn.felord</groupId>
            <artifactId>payment-spring-boot-starter</artifactId>
            <version>${payment-spring-boot-starter.version}</version>
      </dependency>

4. Wechat Pay configuration

Configure wechat.pay.v3 parameters in application.yaml of the Spring Boot project.

wechat:
  pay:
    v3:
#    Tenant id  
     <tentantID>: 
#  appId Indicates the appid of the service provider in service mode. This parameter is mandatory
      app-id: xxxxxxxx
#  v2 api This parameter is mandatory if the key version is later than 1.0.5 and the interface on V2 is used
      app-secret: xxxxxxxxxxx
#  api v3Key required
      app-v3-secret: xxxxxxxx
#  Wechat Pay merchant number service provider mode is the mchid of the service provider is required
      mch-id: xxxxxxx
#  Merchant server domain name used for callback Security policy to release the callback interface This parameter is mandatory
      domain: https://felord.cn
#  Merchant api Certificate path Required classpath The path is located under the resources file of Project maven
      cert-path: apiclient_cert.p12

Wechat Pay tentantID scenario description

When the project needs to support wechat App payment, wechat public account payment, and wechat mini program payment at the same time, the app-ids in the above configuration may be multiple, so we need to carry out route identification to distinguish them, so you need to define a tentanID for identification. If we have both App payment and wechat mini program payment, we should configure it like this:

wechat:
  pay:
    v3:
    # App Tenant Indicates the tenant  mobile
     mobile:
      app-id: wx524534x423234
      app-secret: felord
      app-v3-secret: 0e5b123323h12234927e455703ec
      mch-id: 1603337223
      domain: https://felord.cn/mobile
      cert-path: mobile/apiclient_cert.p12
    # The wechat mini program tenant is identified as miniapp
     miniapp:
      app-id: wx344123x3541223
      app-secret: felord
      app-v3-secret: 0e5b123323h12234927e455703ec
      mch-id: 1603337223
      domain: https://felord.cn/miniapp
      cert-path: miniapp/apiclient_cert.p12

Note: Developers are required to ensure that Tentanids are unique within a set of systems.

5. Enable configuration

After configuration, you need to enable the @EnableMobilePay comment to enable the payment function:

@EnableMobilePay
@Configuration
public class PayConfig {
}

6.  Use API

Wechat Pay V3 open interfaces are introduced through WechatApiProvider, which will be initialized and injected with Spring IoC after the enabling and configuration steps are completed, and can be introduced in the following ways:

 @Autowired
    WechatApiProvider wechatApiProvider;

WechatApiProvider requires the developer to specify the tenant IDtenantID to initialize the Api for a specific scenario. For example, to query the end user’s coupon under Tenant mobile:

// Inquire about offers under Merchant quan
     @Test
     public void v3MchStocks() {
        // Corresponding tenantID in the configuration file:
        String tenantId =“mobile”;
        StocksQueryParams params = new StocksQueryParams();
        params.setOffset(0);
        params.setLimit(10);
        WechatResponseEntity<ObjectNode> objectNodeWechatResponseEntity = wechatApiProvider.favorApi(tenantId).queryStocksByMch(params);
        System.out.println("objectNodeWechatResponseEntity = " + objectNodeWechatResponseEntity);
     }

You can read more on your own.

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code SpringBoot style Alipay, wechat Pay development kit https://ictcoder.com/kyym/springboot-style-alipay-wechat-pay-development-kit.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service