Coder Social home page Coder Social logo

wechat_pay_py's Introduction

Wechat Pay For Python

实现微信支付V2和V3。

1. Wechat Pay V3

发起支付

python端, 修改version3中的config文件

config = {
    'appId': '',
    'Mchid': '',
    'Key': '',
    'notify_url': ''
}
import version3
import json

params = version3.build_form_by_params({
    'body': 'test',
    'out_trade_no': 'id',
    'total_fee': '1',
    'spbill_create_ip': '127.0.0.1',
    'openid': ''
    })

json.dumps(params)

前端

var json_str = $.get(url)
var params = JSON.parse(json_str)

WeixinJSBridge.invoke('getBrandWCPayRequest', params, function(res){
    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
    }
});

验证notify

python端

import version3

version3.verify_notify_string(request_string)
返回True或者False

2. Wechat Pay V2

发起支付

python端, 修改version2中的config文件

config = {
    'appId': 'xxx',
    'appSecret': 'xxx',
    'paySignKey': 'xxx',
    'partnerId': 'xxx',
    'partnerKey': 'xxx',
    'notify_url': 'xxx'
}
import version2
import json

params = version2.build_form(
    'body': 'product name',
    'out_trade_no': 'order number',
    'total_fee': '1',
    'spbill_create_ip': 'd.d.d.d'
)

json.dumps(params)

前端

var json_str = $.get(url)
var params = JSON.parse(json_str)

document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    WeixinJSBridge.call('hideOptionMenu');
    WeixinJSBridge.call('hideToolbar');

    $('a#getBrandWCPayRequest').click(function(e){
        WeixinJSBridge.invoke('getBrandWCPayRequest', params, function(res){
            alert(res.err_msg)

            if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                // check notify, or query
            }
            if(res.err_msg == "get_brand_wcpay_request:cancel") {
            }
            if(res.err_msg == "get_brand_wcpay_request:fail") {
                alert("支付失败.")
            }
        });
    });

}, false)

验证notify

python端

import version2

version2.verify_notify_string(request_string)
返回True或者False

wechat_pay_py's People

Contributors

r0uter avatar richfisher avatar

Watchers

 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.