SpringBoot style Alipay, wechat Pay development kit

SpringBoot style Alipay, wechat Pay development kit

2022-09-02 0 976
Resource Number 38019 Last Updated 2025-02-24
¥ 0HKD 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/springboot-style-alipay-wechat-pay-development-kit/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services