You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.1 KiB
126 lines
3.1 KiB
package payplus |
|
|
|
import ( |
|
"errors" |
|
"fmt" |
|
"net/http" |
|
"server/common" |
|
"server/modules/pay/base" |
|
"server/modules/pay/values" |
|
"server/pb" |
|
|
|
"github.com/gogo/protobuf/proto" |
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
func NewSub(b *base.Base) { |
|
sub := &Sub{ |
|
Base: b, |
|
} |
|
b.SignKey = key |
|
b.HttpType = base.HttpTypeForm |
|
b.ShouldSignUpper = true |
|
b.Channel = values.PayPlus |
|
if b.Opt == 1 { |
|
b.Resp = new(PayReq) |
|
b.ReqURL = payApi |
|
} else if b.Opt == 2 { |
|
b.Resp = new(WithdrawReq) |
|
b.ReqURL = withdrawApi |
|
} else if b.Opt == 3 { |
|
b.SignPassStr = []string{"sign"} |
|
b.CallbackResp.Msg = "SUCCESS" |
|
b.CallbackReq = new(PayCallbackReq) |
|
} else if b.Opt == 4 { |
|
b.SignPassStr = []string{"sign", "msg"} |
|
b.CallbackResp.Msg = "SUCCESS" |
|
b.CallbackReq = new(WithdrawCallbackReq) |
|
} |
|
b.Sub = sub |
|
} |
|
|
|
type Sub struct { |
|
Base *base.Base |
|
} |
|
|
|
func (s *Sub) PackHeader(header http.Header) { |
|
// header.Set("Merchant-Id", config.GetConfig().Pay.IGeek.MID) |
|
} |
|
|
|
func (s *Sub) PackReq() interface{} { |
|
if s.Base.Opt == 1 { |
|
return s.PackPayReq() |
|
} |
|
return s.PackWithdrawReq() |
|
} |
|
|
|
func (s *Sub) GetResp() (proto.Message, error) { |
|
if s.Base.Opt == 1 { |
|
resp := s.Base.Resp.(*PaymentResponse) |
|
if resp.RetCode != StatusSuccess || resp.PayUrl == "" { |
|
return nil, errors.New("pay fail") |
|
} |
|
return &pb.InnerRechargeResp{APIOrderID: fmt.Sprintf("%v", resp.OrderNo), URL: resp.PayUrl, Channel: uint32(values.PayPlus)}, nil |
|
} |
|
resp := s.Base.Resp.(*PayoutResponse) |
|
if s.Base.Status == 0 && resp.RetCode != StatusSuccess { |
|
return nil, errors.New("withdraw fail") |
|
} |
|
return &pb.InnerWithdrawResp{APIOrderID: fmt.Sprintf("%v", resp.MchTransNo), Channel: uint32(values.PayPlus)}, nil |
|
} |
|
|
|
func (s *Sub) PackPayReq() interface{} { |
|
r := s.Base.PayReq |
|
send := &PayReq{ |
|
Amount: r.Amount, |
|
MchId: "", |
|
OrderNo: r.OrderID, |
|
NotifyUrl: values.GetPayCallback(values.PayPlus), |
|
} |
|
send.Sign = s.Base.SignMD5(send) |
|
return send |
|
} |
|
|
|
func (s *Sub) PackWithdrawReq() interface{} { |
|
r := s.Base.WithdrawReq |
|
if r.PayType != int64(common.PayTypeBank) { |
|
return nil |
|
} |
|
send := &WithdrawReq{ |
|
Amount: r.Amount, |
|
MchId: "", |
|
OrderNo: r.OrderID, |
|
BankCode: r.PayCode, |
|
AccountName: r.Name, |
|
AccountNo: r.CardNo, |
|
NotifyUrl: values.GetWithdrawCallback(values.PayPlus), |
|
} |
|
|
|
send.Sign = s.Base.SignMD5(send) |
|
return send |
|
} |
|
|
|
func (s *Sub) CheckSign(str string) bool { |
|
// str += "&key=" + key |
|
checkSign := "" |
|
s.Base.CallbackResp.Msg = "SUCCESS" |
|
mySign := "" |
|
if s.Base.Opt == 3 { |
|
req := s.Base.CallbackReq.(*PayCallbackReq) |
|
log.Debug("checkSign pay:%+v", *req) |
|
checkSign = req.Sign |
|
s.Base.CallbackResp.OrderID = req.OrderNo |
|
s.Base.CallbackResp.Success = req.Status == StatusSuccess |
|
mySign = s.Base.SignMD5(req) |
|
} else if s.Base.Opt == 4 { |
|
req := s.Base.CallbackReq.(*WithdrawCallbackReq) |
|
log.Debug("checkSign withdraw:%+v", *req) |
|
checkSign = req.Sign |
|
s.Base.CallbackResp.OrderID = req.OrderNo |
|
s.Base.CallbackResp.Success = req.Status == StatusSuccess |
|
s.Base.CallbackResp.APIOrderID = req.TradeNo |
|
s.Base.CallbackResp.FailMessage = "" |
|
mySign = s.Base.SignMD5(req) |
|
} |
|
return mySign == checkSign |
|
}
|
|
|