当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 97

开发团队 / 微信Go SDK
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client_sandbox_sign.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
shallot 提交于 2019-07-17 19:33 . 添加授权码查询openid接口。
package wechat
import (
"encoding/xml"
"errors"
)
// 获取沙盒签名Key的返回值
type getSignKeyResponse struct {
ResponseModel
Retcode string `xml:"retcode"`
MchId string `xml:"mch_id"`
SandboxSignkey string `xml:"sandbox_signkey"`
}
// 获取沙盒的签名
func (c *Client) sandboxSign(nonceStr string, signType string) (key string, err error) {
body := make(BodyMap)
body["mch_id"] = c.config.MchId
body["nonce_str"] = nonceStr
// 计算沙箱参数Sign
sanboxSign := c.localSign(body, signType, c.apiKey)
// 沙箱环境:获取key后,重新计算Sign
key, err = c.getSandBoxSignKey(nonceStr, sanboxSign)
return
}
// 调用微信提供的接口获取SandboxSignkey
func (c *Client) getSandBoxSignKey(nonceStr string, sign string) (key string, err error) {
params := make(map[string]interface{})
params["mch_id"] = c.config.MchId
params["nonce_str"] = nonceStr
params["sign"] = sign
paramXml := GenerateXml(params)
bytes, err := httpPost(baseUrlSandbox+"pay/getsignkey", paramXml)
if err != nil {
return
}
var keyResponse getSignKeyResponse
if err = xml.Unmarshal(bytes, &keyResponse); err != nil {
return
}
if keyResponse.ReturnCode == ResponseFail {
err = errors.New(keyResponse.RetMsg)
return
}
key = keyResponse.SandboxSignkey
return
}
Go
1
https://gitee.com/OAGroup/wechat.git
git@gitee.com:OAGroup/wechat.git
OAGroup
wechat
微信Go SDK
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891