Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dcsunny committed Aug 3, 2018
1 parent 921724a commit 9e80617
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion context/qy_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ func (ctx *Context) GetQyAccessTokenFromServer() (resQyAccessToken ResQyAccessTo
expires := resQyAccessToken.ExpiresIn - 1500
err = ctx.Cache.Set(qyAccessTokenCacheKey, resQyAccessToken.AccessToken, time.Duration(expires)*time.Second)
return
}
}
2 changes: 1 addition & 1 deletion examples/gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"fmt"

"github.com/gin-gonic/gin"
"github.com/dcsunny/wechat"
"github.com/dcsunny/wechat/message"
"github.com/gin-gonic/gin"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions material/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const (
type Media struct {
util.CommonError

Type MediaType `json:"type"`
MediaID string `json:"media_id"`
ThumbMediaID string `json:"thumb_media_id"`
CreatedAt int64 `json:"created_at"`
Type MediaType `json:"type"`
MediaID string `json:"media_id"`
ThumbMediaID string `json:"thumb_media_id"`
CreatedAt int64 `json:"created_at"`
}

//MediaUpload 临时素材上传
Expand Down
19 changes: 10 additions & 9 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type MixMessage struct {
//基本消息
MsgID int64 `xml:"MsgId"`
Content string `xml:"Content"`
Recognition string `xml:"Recognition"`
PicURL string `xml:"PicUrl"`
MediaID string `xml:"MediaId"`
Format string `xml:"Format"`
Expand All @@ -82,15 +83,15 @@ type MixMessage struct {
URL string `xml:"Url"`

//事件相关
Event EventType `xml:"Event"`
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
Latitude string `xml:"Latitude"`
Longitude string `xml:"Longitude"`
Precision string `xml:"Precision"`
MenuID string `xml:"MenuId"`
Status string `xml:"Status"`
SessionFrom string `xml:"SessionFrom"`
Event EventType `xml:"Event"`
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
Latitude string `xml:"Latitude"`
Longitude string `xml:"Longitude"`
Precision string `xml:"Precision"`
MenuID string `xml:"MenuId"`
Status string `xml:"Status"`
SessionFrom string `xml:"SessionFrom"`

ScanCodeInfo struct {
ScanType string `xml:"ScanType"`
Expand Down
25 changes: 13 additions & 12 deletions pay/pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ type Pay struct {
*context.Context
}

// Params was NEEDED when request unifiedorder
// 传入的参数,用于生成 prepay_id 的必需参数
type Params struct {
// PayParams was NEEDED when request unifiedorder
type PayParams struct {
TotalFee string
CreateIP string
Body string
OutTradeNo string
OpenID string
}

// Config 是传出用于 jsdk 用的参数
type Config struct {
// PayConfig 是传出用于 jsdk 用的参数
type PayConfig struct {
Timestamp int64
NonceStr string
PrePayID string
Expand Down Expand Up @@ -65,13 +65,13 @@ type payRequest struct {
OutTradeNo string `xml:"out_trade_no"` //商户订单号
FeeType string `xml:"fee_type,omitempty"` //标价币种
TotalFee string `xml:"total_fee"` //标价金额
SpbillCreateIP string `xml:"spbill_create_ip"` //终端IP
SpbillCreateIp string `xml:"spbill_create_ip"` //终端IP
TimeStart string `xml:"time_start,omitempty"` //交易起始时间
TimeExpire string `xml:"time_expire,omitempty"` //交易结束时间
GoodsTag string `xml:"goods_tag,omitempty"` //订单优惠标记
NotifyURL string `xml:"notify_url"` //通知地址
NotifyUrl string `xml:"notify_url"` //通知地址
TradeType string `xml:"trade_type"` //交易类型
ProductID string `xml:"product_id,omitempty"` //商品ID
ProductId string `xml:"product_id,omitempty"` //商品ID
LimitPay string `xml:"limit_pay,omitempty"` //
OpenID string `xml:"openid,omitempty"` //用户标识
SceneInfo string `xml:"scene_info,omitempty"` //场景信息
Expand All @@ -83,8 +83,8 @@ func NewPay(ctx *context.Context) *Pay {
return &pay
}

// PrePayID will request wechat merchant api and request for a pre payment order id
func (pcf *Pay) PrePayID(p *Params) (prePayID string, err error) {
// PrePayId will request wechat merchant api and request for a pre payment order id
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
nonceStr := util.RandomStr(32)
tradeType := "JSAPI"
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s&notify_url=%s&openid=%s&out_trade_no=%s&spbill_create_ip=%s&total_fee=%s&trade_type=%s&key=%s"
Expand All @@ -98,8 +98,8 @@ func (pcf *Pay) PrePayID(p *Params) (prePayID string, err error) {
Body: p.Body,
OutTradeNo: p.OutTradeNo,
TotalFee: p.TotalFee,
SpbillCreateIP: p.CreateIP,
NotifyURL: pcf.PayNotifyURL,
SpbillCreateIp: p.CreateIP,
NotifyUrl: pcf.PayNotifyURL,
TradeType: tradeType,
OpenID: p.OpenID,
}
Expand All @@ -118,6 +118,7 @@ func (pcf *Pay) PrePayID(p *Params) (prePayID string, err error) {
return payRet.PrePayID, nil
}
return "", errors.New(payRet.ErrCode + payRet.ErrCodeDes)
} else {
return "", errors.New("[msg : xmlUnmarshalError] [rawReturn : " + string(rawRet) + "] [params : " + str + "] [sign : " + sign + "]")
}
return "", errors.New("[msg : xmlUnmarshalError] [rawReturn : " + string(rawRet) + "] [params : " + str + "] [sign : " + sign + "]")
}
2 changes: 1 addition & 1 deletion util/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func decodeNetworkByteOrder(orderBytes []byte) (n uint32) {
uint32(orderBytes[3])
}

// MD5Sum 计算 32 位长度的 MD5 sum
// 计算 32 位长度的 MD5 sum
func MD5Sum(txt string) (sum string) {
h := md5.New()
buf := bufio.NewWriterSize(h, 128)
Expand Down

0 comments on commit 9e80617

Please sign in to comment.