Springboot Alipay Pay Skill logo

Springboot Alipay Pay Skill

Community
jiushiwon
springboot-alipay-pay-skill

Spring Boot 支付宝支付模块技能(独立版)。面向已有 Spring Boot 项目,提供支付宝当面付(条码/扫码)、手机网站支付、PC 网站支付、App 支付、退款、回调验签、订单查询、关单。**不包含微信支付**,如需微信请引入 springboot-wechat-pay-skill。触发词:"支付宝"、"当面付"、"手机网站支付"、"PC支付"、"App支付"、"支付宝退款"、"支付宝回调"、"alipay"、"商户号配置"。

Overview

Publisherjiushiwon
Repositorywg-skills
Skill namespringboot-alipay-pay-skill
Stars
123
Forks
38
Bundled files
6
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 6 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by jiushiwon on GitHub. Read the source before you install it.

Installation

Install the Springboot Alipay Pay Skill AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/java/springboot-module/springboot-alipay-pay-skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jiushiwon/wg-skills.git /tmp/wg-skills
mkdir -p .claude/skills
cp -r /tmp/wg-skills/vibeCoding/backend/java/springboot-module/springboot-alipay-pay-skill .claude/skills/springboot-alipay-pay-skill
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Springboot Alipay Pay Skill in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Springboot Alipay Pay Skill on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Springboot Alipay Pay Skill is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Spring Boot Alipay Pay Module Skill

支付宝支付独立模块,只覆盖支付宝渠道。与微信支付完全解耦,按需引入。

与合一版的关系

Skill范围推荐度
springboot-alipay-pay-skill(本)仅支付宝⭐⭐⭐⭐⭐ 单一渠道项目
springboot-wechat-pay-skill仅微信⭐⭐⭐⭐⭐ 单一渠道项目
springboot-payment-module-skill微信+支付宝合一旧版,已不推荐

能力清单

能力适用场景接口
当面付(条码)线下收银台,用户被扫POST /api/alipay/trade/precreate
当面付(扫码)PC 网站生成二维码POST /api/alipay/trade/precreate
手机网站支付手机浏览器(H5)POST /api/alipay/trade/wap
PC 网站支付PC 浏览器(页面跳转)POST /api/alipay/trade/page
App 支付iOS / Android AppPOST /api/alipay/trade/app
退款全渠道通用POST /api/alipay/trade/refund
查询订单全渠道通用GET /api/alipay/trade/query/{orderNo}
关单全渠道通用POST /api/alipay/trade/close/{orderNo}
回调验签全渠道通用POST /api/alipay/notify
账单下载对账GET /api/alipay/bill

前置依赖

依赖说明
springboot-init-skill项目骨架(必须)
springboot-auth-module-skill当前用户获取(推荐)
springboot-redis-module-skill幂等防重 + 限流(推荐)

核心实现

1. 依赖

xml
<!-- 支付宝新版 SDK(推荐) -->
<dependency>
    <groupId>com.alipay.sdk</groupId>
    <artifactId>alipay-sdk-java</artifactId>
    <version>4.35.2.ALL</version>
</dependency>

2. 配置(application.yml)

yaml
alipay:
  # ====== 必填项:从开放平台获取 ======
  app-id: ${ALIPAY_APP_ID:}                  # 16 位数字(沙箱:2021000000000000)
  
  # ====== 密钥对(V2 私钥 + 支付宝公钥) ======
  # 商户应用私钥(pkcs8 格式)
  private-key: ${ALIPAY_PRIVATE_KEY:}
  # 支付宝公钥(从开放平台获取,不是应用公钥!)
  alipay-public-key: ${ALIPAY_PUBLIC_KEY:}
  
  # ====== 回调地址 ======
  notify-url: ${ALIPAY_NOTIFY_URL:https://yourdomain.com/api/alipay/notify}
  return-url: ${ALIPAY_RETURN_URL:https://yourdomain.com/pay/success}
  
  # ====== 网关地址 ======
  # 生产:https://openapi.alipay.com/gateway.do
  # 沙箱:https://openapi.alipaydev.com/gateway.do
  gateway-url: ${ALIPAY_GATEWAY_URL:https://openapi.alipay.com/gateway.do}
  
  # ====== 签名方式 ======
  sign-type: RSA2
  charset: UTF-8
  format: json

完整配置说明 + 参数获取步骤 见 references/merchant-onboarding.md

3. 实体

java
@Entity
@Table(name = "wg_alipay_pay_order")
public class AlipayPayOrder {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(unique = true, length = 64)
    private String orderNo;            // 商户订单号
    
    @Column(length = 64)
    private String tradeNo;            // 支付宝交易号(回调后回填)
    
    @Enumerated(EnumType.STRING)
    private PayScene scene;            // PRECREATE / WAP / PAGE / APP
    
    @Enumerated(EnumType.STRING)
    private PayStatus status;          // PENDING / PAID / CLOSED / REFUNDED
    
    /** 金额(单位:元,BigDecimal) */
    private BigDecimal amount;
    
    private String subject;            // 商品标题
    private String qrCode;              // 当面付返回的二维码
    private String payUrl;              // 手机/PC 网站支付返回的 URL
    private String paidAt;
    private LocalDateTime createdAt;
}

@Entity
@Table(name = "wg_alipay_refund_order")
public class AlipayRefundOrder {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(unique = true, length = 64)
    private String refundNo;
    @Column(length = 64)
    private String orderNo;
    @Column(length = 64)
    private String refundId;            // 支付宝退款单号
    private BigDecimal refundAmount;
    private BigDecimal totalAmount;
    @Enumerated(EnumType.STRING)
    private RefundStatus status;
    private String reason;
    private LocalDateTime refundedAt;
}

4. 服务层(核心)

java
@Service
public class AlipayPayService {
    
    @Value("${alipay.app-id}") private String appId;
    @Value("${alipay.private-key}") private String privateKey;
    @Value("${alipay.alipay-public-key}") private String alipayPublicKey;
    @Value("${alipay.gateway-url}") private String gatewayUrl;
    @Value("${alipay.notify-url}") private String notifyUrl;
    @Value("${alipay.return-url}") private String returnUrl;
    
    private AlipayClient client;
    
    public AlipayPayService(...) {
        // 构造支付宝客户端(单例)
        this.client = new DefaultAlipayClient(
            gatewayUrl, appId, privateKey, "json", "UTF-8",
            alipayPublicKey, "RSA2"
        );
    }
    
    /** 当面付(预创建订单,返回二维码) */
    public PrecreateResponse precreate(PrecreateRequest req) {
        AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
        request.setNotifyUrl(notifyUrl);
        
        AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
        model.setOutTradeNo(req.getOrderNo());
        model.setTotalAmount(req.getAmount().toString());
        model.setSubject(req.getSubject());
        request.setBizModel(model);
        
        try {
            AlipayTradePrecreateResponse response = client.execute(request);
            if (response.isSuccess()) {
                return new PrecreateResponse(response.getQrCode());
            }
            throw new BusinessException(-3001, "预创建失败: " + response.getSubMsg());
        } catch (AlipayApiException e) {
            throw new BusinessException(-3001, "支付宝调用失败: " + e.getMessage());
        }
    }
    
    /** 手机网站支付(返回 form 表单,前端自动提交) */
    public String wapPay(WapPayRequest req) {
        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
        request.setReturnUrl(returnUrl);
        request.setNotifyUrl(notifyUrl);
        
        AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
        model.setOutTradeNo(req.getOrderNo());
        model.setTotalAmount(req.getAmount().toString());
        model.setSubject(req.getSubject());
        model.setProductCode("QUICK_WAP_WAY");
        request.setBizModel(model);
        
        try {
            return client.pageExecute(request).getBody();  // 返回 HTML form
        } catch (AlipayApiException e) {
            throw new BusinessException(-3001, "WAP 支付失败: " + e.getMessage());
        }
    }
    
    /** PC 网站支付(页面跳转) */
    public String pagePay(PagePayRequest req) {
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setReturnUrl(returnUrl);
        request.setNotifyUrl(notifyUrl);
        
        AlipayTradePagePayModel model = new AlipayTradePagePayModel();
        model.setOutTradeNo(req.getOrderNo());
        model.setTotalAmount(req.getAmount().toString());
        model.setSubject(req.getSubject());
        model.setProductCode("FAST_INSTANT_TRADE_PAY");
        request.setBizModel(model);
        
        try {
            return client.pageExecute(request).getBody();
        } catch (AlipayApiException e) {
            throw new BusinessException(-3001, "PC 支付失败: " + e.getMessage());
        }
    }
    
    /** App 支付(返回 orderStr 给 App 端调起支付宝) */
    public String appPay(AppPayRequest req) {
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
        request.setNotifyUrl(notifyUrl);
        
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setOutTradeNo(req.getOrderNo());
        model.setTotalAmount(req.getAmount().toString());
        model.setSubject(req.getSubject());
        model.setProductCode("QUICK_MSECURITY_PAY");
        request.setBizModel(model);
        
        try {
            return client.sdkExecute(request).getBody();  // 返回 orderStr
        } catch (AlipayApiException e) {
            throw new BusinessException(-3001, "App 支付失败: " + e.getMessage());
        }
    }
    
    /** 退款 */
    public RefundResponse refund(RefundRequest req) {
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        
        AlipayTradeRefundModel model = new AlipayTradeRefundModel();
        model.setOutTradeNo(req.getOrderNo());
        model.setOutRequestNo(req.getRefundNo());
        model.setRefundAmount(req.getRefundAmount().toString());
        model.setTotalAmount(req.getTotalAmount().toString());
        model.setRefundReason(req.getReason());
        request.setBizModel(model);
        
        try {
            AlipayTradeRefundResponse response = client.execute(request);
            if (response.isSuccess()) {
                return new RefundResponse(req.getRefundNo(), "PROCESSING");
            }
            throw new BusinessException(-3005, "退款失败: " + response.getSubMsg());
        } catch (AlipayApiException e) {
            throw new BusinessException(-3005, "退款异常: " + e.getMessage());
        }
    }
    
    /** 查询订单 */
    public AlipayPayOrder queryOrder(String orderNo) {
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        AlipayTradeQueryModel model = new AlipayTradeQueryModel();
        model.setOutTradeNo(orderNo);
        request.setBizModel(model);
        
        try {
            AlipayTradeQueryResponse response = client.execute(request);
            // 解析返回,更新本地订单
            return parsePayOrder(response);
        } catch (AlipayApiException e) {
            throw new BusinessException(-3003, "查询失败: " + e.getMessage());
        }
    }
    
    /** 关单 */
    public void closeOrder(String orderNo) {
        AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
        AlipayTradeCloseModel model = new AlipayTradeCloseModel();
        model.setOutTradeNo(orderNo);
        request.setBizModel(model);
        
        try {
            AlipayTradeCloseResponse response = client.execute(request);
            if (!response.isSuccess()) {
                throw new BusinessException(-3006, "关单失败: " + response.getSubMsg());
            }
        } catch (AlipayApiException e) {
            throw new BusinessException(-3006, "关单异常: " + e.getMessage());
        }
    }
}

5. 回调验签

java
@PostMapping("/api/alipay/notify")
public String notify(HttpServletRequest request) throws AlipayApiException {
    // 1. 获取所有参数(alipay 回调所有参数都在 form 里)
    Map<String, String> params = new HashMap<>();
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String name = paramNames.nextElement();
        params.put(name, request.getParameter(name));
    }
    
    // 2. 验签(关键步骤)
    boolean signVerified = AlipaySignature.rsaCheckV1(
        params, alipayPublicKey, "UTF-8", "RSA2"
    );
    
    if (!signVerified) {
        log.warn("支付宝回调验签失败: {}", params);
        return "fail";
    }
    
    // 3. 处理订单
    String orderNo = params.get("out_trade_no");
    String tradeNo = params.get("trade_no");
    String tradeStatus = params.get("trade_status");
    
    if ("TRADE_SUCCESS".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) {
        payOrderService.markAsPaid(orderNo, tradeNo);
    }
    
    // 4. 必须返回 "success"(注意是小写,且不带任何空格)
    return "success";
}

数据库表(Flyway 迁移示例)

sql
CREATE TABLE wg_alipay_pay_order (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    order_no VARCHAR(64) NOT NULL UNIQUE COMMENT '商户订单号',
    trade_no VARCHAR(64) COMMENT '支付宝交易号',
    scene VARCHAR(20) NOT NULL COMMENT 'PRECREATE/WAP/PAGE/APP',
    status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    amount DECIMAL(10,2) NOT NULL COMMENT '金额(元)',
    subject VARCHAR(200) COMMENT '商品标题',
    qr_code TEXT COMMENT '当面付二维码',
    pay_url TEXT COMMENT 'WAP/PC 支付URL',
    paid_at DATETIME,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='支付宝支付订单';

CREATE TABLE wg_alipay_refund_order (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    refund_no VARCHAR(64) NOT NULL UNIQUE,
    order_no VARCHAR(64) NOT NULL,
    refund_id VARCHAR(64),
    refund_amount DECIMAL(10,2) NOT NULL,
    total_amount DECIMAL(10,2) NOT NULL,
    status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    reason VARCHAR(200),
    refunded_at DATETIME,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_order_no (order_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='支付宝退款订单';

关键踩坑

坑现象解决
回调验签失败应用公钥填错用支付宝公钥(从开放平台复制),不是应用公钥
WAP 支付跳到登录页沙箱环境切到生产环境
异步通知收不到回调地址不通必须是公网 HTTPS,内网穿透用 frp
App 支付 iOS 端没反应orderStr 错误必须用 client.sdkExecute(request).getBody() 不用 pageExecute
金额对不上用了分(元)支付宝用元(BigDecimal),微信用分(long)

不做

  • ❌ 商户号开通(参考 merchant-onboarding.md)
  • ❌ 证书申请(参考同上)
  • ❌ UI 组件
  • ❌ 微信(独立 skill)

触发场景

用户说以下任一句即触发本 skill:

  • 「帮我加支付宝支付」
  • 「集成当面付 / 手机网站 / PC / App 支付」
  • 「做支付宝退款」
  • 「配置支付宝商户号」
  • 「支付宝回调怎么验签」

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Springboot Alipay Pay Skill AI skill do?

Spring Boot 支付宝支付模块技能(独立版)。面向已有 Spring Boot 项目,提供支付宝当面付(条码/扫码)、手机网站支付、PC 网站支付、App 支付、退款、回调验签、订单查询、关单。**不包含微信支付**,如需微信请引入 springboot-wechat-pay-skill。触发词:"支付宝"、"当面付"、"手机网站支付"、"PC支付"、"App支付"、"支付宝退款"、"支付宝回调"、"alipay"、"商户号配置"。

Why use Springboot Alipay Pay Skill on TypingMind?

Because you install it once and use it with any model. Springboot Alipay Pay Skill is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Springboot Alipay Pay Skill in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/java/springboot-module/springboot-alipay-pay-skill. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Springboot Alipay Pay Skill?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Springboot Alipay Pay Skill?

As many as you like. As long as a model supports skills, you can use Springboot Alipay Pay Skill with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Springboot Alipay Pay Skill AI skill free?

Yes. It is published on GitHub by jiushiwon under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇