Skip to content

Commit

Permalink
优化返回信息
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-lee committed Jul 18, 2020
1 parent e4fd3bc commit bf27bce
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 79 deletions.
4 changes: 2 additions & 2 deletions wechat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (self ConfigPay) CreatePayOrder() (res interface{}) {
if resPay.ReturnCode == CODE_SUCCESS && resPay.ResultCode == CODE_SUCCESS {
switch self.Source {
case SOURCE_APP:
res = newTwoSignApp(resPay.PrepayId)
res = newTwoSignApp(self.OutTradeNo, resPay.PrepayId)
case SOURCE_APPLET:
res = newTwoSignApplet(resPay.PrepayId)
res = newTwoSignApplet(self.OutTradeNo, resPay.PrepayId)
//case jsapi支付: //TODO 需要实现

//case h5支付: //TODO 需要实现
Expand Down
35 changes: 0 additions & 35 deletions wechat/payApp.go

This file was deleted.

29 changes: 0 additions & 29 deletions wechat/payApplet.go

This file was deleted.

13 changes: 0 additions & 13 deletions wechat/payApplet_test.go

This file was deleted.

37 changes: 37 additions & 0 deletions wechat/pay_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package wechat

import (
"fmt"
"github.com/lucky-lee/gutil/gStr"
"time"
)

//二次签名支付配置
type TwoSignApp struct {
AppId string `json:"app_id" xml:"appid"`
NonceStr string `json:"nonce_str" xml:"noncestr"`
packAge string `json:"package" xml:"package"`
PartnerId string `json:"partner_id" xml:"partnerid"`
PrepayId string `json:"prepay_id" xml:"prepayid"`
Timestamp string `json:"timestamp" xml:"timestamp"`
Sign string `json:"sign" xml:"-"`
PackageVal string `json:"package_val" xml:"-"`
OrderId string `json:"order_id"` //订单id
}

//生成-二次签名-配置
func newTwoSignApp(orderId, prepayId string) (res TwoSignApp) {
pVal := "Sign=WXPay"

res.AppId = AppId()
res.PartnerId = MchId()
res.PrepayId = prepayId
res.NonceStr = gStr.RandStr(32)
res.Timestamp = fmt.Sprintf("%d", time.Now().Unix())
res.packAge = pVal
res.PackageVal = pVal
res.Sign = toSign(res)
res.OrderId = orderId

return
}
31 changes: 31 additions & 0 deletions wechat/pay_applet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package wechat

import (
"fmt"
"github.com/lucky-lee/gutil/gStr"
"time"
)

type TwoSignApplet struct {
AppId string `json:"app_id" xml:"appId"` //应用id
NonceStr string `json:"nonce_str" xml:"nonceStr"` //随机字符串 不长于32位
Package string `json:"package" xml:"package"` //数据包
SignType string `json:"sign_type" xml:"signType"` //签名方式
Timestamp string `json:"timestamp" xml:"timeStamp"` //时间戳

PaySign string `json:"pay_sign" xml:"-"` //
OrderId string `json:"order_id"` //订单id
}

//生成 二次签名 配置
func newTwoSignApplet(orderId, prepayId string) (res TwoSignApplet) {
res.AppId = AppId()
res.Timestamp = fmt.Sprintf("%d", time.Now().Unix())
res.NonceStr = gStr.RandStr(32)
res.Package = fmt.Sprintf("prepay_id=%s", prepayId)
res.SignType = "MD5"
res.PaySign = toSign(res)
res.OrderId = orderId

return
}

0 comments on commit bf27bce

Please sign in to comment.