Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

finallyeva/wx_pay_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

微信支付

参考文档 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php

使用

首先引入包

 from wx_pay import WxPay, WxPayError

构造微信支付类,传入配置微信支付参数

 wx_pay = WxPay(
 wx_app_id='WX_APP_ID', 
 wx_mch_id='WX_MCH_ID', 
 wx_mch_key='WX_MCH_KEY',
 wx_notify_url='http://www.example.com/pay/weixin/notify'
 )

创建订单

 pay_data = wx_pay.js_api(
 openid=u'***user_openid***', # 付款用户openid
 body=u'***商品名称/付款显示名称***', # 例如:饭卡充值100元
 total_fee=100 # total_fee 单位是 分, 100 = 1元
 )

给用户发红包

 wx_pay.send_red_pack(
 api_client_cert_path='/home/xxx/SERVER/ext_file/wx_2_pay_cert.pem',
 api_client_key_path='/home/xxx/SERVER/ext_file/wx_2_pay_key.pem',
 send_name=u'公众号发送红包测试', # 红包名称
 re_openid=u'***to_user_openid***', # 要接收红包的用户openid
 total_amount=100, # total_fee 单位是 分, 100 = 1元, 最大499元
 wishing=u'感谢参与测试', # 祝福语
 client_ip=u'222.222.222.222', # 调用微信发红包接口服务器公网IP地址
 act_name=u'微信支付测试系统', # 活动名称
 remark=u'感谢参与' # 备注
 )

查询订单

 raw = wx_pay.close_order(out_trade_no)

关闭订单

 raw = wx_pay.order_query(out_trade_no=out_trade_no)

工具函数

签名

 wx_pay.sign(dict(openid="xxxxxxxxxxxxxxxxxx", total_fee=100))

32位随机字符串

 wx_pay.nonce_str()

验证签名

 wx_pay.check(dict(openid="xxxxxxxxxxxxxxxxxx", total_fee=100, sign="signsignsignsign"))

生成微信前端JS配置参数

 详见example.py的wx_js_config方法,用来生成前端使用微信js的必要参数

License

The MIT License(http://opensource.org/licenses/MIT)

请自由地享受和参与开源

贡献

如果你有好的意见或建议,欢迎给我们提issue或pull request,为提升Python调用微信支付体验贡献力量

About

微信支付功能集

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%

AltStyle によって変換されたページ (->オリジナル) /