通联宝支付测试

This commit is contained in:
苏尹岚
2020-02-27 14:33:36 +08:00
parent cc5e35caa6
commit a782f2ad49
2 changed files with 16 additions and 14 deletions

View File

@@ -6,7 +6,8 @@ import (
"crypto/x509"
"encoding/json"
"encoding/pem"
"os"
"io/ioutil"
"strings"
"time"
"git.rosy.net.cn/jx-callback/globals"
@@ -37,7 +38,7 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
if err == nil {
var result2 tonglianpayapi.PayInfo
json.Unmarshal([]byte(result.PayInfo), &result2)
globals.SugarLogger.Debugf("pay4OrderByTL, [%v]", result2)
prePayID := result2.Package[strings.LastIndex(result2.Package, "=")+1 : len(result2.Package)]
orderPay = &model.OrderPay{
PayOrderID: param.Reqsn,
PayType: model.PayTypeTL,
@@ -47,31 +48,33 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
VendorID: order.VendorID,
Status: 0,
PayCreatedAt: payCreatedAt,
PrepayID: result2.PrepayID,
PrepayID: prePayID,
CodeURL: utils.LimitUTF8StringLen(result.PayInfo, 3200),
TotalFee: int(order.ActualPayPrice),
}
plainText, err2 := RSADecrypt([]byte(result2.PaySign))
result2.PaySign = string(plainText)
globals.SugarLogger.Debugf("pay4OrderByTL2, [%v]", string(plainText))
str, err2 := json.Marshal(result2)
result.PayInfo = string(str)
err = err2
}
globals.SugarLogger.Debugf("pay4OrderByTL2, [%v]", *result)
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)
// 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)
buf, err := ioutil.ReadFile("conf/rsa_key.pem")
globals.SugarLogger.Debugf("pay4OrderByTL3, [%v]", string(buf))
//pem解码
block, _ := pem.Decode(buf)
//X509解码