pay result
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package financial
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -18,6 +22,10 @@ import (
|
||||
|
||||
const (
|
||||
CashPercentage = 90
|
||||
|
||||
sigKey = "sign"
|
||||
sigTypeMd5 = "MD5"
|
||||
sigTypeSha256 = "HMAC-SHA256"
|
||||
)
|
||||
|
||||
func (p *PayHandler) CreatePay() (err error) {
|
||||
@@ -58,7 +66,24 @@ func (p *PayHandler) CreatePay() (err error) {
|
||||
}
|
||||
result, err := api.WxpayAPI.CreateUnifiedOrder(param)
|
||||
if err == nil {
|
||||
p.WxPayResult = result
|
||||
param2 := utils.Struct2FlatMap(param)
|
||||
param2["prepayid"] = result.PrepayID
|
||||
param2["noncestr"] = utils.GetUUID()
|
||||
param2["timestamp"] = time.Now().Unix()
|
||||
param2["package"] = "Sign=WXPay"
|
||||
param2["partnerid"] = result.MchID
|
||||
param2["appid"] = result.AppID
|
||||
sign := signParam(sigTypeMd5, param2)
|
||||
wxPay := &WxPayParam{
|
||||
Prepayid: param2["prepayid"].(string),
|
||||
Noncestr: param2["noncestr"].(string),
|
||||
Timestamp: param2["timestamp"].(string),
|
||||
Package: param2["package"].(string),
|
||||
Partnerid: param2["partnerid"].(string),
|
||||
Appid: param2["appid"].(string),
|
||||
Sign: sign,
|
||||
}
|
||||
p.WxPayParam = wxPay
|
||||
p.Order.PrepayID = result.PrepayID
|
||||
p.Order.Comment = result.CodeURL
|
||||
_, err = dao.UpdateEntity(dao.GetDB(), p.Order, "PrepayID", "Comment")
|
||||
@@ -69,6 +94,32 @@ func (p *PayHandler) CreatePay() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func signParam(signType string, params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
valueList = append(valueList, fmt.Sprintf("key=%s", globals.WxpayAppKey))
|
||||
sig = strings.Join(valueList, "&")
|
||||
var binSig []byte
|
||||
if signType == sigTypeSha256 {
|
||||
mac := hmac.New(sha256.New, []byte(globals.WxpayAppKey))
|
||||
mac.Write([]byte(sig))
|
||||
binSig = mac.Sum(nil)
|
||||
} else {
|
||||
binSig2 := md5.Sum([]byte(sig))
|
||||
binSig = binSig2[:]
|
||||
}
|
||||
sig = fmt.Sprintf("%X", binSig)
|
||||
// baseapi.SugarLogger.Debug(sig)
|
||||
return sig
|
||||
}
|
||||
|
||||
func (p *PayHandler) CreateRefund() (err error) {
|
||||
switch p.PayType {
|
||||
case model.PayTypeTL:
|
||||
|
||||
@@ -3,8 +3,6 @@ package financial
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
@@ -19,7 +17,17 @@ type PayHandler struct {
|
||||
Order *model.Order
|
||||
VendorPayType string
|
||||
|
||||
WxPayResult *wxpayapi.CreateOrderResult `json:"wxPayResult"`
|
||||
WxPayParam *WxPayParam `json:"wxPayParam"`
|
||||
}
|
||||
|
||||
type WxPayParam struct {
|
||||
Prepayid string `json:"Prepayid"`
|
||||
Noncestr string `json:"Noncestr"`
|
||||
Timestamp string `json:"Timestamp"`
|
||||
Package string `json:"Package"`
|
||||
Partnerid string `json:"Partnerid"`
|
||||
Appid string `json:"Appid"`
|
||||
Sign string `json:"Sign"`
|
||||
}
|
||||
|
||||
type PayHandlerInterface interface {
|
||||
|
||||
@@ -40,6 +40,7 @@ var (
|
||||
GetYLYTokenURL string
|
||||
GetPushTokenURL string
|
||||
GetWeimobTokenURL string
|
||||
WxpayAppKey string
|
||||
|
||||
StoreName string
|
||||
StoreNameMtwm string
|
||||
@@ -128,6 +129,7 @@ func Init() {
|
||||
EnableWXAuth2 = true // beego.BConfig.RunMode == "beta"
|
||||
DisableWXAuth1 = true
|
||||
|
||||
WxpayAppKey = beego.AppConfig.DefaultString("wxpayAppKey", "")
|
||||
WxpayNotifyURL = beego.AppConfig.DefaultString("wxpayNotifyURL", "")
|
||||
TLPayNotifyURL = beego.AppConfig.DefaultString("tonglianPayNotifyURL", "")
|
||||
JdOrgCode = beego.AppConfig.DefaultString("jdOrgCode", "")
|
||||
|
||||
Reference in New Issue
Block a user