wxpay

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2016 License: MIT Imports: 14 Imported by: 0

README

微信支付商户平台SDK for Go

GoDoc Build Status

这是一个使用Go语言编写的微信支付商户平台SDK

举个栗子

以查询企业付款API为栗

package main

import (
	"log"

	"github.com/go-with/wxpay"
)

const (
	appId  = "" // 微信公众平台应用ID
	mchId  = "" // 微信支付商户平台商户号
	apiKey = "" // 微信支付商户平台API密钥

	// 微信支付商户平台证书路径
	certFile   = "cert/apiclient_cert.pem"
	keyFile    = "cert/apiclient_key.pem"
	rootcaFile = "cert/rootca.pem"
)

func main() {
	c := wxpay.NewClient(appId, mchId, apiKey)

	// 附着商户证书
	err := c.WithCert(certFile, keyFile, rootcaFile)
	if err != nil {
		log.Fatal(err)
	}

	params := make(wxpay.Params)
	// 查询企业付款接口请求参数
	params.SetString("appid", c.AppId)
	params.SetString("mch_id", c.MchId)
	params.SetString("nonce_str", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS")  // 随机字符串
	params.SetString("partner_trade_no", "10000098201411111234567890") // 商户订单号
	params.SetString("sign", c.Sign(params))                           // 签名

	// 查询企业付款接口请求URL
	url := "https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo"

	// 发送查询企业付款请求
	ret, err := c.Post(url, params, true)
	if err != nil {
		log.Fatal(err)
	}

	log.Print(ret)
}

相关链接

微信支付商户平台

微信支付商户平台开发者文档

微信支付商户平台API错误码查询

许可协议

The MIT License (MIT)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	AppId  string
	MchId  string
	ApiKey string
	// contains filtered or unexported fields
}

API客户端

func NewClient

func NewClient(appId, mchId, apiKey string) *Client

实例化API客户端

func (*Client) CheckSign added in v1.1.0

func (c *Client) CheckSign(params Params) bool

验证签名

func (*Client) Decode

func (c *Client) Decode(r io.Reader) Params

XML解码

func (*Client) Encode

func (c *Client) Encode(params Params) io.Reader

XML编码

func (*Client) Post

func (c *Client) Post(url string, params Params, tls bool) (Params, error)

发送请求

func (*Client) SetTimeout added in v1.2.0

func (c *Client) SetTimeout(d time.Duration)

设置请求超时时间

func (*Client) Sign

func (c *Client) Sign(params Params) string

生成签名

func (*Client) WithCert

func (c *Client) WithCert(certFile, keyFile, rootcaFile string) error

附着商户证书

type Params

type Params map[string]string

func (Params) GetInt64

func (p Params) GetInt64(k string) int64

func (Params) GetString

func (p Params) GetString(k string) string

func (Params) SetInt64

func (p Params) SetInt64(k string, i int64)

func (Params) SetString

func (p Params) SetString(k, s string)

Jump to

Keyboard shortcuts

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