js

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: 5 Imported by: 0

Documentation

Overview

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

NOTE: 要求微信 5.0+(包括5.0)

Index

Constants

View Source
const (
	SIGN_METHOD_SHA1 = "SHA1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EditAddressParameters

type EditAddressParameters struct {
	AppId     string `json:"appId"`            // 公众号 id
	NonceStr  string `json:"nonceStr"`         // 随机字符串
	TimeStamp int64  `json:"timeStamp,string"` // 时间戳, unixtime

	Scope string `json:"scope"` // 填写"jsapi_address", 获得编辑地址权限

	Signature  string `json:"addrSign"` // 签名
	SignMethod string `json:"signType"` // 签名方式, 目前仅支持SHA1
}

js api 编辑并获取收货地址 editAddress 的参数.

在前端 js 中这样调用:
WeixinJSBridge.invoke(
    'editAddress',
    {
        "appId" : getAppId(),
        "scope" : "jsapi_address",
        "signType" : "sha1",
        "addrSign" : "xxxxx",
        "timeStamp" : "12345",
        "nonceStr" : "10000",
    },
    function(res) {
        // 若res 中所带的返回值不为空,则表示用户选择该返回值作为收货地址。
        // 否则若返回空,则表示用户取消了这一次编辑收货地址。
        document.form1.address1.value = res.proviceFirstStageName;
        document.form1.address2.value = res.addressCitySecondStageName;
        document.form1.address3.value = res.addressCountiesThirdStageName;
        document.form1.detail.value = res.addressDetailInfo;
        document.form1.phone.value = res.telNumber;
    }
});

func (*EditAddressParameters) SetSignature

func (para *EditAddressParameters) SetSignature(url, oauth2AccessToken string) (err error)

设置签名字段.

@url:               当前网页的 URL
@oauth2AccessToken: oauth2 用户授权凭证
NOTE: 要求在 para *EditAddressParameters 其他字段设置完毕后才能调用这个函数, 否则签名就不正确.

type PayRequestParameters

type PayRequestParameters struct {
	AppId     string `json:"appId"`            // 必须, 公众号 id
	NonceStr  string `json:"nonceStr"`         // 必须, 商户生成的随机字符串, 32个字符以内
	TimeStamp int64  `json:"timeStamp,string"` // 必须, unixtime, 商户生成

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

	Signature  string `json:"paySign"`  // 必须, 该 PayRequestParameters 自身的签名. see PayRequestParameters.SetSignature
	SignMethod string `json:"signType"` // 必须, 签名方式, 目前仅支持 SHA1
}

js api 微信支付接口 getBrandWCPayRequest 的参数.

在前端 js 中这样调用:
WeixinJSBridge.invoke(
    'getBrandWCPayRequest',
    {
        "appId" : "wxf8b4f85f3a794e77",
        "timeStamp" : "189026618",
        "nonceStr" : "adssdasssd13d",
        "package" : "bank_type=WX&body=XXX&fee_type=1&input_charset=GBK&notify_url=http%3a%2f%2fwww.qq.com&out_trade_no=16642817866003386000&partner=1900000109&spbill_create_ip=127.0.0.1&total_fee=1&sign=BEEF37AD19575D92E191C1E4B1474CA9",
        "signType" : "SHA1",
        "paySign" : "7717231c335a05165b1874658306fa431fe9a0de"
    },
    function(res){
        // 返回 res.err_msg,取值
        // get_brand_wcpay_request:cancel 用户取消
        // get_brand_wcpay_request:fail 发送失败
        // get_brand_wcpay_request:ok 发送成功
        WeixinJSBridge.log(res.err_msg);
        alert(res.err_code+res.err_desc);
    }
);

func (*PayRequestParameters) SetSignature

func (para *PayRequestParameters) SetSignature(paySignKey string) (err error)

设置签名字段.

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

Jump to

Keyboard shortcuts

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