Community编程与开发github.com

shuangying0001-beep/wechat-pay-integration

微信支付接入(JSAPI/Native/退款,含安全):强制回调验签、幂等、密钥隔离。适合任何要收款的微信应用。

wechat-pay-integration 是什么?

wechat-pay-integration is a Claude Code agent skill that 微信支付接入(JSAPI/Native/退款,含安全):强制回调验签、幂等、密钥隔离。适合任何要收款的微信应用。.

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/wechat-pay-integration

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

WeChat Pay Secure Integration

Source: Parent-Child Growth Diary Kit AI How-To.md §3.3 WeChat Pay, decoupled from project name to become a universal integration specification.

What It Is

WeChat Pay integration involves fixed interfaces and a set of security ironclads (callback signature verification, idempotency, key management). This skill provides both a "must-implement" checklist and generates a FastAPI payment module skeleton (routes + WeChat Pay client + callback verification + idempotency + JSAPI payment parameters + .env template), saving you from starting from scratch and encountering pitfalls.

The script includes --self-test: it uses temporary RSA keys + random APIv3 key to verify signature/signing verification and callback message AES encryption/decryption round-trip correctness, proving the generated cryptographic logic works — you don't have to trust it blindly.

When to Use

  • User says: "Integrate WeChat Pay" / "Mini Program payment" / "How to write WeChat Pay callback" / "WeChat refund" / "How to calculate paySign"
  • Any WeChat Mini Program / Official Account project that needs to accept payments

Pre-requisite Credentials Before Development (P0, otherwise code won't run)

  • WeChat Merchant ID MCH_ID (obtain from pay.weixin.qq.com)
  • API v3 Key (Merchant Platform → Account Center → API Security → Set APIv3 Key, 32 characters)
  • Merchant Certificate (apiclient_cert.pem + apiclient_key.pem, download from API Security page)
  • Mini Program / Official Account AppID (bound to the merchant ID)
  • Payment callback domain (configure whitelist on Merchant Platform)

WeChat Pay Interface Specification (Pre-built)

InterfaceDescriptionKey Notes
JSAPI Order POST /v3/pay/transactions/jsapiMini Program / Official Account paymentNeed to pass openid
Native Order POST /v3/pay/transactions/nativeQR code paymentReturns QR code URL
H5 Order POST /v3/pay/transactions/h5Mobile browser paymentNeed to configure H5 payment domain
Query Order GET /v3/pay/transactions/out-trade-no/{out_trade_no}Active queryCompensation for callback failure
Close Order POST /v3/pay/transactions/out-trade-no/{out_trade_no}/closeClose orderClose on timeout without payment
Payment Callback POST /your-callback-pathAsync notificationMust verify signature, this is the basis for payment success
Apply Refund POST /v3/refund/domestic/refundsRefundNeed merchant certificate

Mandatory Security Constraints (P0, none can be omitted)

  1. Payment result relies on async callback as the sole authority; do not trust front-end callbacks alone to determine payment success
  2. Callback interface must verify WeChat signature (Wechatpay-Signature header + platform certificate)
  3. Callback interface must implement idempotency (process same order only once even with multiple callbacks, using order number unique constraint / processed flag)
  4. Payment keys (apiv3_key, private key files) only stored on server locally / .env, not committed to Git, not written to logs
  5. Payment amount computed server-side, not trusting amount parameter from front-end

Script Usage (Generate FastAPI Payment Module Skeleton)

# 0) First verify the generated cryptographic logic works (recommended before first use)
python gen_pay.py --self-test

# 1) Generate module
python gen_pay.py --out ./pay_module

Generates:

  • pay_module/wechat_pay_client.py — Unified order (JSAPI/Native/H5), query, close, refund; signature and certificate loading; build_jsapi_payment() directly calculates the paySign required by frontend wx.requestPayment; callback message AES-256-GCM decryption; auto-fetch and verification of platform certificate
  • pay_module/router.py — /api/pay/create, /api/pay/notify (verify signature + idempotent), /api/pay/refund
  • pay_module/.env.example — Key fields to fill in (never commit real values)
  • pay_module/README.md — Integration steps

The generated code is a skeleton; you need to fill in real AppID / Merchant ID, and implement order table and "processed flag" logic (idempotency grounding).

Security Requirements (Re-emphasized)

  • apiv3_key and private key file paths only stored in .env, never appear in code or Git
  • If callback signature verification fails, return failure and do not update order status
  • WeChat Pay certificates are rotated periodically; platform certificate is auto-fetched and cached on the first callback

Notes

  • WeChat Pay v3 uses AES-256-GCM to decrypt callback messages and RSA for signature verification, requires cryptography library; the script will note dependencies
  • This skill only produces server-side integration skeleton; on the mini-program side, after receiving the payment object from /api/pay/create, directly call wx.requestPayment(payment) (already includes paySign)
  • Use with wechat-miniprogram-devrules (security boundaries) and ai-work-acceptance (acceptance) for best results

相关技能