Giter Club home page Giter Club logo

gopay's Introduction

golang语言实现的支付库

最近在搞支付这块,但是网上的代码基本没有能用的,要么不全,要么有硬伤,所以最后还是自己接了。抽出写的一部分代码,封装下分享出来,希望能给大家一点借鉴意义。

支持的支付方式

目前支持微信公众号,微信app,微信小程序,支付宝网页版,支付宝app。要是谁有新的支付方式也可以合并。

使用方法

package main

import (
	"fmt"
	"github.com/wangwei-go/gopay"
	"github.com/wangwei-go/gopay/client"
	"github.com/wangwei-go/gopay/common"
	"github.com/wangwei-go/gopay/constant"
	"net/http"
)

//支付宝举例
func main() {
	//设置支付宝账号信息
	initClient()
	//设置回调函数
	initHandle()

	//支付
	charge := new(common.Charge)
	charge.PayMethod = constant.WECHAT                              //支付方式
	charge.MoneyFee = 1                                             // 支付钱单位分
	charge.Describe = "test pay"                                    //支付描述
	charge.TradeNum = "1111111111"                                  //交易号
	charge.CallbackURL = "http://127.0.0.1/callback/aliappcallback" //回调地址必须跟下面一样

	fdata, err := gopay.Pay(charge)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(fdata)
}

func initClient() {
	client.InitAliAppClient(&client.AliAppClient{
		PartnerID:  "xxx",
		SellerID:   "xxxx",
		AppID:      "xxx",
		PrivateKey: nil,
		PublicKey:  nil,
	})
}

func initHandle() {
	http.HandleFunc("callback/aliappcallback", func(w http.ResponseWriter, r *http.Request) {
		//返回支付结果
		aliResult, err := gopay.AliAppCallback(w, r)
		if err != nil {
			fmt.Println(err)
			//log.xxx
			return
		}
		//接下来处理自己的逻辑
		fmt.Println(aliResult)
	})
}

gopay's People

Contributors

milkbobo avatar wangwei123 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.