native

package
v0.0.0-...-f5adc6c Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2014 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

定义微信支付 native api 相关的数据结构和 helper 函数

Index

Constants

View Source
const (
	SIGN_METHOD_SHA1 = "sha1"

	IS_SUBSCRIBE_TRUE  = 1
	IS_SUBSCRIBE_FALSE = 0
)

Variables

This section is empty.

Functions

func NativeURL

func NativeURL(appId, nonceStr string, timestamp int64,
	productId, paySignKey string) string

生成 native 支付 URL.

@appId:      必须, 公众号 id
@nonceStr:   必须, 32个字符以内, 商户生成的随机字符串
@timestamp:  必须, unixtime, 商户生成
@productId:  必须, 32个字符以内, 商户需要定义并维护自己的商品id, 这个id与一张订单等价, 微信后台凭借该id通过POST商户后台获取交易必须信息;
@paySignKey: 必须, 公众号支付请求中用于加密的密钥 Key

Types

type BillRequest

type BillRequest struct {
	XMLName struct{} `xml:"xml" json:"-"`

	AppId     string `xml:"AppId"`     // 必须, 公众帐号的 appid
	NonceStr  string `xml:"NonceStr"`  // 必须, 随机串
	TimeStamp int64  `xml:"TimeStamp"` // 必须, 时间戳

	ProductId string `xml:"ProductId"` // 必须, 第三方的商品 id 号

	OpenId      string `xml:"OpenId"`      // 必须, 点击链接准备购买商品的用户 OpenId
	IsSubscribe int    `xml:"IsSubscribe"` // 必须, 标记用户是否订阅该公众帐号, 1为关注, 0为未关注

	Signature  string `xml:"AppSignature"` // 必须, 参数的加密签名
	SignMethod string `xml:"SignMethod"`   // 必须, 签名方式, 目前只支持 "sha1", 该字段不参与签名
}

公众平台接到用户点击 Native 支付 URL 之后, 会调用注册时填写的商户获取订单 Package 的回调 URL. 微信公众平台调用时会使用POST方式, 这是推送的 xml 格式的数据结构.

func (*BillRequest) Check

func (req *BillRequest) Check(paySignKey string) (err error)

检查 req *BillRequest 是否合法(包括签名的检查), 合法返回 nil, 否则返回错误信息.

@paySignKey: 公众号支付请求中用于加密的密钥 Key, 对应于支付场景中的 appKey

type BillResponse

type BillResponse struct {
	XMLName struct{} `xml:"xml" json:"-"`

	AppId     string `xml:"AppId"`     // 必须, 公众帐号的 appid
	NonceStr  string `xml:"NonceStr"`  // 必须, 随机串
	TimeStamp int64  `xml:"TimeStamp"` // 必须, 时间戳

	Package string `xml:"Package"` // 必须, 订单详情组合成的字符串, 4096个字符以内, see ../Bill.Package

	// 可以自己定义错误信息
	ErrCode int    `xml:"RetCode"`   // 可选, 0 表示正确
	ErrMsg  string `xml:"RetErrMsg"` // 可选, 错误信息, 要求 utf8 编码格式

	Signature  string `xml:"AppSignature"` // 必须, 该 BillResponse 自身的签名. see BillResponse.SetSignature
	SignMethod string `xml:"SignMethod"`   // 必须, 签名方式, 目前只支持 "sha1"
}

公众平台接到用户点击 Native 支付 URL 之后, 会调用注册时填写的商户获取订单 Package 的回调 URL. 这是获取订单详情 package 的回复消息数据结构.

func (*BillResponse) SetSignature

func (resp *BillResponse) SetSignature(paySignKey string) (err error)

设置签名字段.

@paySignKey: 公众号支付请求中用于加密的密钥 Key, 对应于支付场景中的 appKey
NOTE: 要求在 resp *BillResponse 其他字段设置完毕后才能调用这个函数, 否则签名就不正确.

Jump to

Keyboard shortcuts

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