105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
package localjx
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
"crypto/x509"
|
|
"encoding/json"
|
|
"encoding/pem"
|
|
"os"
|
|
"time"
|
|
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/tonglianpayapi"
|
|
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
|
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayType string) (orderPay *model.OrderPay, err error) {
|
|
payCreatedAt := time.Now()
|
|
// param := &wxpayapi.CreateOrderParam{
|
|
// OutTradeNo: utils.Int64ToStr(GenPayOrderID(order)),
|
|
// Body: getOrderBrief(order),
|
|
// NotifyURL: globals.TLPayNotifyURL,
|
|
// SpbillCreateIP: ctx.GetRealRemoteIP(),
|
|
// TradeType: vendorPayType2WxpayType(vendorPayType),
|
|
// TotalFee: int(order.ActualPayPrice),
|
|
|
|
// TimeStart: wxpayapi.Time2PayTime(payCreatedAt),
|
|
// // TimeExpire: wxpayapi.Time2PayTime(payCreatedAt.Add(PayWaitingTime)),
|
|
// ProfitSharing: wxpayapi.OptYes,
|
|
// }
|
|
param := &tonglianpayapi.CreateUnitorderOrderParam{
|
|
Trxamt: int(order.ActualPayPrice),
|
|
NotifyUrl: globals.TLPayNotifyURL,
|
|
Reqsn: order.VendorOrderID,
|
|
}
|
|
|
|
if authInfo, err := ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini {
|
|
param.Acct = authInfo.GetAuthID()
|
|
}
|
|
result, err := api.TLpayAPI.CreateUnitorderOrder(param)
|
|
if err == nil {
|
|
result2 := &tonglianpayapi.PayInfo{}
|
|
json.Unmarshal([]byte(result.PayInfo), &result2)
|
|
orderPay = &model.OrderPay{
|
|
PayOrderID: param.Reqsn,
|
|
PayType: model.PayTypeTL,
|
|
VendorPayType: vendorPayType,
|
|
|
|
VendorOrderID: order.VendorOrderID,
|
|
VendorID: order.VendorID,
|
|
Status: 0,
|
|
PayCreatedAt: payCreatedAt,
|
|
PrepayID: result2.PrepayID,
|
|
CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
|
|
TotalFee: int(order.ActualPayPrice),
|
|
}
|
|
plainText, err := RSADecrypt([]byte(result2.PaySign))
|
|
result2.PaySign = string(plainText)
|
|
str, err := json.Marshal(result2)
|
|
result.PayInfo = string(str)
|
|
}
|
|
return orderPay, err
|
|
}
|
|
|
|
func RSADecrypt(pub []byte) (plainText []byte, err error) {
|
|
//打开文件
|
|
file, err := os.Open("conf/rsa_key.pem")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer file.Close()
|
|
//获取文件内容
|
|
info, _ := file.Stat()
|
|
buf := make([]byte, info.Size())
|
|
file.Read(buf)
|
|
//pem解码
|
|
block, _ := pem.Decode(buf)
|
|
//X509解码
|
|
privateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
//对密文进行解密
|
|
plainText, err = rsa.DecryptPKCS1v15(rand.Reader, privateKey.(*rsa.PrivateKey), pub)
|
|
return plainText, err
|
|
}
|
|
|
|
func OnTLPayCallback(msg *wxpayapi.CallbackMsg) (err error) {
|
|
globals.SugarLogger.Debugf("OnTLPayCallback msg:%s", utils.Format4Output(msg, true))
|
|
switch msg.MsgType {
|
|
case wxpayapi.MsgTypePay:
|
|
err = onWxpayFinished(msg.Data.(*wxpayapi.PayResultMsg))
|
|
case wxpayapi.MsgTypeRefund:
|
|
err = onWxpayRefund(msg.Data.(*wxpayapi.RefundResultMsg))
|
|
}
|
|
return err
|
|
}
|