pays_with_go

package module
v0.0.0-...-c10a5fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 12 Imported by: 0

README

golang支付合集(包括微信支付,支付宝,后期会加入聚合支付)喜欢的朋友star一下吧~

tips:作者新书《零基础Go语言算法实战》出版了,欢迎京东当当购买!

免费开源代码库:https://gitee.com/shirdonl/goAlgorithms
(当当(🔥🔥🔥🔥🔥🔥 活动抢购中):https://product.dangdang.com/11726270217.html
(京东(🔥🔥🔥🔥🔥🔥 活动抢购中):https://item.jd.com/14101229.html

tips:作者《Go Web编程实战派》出版了,欢迎京东当当购买!

(京东(🔥🔥🔥🔥🔥🔥活动抢购中......):https://item.jd.com/13200972.html
(当当(🔥🔥🔥🔥🔥🔥活动抢购中......):http://product.dangdang.com/29225055.html

tips:作者《Go语言高级开发与实战》出版了,欢迎京东当当购买!

(当当(🔥🔥🔥🔥🔥🔥 活动抢购中......):http://product.dangdang.com/29359572.html
(京东(🔥🔥🔥🔥🔥🔥 活动抢购中......):https://item.jd.com/13594166.html
  • golang支付库 想必gopher们都会抱怨go成熟的包太少,特别是go语言支付这块,网上的代码基本没有能用的,要么不全,要么有硬伤,所以结合网上和自己经验,抽出时间写的一部分代码,封装下分享出来,希望能给大家一点借鉴意义。原创不易,喜欢的朋友star一下吧~

  • 支持的支付方式 目前支持微信app,支付宝网页版,支付宝app。要是谁有新的支付方式也可以合并。

  • 项目开源协议:MIT

  • github地址:https://github.com/shirdonliao/pays_with_go

  • 使用方法

  • 1.git clone https://gitee.com/shirdonl/pays_with_go.git 或者 go get gitee.com/shirdonl/pays_with_go
  • 2.在自己的项目里调用,示例代码如下,确保填入自己的配置参数,开发中有问题欢迎留言或者关注公众号:codebigdata
package main

import (
    "fmt"
    "gitee.com/shirdonl/pays_with_go"
	"gitee.com/shirdonl/pays_with_go/client"
	"gitee.com/shirdonl/pays_with_go/common"
	"gitee.com/shirdonl/pays_with_go/constant"
	"net/http"
)
func main() {
	//设置支付宝账号信息
	initClient()
	//设置回调函数
	initHandle()

	//支付
	charge := new(common.Charge)
	charge.PayMethod = constant.ALI_APP                              //支付方式
	charge.MoneyFee = 1                                   // 支付钱单位分
	charge.Describe = "测试订单"                                    //支付描述
	charge.TradeNum = "88888888"                                  //交易号
	charge.CallbackURL = "http://127.0.0.1/callback/aliappcallback" //回调地址必须跟下面一样
    //导入包
	fdata, err := pays_with_go.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 := pays_with_go.AliAppCallback(w, r)
		if err != nil {
			fmt.Println(err)
			//log.xxx
			return
		}
		//接下来处理自己的逻辑
		fmt.Println(aliResult)
	})
}

关注公众号:源码大数据,获取海量精品教程和源码。 输入图片说明

Documentation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL