Coder Social home page Coder Social logo

wechatpayv3's Introduction

WeChatPayV3

Python微信支付V3

  • 目前只实现了H5支付,小程序支付,后续补充其他。如有问题联系,谢谢!
# 如果 Cryptodome 报错使用 Crypto 代替

# 旧
from Cryptodome.PublicKey import RSA
from Cryptodome.Signature import pkcs1_15
from Cryptodome.Hash import SHA256
from Cryptodome.Cipher import AES

# 新
from Crypto.PublicKey import RSA
from Crypto.Signature import pkcs1_15
from Crypto.Hash import SHA256
from Crypto.Cipher import AES

H5支付例子

from main import WeChatPayV3
from utils import gen_order_number

mchid = 1234567890  # 商户号
appid = "wx1234567890123456"  # appid
v3key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"  # API V3 密钥
apiclient_key = "/Users/yangyuexiong/Desktop/apiclient_key.pem"  # 私钥证书路径
serial_no = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234"  # 商户号证书序列号
notify_url = "https://www.xxx.com/api/wxpay/notifyUrl"  # 回调地址

wx_pay = WeChatPayV3(
    mchid=mchid,
    appid=appid,
    v3key=v3key,
    apiclient_key=apiclient_key,
    serial_no=serial_no,
    notify_url=notify_url,
    pay_type="h5"
)

order_number = gen_order_number()
resp = wx_pay.pay(
    out_trade_no=order_number,
    total=1,
    description="测试",
    ip="127.0.0.1"
)
print(resp)

小程序支付例子

from config import *
from main import WeChatPayV3
from utils import gen_order_number

# 要注意`appid`是小程序的不是公众号的

wx_pay = WeChatPayV3(
    mchid=mchid,
    appid=appid,
    v3key=v3key,
    apiclient_key=apiclient_key,
    serial_no=serial_no,
    notify_url=notify_url,
    pay_type="mini"
)

order_number = gen_order_number()
resp = wx_pay.pay(
    out_trade_no=order_number,
    total=1,
    description="测试",
    ip="127.0.0.1",
    openid="omScQ7XY4LM-FyCiJmJH6H9r2Zxo"
)
print(resp)

wechatpayv3's People

Contributors

yangyuexiong avatar

Stargazers

Tom avatar  avatar Zi LIANG avatar AlexCaffrey avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.