Compare commits
9 Commits
ee912a204d
...
1f7d46c110
Author | SHA1 | Date |
---|---|---|
|
1f7d46c110 | |
|
7f20bf6925 | |
|
39e64c8a22 | |
|
e5f50423ad | |
|
222522dc76 | |
|
9c725163c8 | |
|
627e1c852c | |
|
342a247c67 | |
|
c9c7bdbc16 |
|
@ -2,10 +2,13 @@ package console
|
|||
|
||||
import (
|
||||
"PaymentCenter/app/constants/common"
|
||||
"PaymentCenter/app/constants/errorcode"
|
||||
"PaymentCenter/app/data"
|
||||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/http/entities/backend"
|
||||
"PaymentCenter/app/models/ordersmodel"
|
||||
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
||||
"PaymentCenter/app/models/paychannelmodel"
|
||||
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
|
||||
"PaymentCenter/app/third/paymentService"
|
||||
"PaymentCenter/app/third/paymentService/payCommon"
|
||||
|
@ -79,11 +82,10 @@ func closeOrder() {
|
|||
// 发起关闭订单请求
|
||||
response := paymentService.OrderClose(ctx, req)
|
||||
// 成功
|
||||
if response.Code == payCommon.PAY_SUCCESS_CODE {
|
||||
orderIds = append(orderIds, orderInfo.Id)
|
||||
} else {
|
||||
utils.Log(nil, "关闭订单,上游失败", response)
|
||||
if response.Code != payCommon.PAY_SUCCESS_CODE {
|
||||
utils.Log(nil, "关闭订单,上游失败", response, orderInfo.Id)
|
||||
}
|
||||
orderIds = append(orderIds, orderInfo.Id)
|
||||
}
|
||||
// 修改订单状态为关闭
|
||||
cond = builder.NewCond()
|
||||
|
@ -166,23 +168,47 @@ func queryOrder() {
|
|||
// 查询成功,校验状态
|
||||
var status int
|
||||
if result.Code == payCommon.PAY_SUCCESS_CODE {
|
||||
var msg string
|
||||
switch result.Result.TradeState {
|
||||
case "SUCCESS":
|
||||
// 成功
|
||||
status = common.ORDER_STATUS_PAYED
|
||||
msg = "支付成功"
|
||||
case "REFUND":
|
||||
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
|
||||
status = common.ORDER_STATUS_PAYED
|
||||
msg = "支付成功"
|
||||
case "NOTPAY":
|
||||
// 未支付
|
||||
return
|
||||
case "CLOSED":
|
||||
// 关闭
|
||||
status = common.ORDER_STATUS_CLOSE
|
||||
msg = "订单关闭"
|
||||
}
|
||||
// 回调通知下游 todo
|
||||
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), "")
|
||||
utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), msg)
|
||||
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||
if notifyResult.ErrCode != errorcode.Success {
|
||||
utils.Log(nil, "主动查询订单支付状态,回调下游失败", notifyResult)
|
||||
}
|
||||
payCallback, _ := json.Marshal(result)
|
||||
merchantCallback, _ := json.Marshal(notifyResult)
|
||||
|
||||
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
|
||||
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||
OrderId: orderInfo.Id,
|
||||
PayCallback: string(payCallback),
|
||||
Status: 1,
|
||||
PayParam: "",
|
||||
MerchantCallback: string(merchantCallback),
|
||||
Type: common.THIRD_ORDER_TYPE_CALL_BACK,
|
||||
}
|
||||
// 写日志
|
||||
_, err = thirdRepo.OrderThirdPayLogInsertOne(&log)
|
||||
if err != nil {
|
||||
utils.Log(nil, "主动查询订单支付状态,记录回调日志失败", log.OrderId, err)
|
||||
}
|
||||
}
|
||||
}(orderInfo)
|
||||
}
|
||||
|
@ -261,6 +287,7 @@ func queryRefundOrder() {
|
|||
var status int
|
||||
if result.Code == payCommon.PAY_SUCCESS_CODE {
|
||||
// 退款状态 0:未申请,1:退款中,2:退款成功,3:退款失败
|
||||
var msg string
|
||||
switch result.Result.RefundStatus {
|
||||
case 0:
|
||||
// 未申请
|
||||
|
@ -273,13 +300,35 @@ func queryRefundOrder() {
|
|||
case 2:
|
||||
// 退款成功
|
||||
status = common.ORDER_STATUS_PAYED
|
||||
msg = "退款成功"
|
||||
case 3:
|
||||
// 退款失败
|
||||
status = common.ORDER_STATUS_FAILED
|
||||
msg = "退款失败"
|
||||
}
|
||||
// 回调通知下游 todo
|
||||
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.RefundFee), "")
|
||||
utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
|
||||
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.RefundFee), msg)
|
||||
//utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
|
||||
if notifyResult.ErrCode != errorcode.Success {
|
||||
utils.Log(nil, "查询退款订单状态,回调下游失败", notifyResult)
|
||||
}
|
||||
payCallback, _ := json.Marshal(result)
|
||||
merchantCallback, _ := json.Marshal(notifyResult)
|
||||
|
||||
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
|
||||
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||
OrderId: orderInfo.Id,
|
||||
PayCallback: string(payCallback),
|
||||
Status: 1,
|
||||
PayParam: "",
|
||||
MerchantCallback: string(merchantCallback),
|
||||
Type: common.THIRD_ORDER_TYPE_CALL_BACK,
|
||||
}
|
||||
// 写日志
|
||||
_, err = thirdRepo.OrderThirdPayLogInsertOne(&log)
|
||||
if err != nil {
|
||||
utils.Log(nil, "查询退款订单状态,记录回调日志失败", log.OrderId, err)
|
||||
}
|
||||
}
|
||||
}(orderInfo)
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ const (
|
|||
AppSM4EncryptKeyNotFound = 1232
|
||||
AppSM4EncryptFail = 1233
|
||||
AppAesEncryptFail = 1234
|
||||
AppDeEncryptFail = 1250
|
||||
// 加密方式不存在
|
||||
EncryptTypeNotFound = 1241
|
||||
|
||||
|
@ -121,6 +122,8 @@ var MsgZH = map[int]string{
|
|||
|
||||
EncryptTypeNotFound: "加密方式不存在",
|
||||
|
||||
AppDeEncryptFail: "未知原因导致解密失败,请检查加密数据是和app加密配置",
|
||||
|
||||
PayChannelNotFound: "支付方式不存在",
|
||||
PayChannelNotBuild: "支付方式尚未开通",
|
||||
PayChannelExtJsonError: "支付方式扩展参数错误",
|
||||
|
|
|
@ -2,6 +2,7 @@ package backend
|
|||
|
||||
import (
|
||||
"PaymentCenter/app/constants/errorcode"
|
||||
"PaymentCenter/app/constants/pojo"
|
||||
"PaymentCenter/app/http/controllers"
|
||||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/http/entities/backend"
|
||||
|
@ -62,11 +63,11 @@ func GenerateDecrypt(c *gin.Context) {
|
|||
var publicKey, privateKey string
|
||||
var err error
|
||||
switch req.KeyType {
|
||||
case "sm2":
|
||||
case pojo.SM2:
|
||||
publicKey, privateKey, err = sm2.GenerateSM2Key()
|
||||
case "rsa":
|
||||
case pojo.RSA:
|
||||
publicKey, privateKey, err = rsa.GenerateKey()
|
||||
case "sm4":
|
||||
case pojo.SM4:
|
||||
privateKey, publicKey = sm4.GenerateKey()
|
||||
default:
|
||||
controllers.HandCodeRes(c, "", errorcode.EncryptTypeNotFound)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/go-playground/locales/zh"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/qit-team/snow-core/redis"
|
||||
|
@ -111,8 +112,10 @@ func GenRequest(c *gin.Context, request interface{}) (msgs []string, err error)
|
|||
if c.Request.Method == "GET" || c.Request.Method == "DELETE" {
|
||||
err = c.ShouldBindQuery(request)
|
||||
} else {
|
||||
err = c.ShouldBindJSON(request)
|
||||
err = c.ShouldBind(request)
|
||||
}
|
||||
var req, _ = sonic.Marshal(request)
|
||||
utils.Log(c, c.FullPath(), "请求参数", string(req))
|
||||
|
||||
if err == nil {
|
||||
validate := validator.New()
|
||||
|
|
|
@ -96,5 +96,5 @@ func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
|
|||
}
|
||||
|
||||
type GenerateDecryptKeyRequest struct {
|
||||
KeyType string `json:"key_type" form:"key_type" label:"密钥类型"`
|
||||
KeyType int32 `json:"key_type" form:"key_type" label:"密钥类型"`
|
||||
}
|
||||
|
|
|
@ -27,8 +27,16 @@ func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
|
|||
p.MerchantId = db.MerchantId
|
||||
p.ChannelType = db.ChannelType
|
||||
p.AppId = db.AppId
|
||||
p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05")
|
||||
p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||
if db.ExpireTime.IsZero() {
|
||||
p.ExpireTime = ""
|
||||
} else {
|
||||
p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if db.CreateTime.IsZero() {
|
||||
p.CreateTime = ""
|
||||
} else {
|
||||
p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
switch db.ChannelType {
|
||||
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
|
||||
|
|
|
@ -61,12 +61,10 @@ func Cors() gin.HandlerFunc {
|
|||
|
||||
func AdminAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
ip, _ := c.RemoteIP()
|
||||
utils.Log(c, "请求地址RemoteIP()", ip.String(), config.GetConf().AdminGate)
|
||||
clientIp := c.ClientIP()
|
||||
utils.Log(c, "请求地址clientIp", clientIp)
|
||||
utils.Log(c, "请求地址clientIp", clientIp, config.GetConf().AdminGate)
|
||||
|
||||
if config.GetConf().Debug == false && !utils.SliceInStr(ip.String(), config.GetConf().AdminGate) {
|
||||
if config.GetConf().Debug == false && !utils.SliceInStr(clientIp, config.GetConf().AdminGate) {
|
||||
c.Abort()
|
||||
controllers.HandCodeRes(c, nil, errorcode.Forbidden)
|
||||
return
|
||||
|
@ -112,7 +110,7 @@ func ValidateRequest() gin.HandlerFunc {
|
|||
handler = requestmapping.FrontRequestMapBeforeDecrypt[path]
|
||||
}
|
||||
if handler == nil {
|
||||
utils.Log(c, "path", path)
|
||||
utils.Log(c, "path", path, "未找到handler")
|
||||
controllers.HandCodeRes(c, nil, errorcode.NotFound)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -42,10 +42,7 @@ func (a *AppCheck) Check() *AppCheck {
|
|||
a.Code = errorcode.AppDisabled
|
||||
return a
|
||||
}
|
||||
if !a.App.DeleteTime.IsZero() {
|
||||
a.Code = errorcode.AppNotFound
|
||||
return a
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
|
|
|
@ -87,8 +87,5 @@ func GetAndCheckMerchant(merchant *merchantmodel.Merchant, conn builder.Cond, co
|
|||
return nil, code
|
||||
}
|
||||
|
||||
if !merchantInfo.DeleteTime.IsZero() {
|
||||
return nil, errorcode.MerchantNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -18,31 +18,31 @@ func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, t
|
|||
// 拼接查询条件
|
||||
conn := builder.NewCond()
|
||||
if req.Id > 0 {
|
||||
conn = conn.And(builder.Eq{"id": req.Id})
|
||||
conn = conn.And(builder.Eq{"orders.id": req.Id})
|
||||
}
|
||||
if req.MerchantId > 0 {
|
||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
||||
conn = conn.And(builder.Eq{"orders.merchant_id": req.MerchantId})
|
||||
}
|
||||
if req.PayChannelId > 0 {
|
||||
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
|
||||
conn = conn.And(builder.Eq{"orders.pay_channel_id": req.PayChannelId})
|
||||
}
|
||||
if req.AppId > 0 {
|
||||
conn = conn.And(builder.Eq{"app_id": req.AppId})
|
||||
conn = conn.And(builder.Eq{"orders.app_id": req.AppId})
|
||||
}
|
||||
if req.OutTreadNo != "" {
|
||||
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
|
||||
conn = conn.And(builder.Like{"orders.out_tread_no", req.OutTreadNo})
|
||||
}
|
||||
if req.Status > 0 {
|
||||
conn = conn.And(builder.Eq{"status": req.Status})
|
||||
conn = conn.And(builder.Eq{"orders.status": req.Status})
|
||||
}
|
||||
if req.OrderType > 0 {
|
||||
conn = conn.And(builder.Eq{"order_type": req.OrderType})
|
||||
conn = conn.And(builder.Eq{"orders.order_type": req.OrderType})
|
||||
}
|
||||
if !req.StartTime.IsZero() {
|
||||
conn = conn.And(builder.Gte{"start_time": req.StartTime})
|
||||
conn = conn.And(builder.Gte{"orders.create_time": req.StartTime})
|
||||
}
|
||||
if !req.EndTime.IsZero() {
|
||||
conn = conn.And(builder.Lte{"end_time": req.EndTime})
|
||||
conn = conn.And(builder.Lte{"orders.create_time": req.EndTime})
|
||||
}
|
||||
|
||||
// 调用repo
|
||||
|
|
|
@ -112,8 +112,6 @@ func GetAndCheckPayChannel(channel *paychannelmodel.PayChannel, conn builder.Con
|
|||
if code != errorcode.Success {
|
||||
return nil, code
|
||||
}
|
||||
if !channelInfo.DeleteTime.IsZero() {
|
||||
return nil, errorcode.PayChannelNotFound
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ func DeCrypt(app *appmodel.App, data string, aesKey string) ([]byte, int) {
|
|||
if errCode != apicrypt.CryptNotError {
|
||||
return nil, errCode
|
||||
}
|
||||
if len(dataByte) == 0 {
|
||||
return nil, errorcode.AppDeEncryptFail
|
||||
}
|
||||
//aesData, err := aes.Decrypt(dataByte, []byte(aesKey))
|
||||
//if err != nil {
|
||||
// return nil, errorcode.AppAesEncryptFail
|
||||
|
|
|
@ -133,10 +133,7 @@ func (o *OrderNotify) checkApp() {
|
|||
if o.Code != errorcode.Success {
|
||||
return
|
||||
}
|
||||
if o.app.DeleteTime.IsZero() {
|
||||
o.Code = errorcode.AppDisabled
|
||||
return
|
||||
}
|
||||
|
||||
if o.app.NotifyUrl == "" {
|
||||
o.Code = errorcode.AppNotifyUrlNotFound
|
||||
return
|
||||
|
@ -148,15 +145,11 @@ func (o *OrderNotify) checkApp() {
|
|||
func (o *OrderNotify) checkOrder() {
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"id": o.OrderId})
|
||||
|
||||
o.order, o.Code = services.OrderFindOne(&ordersmodel.Orders{}, cond)
|
||||
if o.Code != errorcode.Success {
|
||||
return
|
||||
}
|
||||
if o.order.DeleteTime.IsZero() {
|
||||
o.Code = errorcode.OrderIsDelete
|
||||
return
|
||||
}
|
||||
|
||||
if o.order.Status != common.ORDER_STATUS_PAYING {
|
||||
o.Code = errorcode.OrderStatusErr
|
||||
return
|
||||
|
|
|
@ -98,7 +98,7 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
|
|||
|
||||
// ALiCallBack 支付宝支付回调
|
||||
func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
|
||||
ok, err := alipay.VerifySignWithCert(aliConfig.AlipayPublicCert, notifyReq)
|
||||
ok, err := alipay.VerifySignWithCert([]byte(aliConfig.AlipayPublicCert), notifyReq)
|
||||
if !ok || err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
|
|||
// 记录日志
|
||||
go func() {
|
||||
payCallback, _ := json.Marshal(notifyReq)
|
||||
payParam := ""
|
||||
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||
payParam := "{}"
|
||||
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||
}()
|
||||
|
||||
if res.ErrCode != errorcode.Success {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"PaymentCenter/app/third/paymentService/payCommon"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/qit-team/snow-core/log/logger"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -77,10 +78,10 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
|
|||
// 记录日志
|
||||
go func() {
|
||||
orderId := payOrderRequest.OrderId
|
||||
payCallback := info
|
||||
payCallback := fmt.Sprintf("{%s}", info)
|
||||
payParam, _ := json.Marshal(payOrderRequest)
|
||||
merchantCallback, _ := json.Marshal(payOrderResponse)
|
||||
saveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
|
||||
SaveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
|
||||
}()
|
||||
return payOrderResponse
|
||||
}
|
||||
|
@ -143,7 +144,7 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
|
|||
payCallback, _ := json.Marshal(info)
|
||||
payParam, _ := json.Marshal(payOrderQueryRequest)
|
||||
merchantCallback, _ := json.Marshal(payOrderQueryResponse)
|
||||
saveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||
SaveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||
}()
|
||||
return payOrderQueryResponse
|
||||
}
|
||||
|
@ -207,7 +208,7 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
|
|||
payCallback, _ := json.Marshal(info)
|
||||
payParam, _ := json.Marshal(orderRefundRequest)
|
||||
merchantCallback, _ := json.Marshal(orderRefundResponse)
|
||||
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
|
||||
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
|
||||
}()
|
||||
|
||||
return orderRefundResponse
|
||||
|
@ -259,7 +260,7 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
|
|||
payCallback, _ := json.Marshal(info)
|
||||
payParam, _ := json.Marshal(orderRefundQueryRequest)
|
||||
merchantCallback, _ := json.Marshal(orderRefundQueryResponse)
|
||||
saveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
|
||||
}()
|
||||
|
||||
return orderRefundQueryResponse
|
||||
|
@ -315,14 +316,14 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
|
|||
payCallback, _ := json.Marshal(info)
|
||||
payParam, _ := json.Marshal(orderCloseRequest)
|
||||
merchantCallback, _ := json.Marshal(orderCloseResponse)
|
||||
saveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
|
||||
SaveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
|
||||
}()
|
||||
|
||||
return orderCloseResponse
|
||||
}
|
||||
|
||||
// saveLog 记录操作日志
|
||||
func saveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
|
||||
// SaveLog 记录操作日志
|
||||
func SaveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
|
||||
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
|
||||
log := orderthirdpaylogmodel.OrderThirdPayLog{
|
||||
OrderId: orderId,
|
||||
|
|
|
@ -165,8 +165,8 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
|
|||
// 记录日志
|
||||
go func() {
|
||||
payCallback, _ := json.Marshal(CallBackInfo)
|
||||
payParam := ""
|
||||
saveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||
payParam := "{}"
|
||||
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
|
||||
}()
|
||||
|
||||
if res.ErrCode != errorcode.Success {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// parseRSAPublicKeyFromPEM 解析PEM编码的RSA公钥
|
||||
|
@ -136,5 +137,9 @@ func GenerateKey() (string, string, error) {
|
|||
Bytes: derPkix,
|
||||
}
|
||||
pubPem := pem.EncodeToMemory(pubBlock)
|
||||
return string(pubPem), string(privPem), nil
|
||||
pri := strings.Replace(string(privPem), "-----BEGIN RSA PRIVATE KEY-----\n", "", -1)
|
||||
pri = strings.Replace(pri, "\n-----END RSA PRIVATE KEY-----\n", "", -1)
|
||||
pub := strings.Replace(string(pubPem), "-----BEGIN PUBLIC KEY-----\n", "", -1)
|
||||
pub = strings.Replace(pub, "\n-----END PUBLIC KEY-----\n", "", -1)
|
||||
return pub, pri, nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
const (
|
||||
SELF_PRI = "BD13D44C74422F80ADDF54AD2DE2888C4092AF6F61E41FABADA6C47F17574A41"
|
||||
|
||||
SELF_PUB = "04363DF574D4FE34EE58FB8A3F7CB08E6CA5EBB3B7335CBAE10A2900551F6450AB3AD25DBC0A76EFA9E6D44D2C51E3027483F7BFD09996457888BAFD1AF673817F"
|
||||
SELF_PUB = "04F26C6CDA5E58153999FDF3023259F16EDE0A556C39FCF4BC97C04A10A8A6CF1D52297B53DB4DD72FEEF8221394C8478E6424F4E84E4A6E2784C1A4A1C99F2DC2"
|
||||
)
|
||||
|
||||
func TestGenerateSM2KeyPair(t *testing.T) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package sm4
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -25,7 +26,10 @@ func TestSM4Encrypt(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSM4Decrypt(t *testing.T) {
|
||||
|
||||
uid, en := encrypt()
|
||||
//uid := "1729382256910270475"
|
||||
//en := "{\"accessToken\":\"77F59F157466F309E703F43CFDCFFECF\",\"encryptKey\":\"04237241E4A465C18645985B3C1DAE987B5DDF1C077AA27D677C843C52E833A24711C63F2512D1A4C37E85A5C9CEAC94156C97460CB5E8966CAD2A0C2596A64ED69CF3306D031C4AADAA73D165FB7EEC34E5AAF532A301169847560329F7F1E40E9FD09EB191976BB49ABFE611E05158EF\",\"request\":\"mkuquQ1RB2AtZYzBtWtLPJ3MMULWj7I5RmK3dKENYVW8OgB//I/+MAD/XnjxYYJlRWM8uL/rWL9o\\r\\n0L7W9fSBvOXWwz8reiwcAF/JZ5dnacZtVe0NPujDfeVIJp+9ua7hxQcegcEsIRS9CQqtF/rJN7M9\\r\\nxxCLSzEiJY8bIdRLBsfmB0uVIE2144s2tH7Q8R2fSOVbiSTH1PW3Ye0kkyCcBw==\",\"signature\":\"ed99a2ce827a4d443e2639ccfb78865e913854e2d61d1746dafb640e19cbb4f8#3793b1cac082d9e1cdfc2b7b8387a8c29e44b2f3fb35b352d02f1b2c9321e0a7\"}"
|
||||
decrypt, err := Sm4Decrypt(uid, SELF_PRI, PARTY_PUB, en, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -34,8 +38,8 @@ func TestSM4Decrypt(t *testing.T) {
|
|||
}
|
||||
|
||||
func encrypt() (string, string) {
|
||||
uid := "1234567890"
|
||||
data := "{\"name\":\"张三\",\"sex\":1,\"is_human\":true}"
|
||||
uid := strconv.FormatInt(int64(5476377146882523149), 10)
|
||||
data := "{\"pay_channel_id\":1729382256910270476,\"out_trade_no\":\"asdadasdas\",\"order_type\":1,\"amount\":1,\"desc\":\"abc\",\"ext_json\":\"\",\"app_id\":5476377146882523149,\"timestamp\":1723096731}"
|
||||
en, err := Sm4Encrypt(uid, PARTY_PRI, SELF_PUB, data, "", true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in New Issue