Compare commits
No commits in common. "c1e354e4abf58c45487526c55ba3bee98e9ecc6b" and "1a292ff5d3bbe374db78f171e2c522222fbc6a8f" have entirely different histories.
c1e354e4ab
...
1a292ff5d3
28
Makefile
28
Makefile
|
@ -1,28 +0,0 @@
|
||||||
GOHOSTOS:=$(shell go env GOHOSTOS)
|
|
||||||
GOPATH:=$(shell go env GOPATH)
|
|
||||||
VERSION=$(shell git describe --tags --always)
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(GOHOSTOS), windows)
|
|
||||||
#the `find.exe` is different from `find` in bash/shell.
|
|
||||||
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
|
|
||||||
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
|
|
||||||
#Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
|
|
||||||
Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
|
|
||||||
INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
|
|
||||||
API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
|
|
||||||
else
|
|
||||||
INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
|
|
||||||
API_PROTO_FILES=$(shell find api -name *.proto)
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
sh build/shell/build.sh
|
|
||||||
|
|
||||||
.PHONY: api
|
|
||||||
api:
|
|
||||||
sh build/shell/build.sh & build/bin/snow -a api
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ const (
|
||||||
TOKEN_PRE = "player_token_"
|
TOKEN_PRE = "player_token_"
|
||||||
TOKEN_Admin = "Admin_token_"
|
TOKEN_Admin = "Admin_token_"
|
||||||
ADMIN_V1 = "/admin/pay/api/v1"
|
ADMIN_V1 = "/admin/pay/api/v1"
|
||||||
FRONT_API_V1 = "/v1"
|
|
||||||
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
PAY_CHANNEL_UNKNOWN = 0
|
||||||
|
|
|
@ -21,9 +21,6 @@ const (
|
||||||
|
|
||||||
//未登录
|
//未登录
|
||||||
NotLogin = 1000
|
NotLogin = 1000
|
||||||
|
|
||||||
// 商户
|
|
||||||
MerchantNotFound = 1100
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var MsgEN = map[int]string{
|
var MsgEN = map[int]string{
|
||||||
|
@ -41,8 +38,6 @@ var MsgZH = map[int]string{
|
||||||
NotFound: "数据不存在",
|
NotFound: "数据不存在",
|
||||||
NotAuth: "未经授权",
|
NotAuth: "未经授权",
|
||||||
NotLogin: "未登录",
|
NotLogin: "未登录",
|
||||||
|
|
||||||
MerchantNotFound: "商户不存在",
|
|
||||||
}
|
}
|
||||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,3 @@ func (m *MerchantRepo) MerchantDelete(merchant *merchantmodel.Merchant, conn bui
|
||||||
func (m *MerchantRepo) MerchantUpdate(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *MerchantRepo) MerchantUpdate(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MerchantRepo) MerchantDetail(merchant *merchantmodel.Merchant, conn builder.Cond) (bool, error) {
|
|
||||||
return m.repo.Where(conn).Get(merchant)
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package data
|
||||||
|
|
||||||
|
import "PaymentCenter/app/models/ordersmodel"
|
||||||
|
|
||||||
|
func GetOrderInfoById(id int64) (orderInfo ordersmodel.Orders, err error) {
|
||||||
|
_, err = ordersmodel.GetInstance().GetDb().Where("Id = ?", id).Get(&orderInfo)
|
||||||
|
if err != nil {
|
||||||
|
return ordersmodel.Orders{}, err
|
||||||
|
}
|
||||||
|
return orderInfo, nil
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ func (m *PayChannelRepo) PayChannelDelete(merchant *paychannelmodel.PayChannel,
|
||||||
return m.repo.Where(conn).Delete(merchant)
|
return m.repo.Where(conn).Delete(merchant)
|
||||||
}
|
}
|
||||||
|
|
||||||
// columns 参数为要更新的字段,即使为空
|
// columns 参数为要更新的字段
|
||||||
func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
|
||||||
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
return m.repo.Where(conn).MustCols(columns...).Update(merchant)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package backend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/constants/errorcode"
|
|
||||||
"PaymentCenter/app/http/controllers"
|
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/http/entities/backend"
|
|
||||||
"PaymentCenter/app/models/appmodel"
|
|
||||||
"PaymentCenter/app/services"
|
|
||||||
"PaymentCenter/app/utils/sm2"
|
|
||||||
"github.com/ahmetb/go-linq/v3"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AppList(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.AppListRequest)
|
|
||||||
req.SetDefault()
|
|
||||||
payChannelList, total, code := services.AppList(*req)
|
|
||||||
|
|
||||||
result := make([]backend.AppResponse, 0, len(payChannelList))
|
|
||||||
linq.From(payChannelList).SelectT(func(in appmodel.App) (out backend.AppResponse) {
|
|
||||||
out.ResponseFromDb(in)
|
|
||||||
return
|
|
||||||
}).ToSlice(&result)
|
|
||||||
data := entities.PageRsp{
|
|
||||||
Total: total,
|
|
||||||
Data: result,
|
|
||||||
}
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppCreate(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.AppCreateRequest)
|
|
||||||
payChannel := req.RequestToDb()
|
|
||||||
code := services.AppCreate(&payChannel)
|
|
||||||
|
|
||||||
data := backend.AppResponse{}
|
|
||||||
data.ResponseFromDb(payChannel)
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppUpdate(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.AppUpdateRequest)
|
|
||||||
payChannel := req.RequestToDb()
|
|
||||||
code := services.AppUpdate(&payChannel)
|
|
||||||
|
|
||||||
data := backend.AppResponse{}
|
|
||||||
data.ResponseFromDb(payChannel)
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppDelete(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
|
|
||||||
code := services.AppDelete(*req)
|
|
||||||
controllers.HandCodeRes(c, nil, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GenerateDecrypt(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.GenerateDecryptKeyRequest)
|
|
||||||
var publicKey, privateKey string
|
|
||||||
var err error
|
|
||||||
switch req.KeyType {
|
|
||||||
default:
|
|
||||||
publicKey, privateKey, err = sm2.GenerateSM2Key()
|
|
||||||
if err != nil {
|
|
||||||
controllers.Error(c, errorcode.SystemError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
controllers.HandCodeRes(c, map[string]string{
|
|
||||||
"publicKey": publicKey,
|
|
||||||
"privateKey": privateKey,
|
|
||||||
}, errorcode.Success)
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package backend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/constants/errorcode"
|
|
||||||
"PaymentCenter/app/http/controllers"
|
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/http/entities/backend"
|
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
|
||||||
"PaymentCenter/app/services"
|
|
||||||
"github.com/ahmetb/go-linq/v3"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PayChannelList(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.PayChannelListRequest)
|
|
||||||
req.SetDefault()
|
|
||||||
payChannelList, total, code := services.PayChannelList(*req)
|
|
||||||
|
|
||||||
result := make([]backend.PayChannelResponse, 0, len(payChannelList))
|
|
||||||
linq.From(payChannelList).SelectT(func(in paychannelmodel.PayChannel) (out backend.PayChannelResponse) {
|
|
||||||
out.ResponseFromDb(in)
|
|
||||||
return
|
|
||||||
}).ToSlice(&result)
|
|
||||||
data := entities.PageRsp{
|
|
||||||
Total: total,
|
|
||||||
Data: result,
|
|
||||||
}
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelCreate(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.PayChannelCreateRequest)
|
|
||||||
payChannel, err := req.RequestToDb()
|
|
||||||
if err != nil {
|
|
||||||
controllers.Error(c, errorcode.ParamError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
code := services.PayChannelCreate(&payChannel)
|
|
||||||
|
|
||||||
data := backend.PayChannelResponse{}
|
|
||||||
data.ResponseFromDb(payChannel)
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelUpdate(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*backend.PayChannelUpdateRequest)
|
|
||||||
payChannel, err := req.RequestToDb()
|
|
||||||
if err != nil {
|
|
||||||
controllers.Error(c, errorcode.ParamError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
code := services.PayChannelUpdate(&payChannel)
|
|
||||||
|
|
||||||
data := backend.PayChannelResponse{}
|
|
||||||
data.ResponseFromDb(payChannel)
|
|
||||||
controllers.HandCodeRes(c, data, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelDelete(c *gin.Context) {
|
|
||||||
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
|
|
||||||
code := services.PayChannelDelete(*req)
|
|
||||||
controllers.HandCodeRes(c, nil, code)
|
|
||||||
}
|
|
|
@ -26,11 +26,7 @@ import (
|
||||||
/**
|
/**
|
||||||
* 成功时返回
|
* 成功时返回
|
||||||
*/
|
*/
|
||||||
func Success(c *gin.Context, data interface{}, messageSlice ...string) {
|
func Success(c *gin.Context, data interface{}, message string) {
|
||||||
var message string
|
|
||||||
if len(messageSlice) > 0 {
|
|
||||||
message = messageSlice[0]
|
|
||||||
}
|
|
||||||
if message == "" {
|
if message == "" {
|
||||||
message = errorcode.GetMsg(errorcode.Success, c.GetHeader("local"))
|
message = errorcode.GetMsg(errorcode.Success, c.GetHeader("local"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package front
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/http/controllers"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
func HelloHandler(c *gin.Context) {
|
|
||||||
controllers.Success(c, "aaaa")
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package front
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/go-pay/gopay/alipay"
|
|
||||||
"github.com/go-pay/xlog"
|
|
||||||
"github.com/qit-team/snow-core/log/logger"
|
|
||||||
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// WxCallback 微信支付回调
|
|
||||||
//func WxCallback(c *gin.Context) {
|
|
||||||
// notifyReq, err := wechat.V3ParseNotify(c.Request)
|
|
||||||
// if err != nil {
|
|
||||||
// xlog.Error(err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// paymentService.WxPayCallBack(notifyReq)
|
|
||||||
//
|
|
||||||
// // ====↓↓↓====异步通知应答====↓↓↓====
|
|
||||||
// // 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
|
||||||
// // 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
|
||||||
//
|
|
||||||
// // 此写法是 gin 框架返回微信的写法
|
|
||||||
// c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
|
||||||
//}
|
|
||||||
|
|
||||||
// AliCallback 支付宝支付回调
|
|
||||||
func AliCallback(c *gin.Context) {
|
|
||||||
notifyReq, err := alipay.ParseNotifyToBodyMap(c.Request) // c.Request 是 gin 框架的写法
|
|
||||||
logger.Info(c, "AliCallback-回调数据", c.Request)
|
|
||||||
if err != nil {
|
|
||||||
xlog.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
appId := notifyReq.Get("app_id")
|
|
||||||
if appId == "" {
|
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo 查询支付宝公钥证书信息,进行验证签名
|
|
||||||
alipayPublicCert := ""
|
|
||||||
ok, err := alipay.VerifySignWithCert([]byte(alipayPublicCert), notifyReq)
|
|
||||||
if !ok {
|
|
||||||
logger.Error(c, "AliCallback-回调数据,验签失败")
|
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo 拼装数据触发下游回调,数据待定
|
|
||||||
|
|
||||||
c.String(http.StatusOK, "%s", "success")
|
|
||||||
}
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package domains
|
||||||
|
|
||||||
|
type Filter struct {
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductFilter struct {
|
||||||
|
Page int `json:"page" form:"page"`
|
||||||
|
PageSize int `json:"page_size" form:"page_size"`
|
||||||
|
ProductName string `json:"product_name" form:"product_name"`
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package domains
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Product struct {
|
||||||
|
Id int
|
||||||
|
ProductName string
|
||||||
|
ProductType int
|
||||||
|
PacketRule int
|
||||||
|
ProductKind int
|
||||||
|
Amount string
|
||||||
|
CouponType int
|
||||||
|
IsSuperposition int
|
||||||
|
TemplateId int
|
||||||
|
Status int
|
||||||
|
IsNeedBill int
|
||||||
|
CreateTime time.Time
|
||||||
|
SupplierProductId int64
|
||||||
|
SupplierProductName string
|
||||||
|
|
||||||
|
Creator string
|
||||||
|
UpdateTime time.Time
|
||||||
|
}
|
|
@ -1,101 +0,0 @@
|
||||||
package backend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/models/appmodel"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AppListRequest struct {
|
|
||||||
MerchantId int64 `json:"merchant_id"`
|
|
||||||
entities.PageRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppResponse struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
MerchantId int64 `json:"merchant_id"`
|
|
||||||
AppName string `json:"app_name"`
|
|
||||||
AppRemark string `json:"app_remark"`
|
|
||||||
Status int `json:"status"`
|
|
||||||
KeyType int `json:"key_type"`
|
|
||||||
PublicKey string `json:"public_key"`
|
|
||||||
PrivateKey string `json:"private_key"`
|
|
||||||
MerchantPublicKey string `json:"merchant_public_key"`
|
|
||||||
CreateTime string `json:"create_time"`
|
|
||||||
WhiteIp string `json:"white_ip"`
|
|
||||||
NotifyUrl string `json:"notify_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AppResponse) ResponseFromDb(db appmodel.App) {
|
|
||||||
a.Id = db.Id
|
|
||||||
a.MerchantId = db.MerchantId
|
|
||||||
a.AppName = db.AppName
|
|
||||||
a.AppRemark = db.AppRemark
|
|
||||||
a.Status = db.Status
|
|
||||||
a.KeyType = db.KeyType
|
|
||||||
a.PublicKey = db.PublicKey
|
|
||||||
a.PrivateKey = db.PrivateKey
|
|
||||||
a.MerchantPublicKey = db.MerchantPublicKey
|
|
||||||
a.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
|
||||||
a.WhiteIp = db.WhiteIp
|
|
||||||
a.NotifyUrl = db.NotifyUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppCreateRequest struct {
|
|
||||||
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
|
|
||||||
AppName string `json:"app_name" validate:"required" label:"应用名称"`
|
|
||||||
AppRemark string `json:"app_remark" label:"应用备注"`
|
|
||||||
Status int `json:"status" validate:"oneof=0 1 2" label:"应用状态"`
|
|
||||||
KeyType int `json:"key_type" validate:"required" label:"应用密钥类型"`
|
|
||||||
PublicKey string `json:"public_key" validate:"required" label:"应用公钥"`
|
|
||||||
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
|
|
||||||
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
|
||||||
WhiteIp string `json:"white_ip"`
|
|
||||||
NotifyUrl string `json:"notify_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
|
|
||||||
db.MerchantId = a.MerchantId
|
|
||||||
db.AppName = a.AppName
|
|
||||||
db.AppRemark = a.AppRemark
|
|
||||||
db.Status = a.Status
|
|
||||||
db.KeyType = a.KeyType
|
|
||||||
db.PublicKey = a.PublicKey
|
|
||||||
db.PrivateKey = a.PrivateKey
|
|
||||||
db.MerchantPublicKey = a.MerchantPublicKey
|
|
||||||
db.WhiteIp = a.WhiteIp
|
|
||||||
db.NotifyUrl = a.NotifyUrl
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppUpdateRequest struct {
|
|
||||||
Id int64 `json:"id" validate:"required" label:"应用ID"`
|
|
||||||
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
|
|
||||||
AppName string `json:"app_name" validate:"required" label:"应用名称"`
|
|
||||||
AppRemark string `json:"app_remark" label:"应用备注"`
|
|
||||||
Status int `json:"status" validate:"oneof=0 1 2" label:"应用状态"`
|
|
||||||
KeyType int `json:"key_type" validate:"required" label:"应用密钥类型"`
|
|
||||||
PublicKey string `json:"public_key" validate:"required" label:"应用公钥"`
|
|
||||||
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
|
|
||||||
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
|
|
||||||
WhiteIp string `json:"white_ip"`
|
|
||||||
NotifyUrl string `json:"notify_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
|
|
||||||
db.Id = a.Id
|
|
||||||
db.MerchantId = a.MerchantId
|
|
||||||
db.AppName = a.AppName
|
|
||||||
db.AppRemark = a.AppRemark
|
|
||||||
db.Status = a.Status
|
|
||||||
db.KeyType = a.KeyType
|
|
||||||
db.PublicKey = a.PublicKey
|
|
||||||
db.PrivateKey = a.PrivateKey
|
|
||||||
db.MerchantPublicKey = a.MerchantPublicKey
|
|
||||||
db.WhiteIp = a.WhiteIp
|
|
||||||
db.NotifyUrl = a.NotifyUrl
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type GenerateDecryptKeyRequest struct {
|
|
||||||
KeyType int `json:"key_type" label:"密钥类型"`
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@ package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/constants/common"
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/utils"
|
"PaymentCenter/app/utils"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -14,11 +13,12 @@ type PayChannelResponse struct {
|
||||||
PayName string `json:"pay_name"`
|
PayName string `json:"pay_name"`
|
||||||
MerchantId int64 `json:"merchant_id"`
|
MerchantId int64 `json:"merchant_id"`
|
||||||
ChannelType int `json:"channel_type"`
|
ChannelType int `json:"channel_type"`
|
||||||
|
WhiteIp string `json:"white_ip"`
|
||||||
AppId string `json:"app_id"`
|
AppId string `json:"app_id"`
|
||||||
ExpireTime string `json:"expire_time"`
|
ExpireTime string `json:"expire_time"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
AliPayPayChannel *AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
||||||
WechatPayChannel *WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
|
func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
|
||||||
|
@ -26,30 +26,32 @@ func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
|
||||||
p.PayName = db.PayName
|
p.PayName = db.PayName
|
||||||
p.MerchantId = db.MerchantId
|
p.MerchantId = db.MerchantId
|
||||||
p.ChannelType = db.ChannelType
|
p.ChannelType = db.ChannelType
|
||||||
|
p.WhiteIp = db.WhiteIp
|
||||||
p.AppId = db.AppId
|
p.AppId = db.AppId
|
||||||
p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05")
|
p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05")
|
||||||
p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
switch p.ChannelType {
|
switch p.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:
|
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:
|
||||||
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
|
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
case common.PAY_CHANNEL_ALIPAY_JSAPI | common.PAY_CHANNEL_ALIPAY_WEB | common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel)
|
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayChannelCreateRequest struct {
|
type PayChannelCreateRequest struct {
|
||||||
PayName string `json:"pay_name" validate:"required" label:"支付渠道名称"`
|
PayName string `json:"pay_name"`
|
||||||
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
|
MerchantId int64 `json:"merchant_id"`
|
||||||
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
ChannelType int `json:"channel_type"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
||||||
AppId string `json:"app_id" validate:"required" label:"应用appId"`
|
WhiteIp string `json:"white_ip"`
|
||||||
|
AppId string `json:"app_id"`
|
||||||
ExpireTime string `json:"expire_time"`
|
ExpireTime string `json:"expire_time"`
|
||||||
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
|
||||||
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WechatPayChannel struct {
|
type WechatPayChannel struct {
|
||||||
MchId string `json:"mch_id"` //直连商户号
|
MchId int `json:"mch_id"` //直连商户号
|
||||||
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号
|
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号
|
||||||
MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥
|
MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥
|
||||||
PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径
|
PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径
|
||||||
|
@ -65,6 +67,7 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
|
||||||
db.PayName = p.PayName
|
db.PayName = p.PayName
|
||||||
db.MerchantId = p.MerchantId
|
db.MerchantId = p.MerchantId
|
||||||
db.ChannelType = p.ChannelType
|
db.ChannelType = p.ChannelType
|
||||||
|
db.WhiteIp = p.WhiteIp
|
||||||
db.AppId = p.AppId
|
db.AppId = p.AppId
|
||||||
if p.ExpireTime != "" {
|
if p.ExpireTime != "" {
|
||||||
db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime)
|
db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime)
|
||||||
|
@ -73,49 +76,12 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch p.ChannelType {
|
switch p.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:
|
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:
|
||||||
b, _ := json.Marshal(p.WechatPayChannel)
|
b, _ := json.Marshal(p.WechatPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
case common.PAY_CHANNEL_ALIPAY_JSAPI | common.PAY_CHANNEL_ALIPAY_WEB | common.PAY_CHANNEL_ALIPAY_MINI:
|
||||||
b, _ := json.Marshal(p.AliPayPayChannel)
|
b, _ := json.Marshal(p.AliPayPayChannel)
|
||||||
db.ExtJson = string(b)
|
db.ExtJson = string(b)
|
||||||
default:
|
|
||||||
err = errors.New("支付渠道类型错误")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayChannelListRequest struct {
|
|
||||||
MerchantId int64 `json:"merchant_id"`
|
|
||||||
entities.PageRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayChannelUpdateRequest struct {
|
|
||||||
Id int64 `json:"id" validate:"required"`
|
|
||||||
PayChannelCreateRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
|
|
||||||
db.Id = p.Id
|
|
||||||
db.PayName = p.PayName
|
|
||||||
db.MerchantId = p.MerchantId
|
|
||||||
db.ChannelType = p.ChannelType
|
|
||||||
db.AppId = p.AppId
|
|
||||||
if p.ExpireTime != "" {
|
|
||||||
db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime)
|
|
||||||
if err != nil {
|
|
||||||
err = errors.Wrap(err, "时间格式错误")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch p.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:
|
|
||||||
b, _ := json.Marshal(p.WechatPayChannel)
|
|
||||||
db.ExtJson = string(b)
|
|
||||||
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
|
|
||||||
b, _ := json.Marshal(p.AliPayPayChannel)
|
|
||||||
db.ExtJson = string(b)
|
|
||||||
default:
|
|
||||||
err = errors.New("支付渠道类型错误")
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package front
|
|
||||||
|
|
||||||
type WxRequest struct {
|
|
||||||
TradeNo string `json:"tradeNo" validate:"required"` // 交易流水号
|
|
||||||
VoucherId string `json:"voucherId"` // 制码批次号
|
|
||||||
VoucherCode string `json:"voucherCode"` // 串码
|
|
||||||
CnclSt string `json:"cnclSt"` // 核销状态,4-已核销
|
|
||||||
RedeemResult string `json:"redeemResult"` // 核销结果,00-成功,09- 失败
|
|
||||||
MrchntNo string `json:"mrchntNo"` // 商户号
|
|
||||||
Sign string `json:"sign"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AliRequest struct {
|
|
||||||
MerchantId int `form:"merchantId" validate:"required"`
|
|
||||||
OutTradeNo string `form:"outTradeNo" validate:"required"`
|
|
||||||
Status string `form:"status" validate:"required"`
|
|
||||||
RechargeAccount string `form:"rechargeAccount"`
|
|
||||||
CardCode string `form:"cardCode"`
|
|
||||||
Sign string `form:"sign" validate:"required"`
|
|
||||||
}
|
|
|
@ -13,15 +13,4 @@ var BackendRequestMap = map[string]func() interface{}{
|
||||||
common.ADMIN_V1 + "/merchant/update": func() interface{} { return new(backend.MerchantUpdateRequest) },
|
common.ADMIN_V1 + "/merchant/update": func() interface{} { return new(backend.MerchantUpdateRequest) },
|
||||||
common.ADMIN_V1 + "/merchant/list": func() interface{} { return new(backend.MerchantListRequest) },
|
common.ADMIN_V1 + "/merchant/list": func() interface{} { return new(backend.MerchantListRequest) },
|
||||||
common.ADMIN_V1 + "/merchant/delete": func() interface{} { return new(entities.IdRequest) },
|
common.ADMIN_V1 + "/merchant/delete": func() interface{} { return new(entities.IdRequest) },
|
||||||
// 支付方式
|
|
||||||
common.ADMIN_V1 + "/paychannel/create": func() interface{} { return new(backend.PayChannelCreateRequest) },
|
|
||||||
common.ADMIN_V1 + "/paychannel/update": func() interface{} { return new(backend.PayChannelUpdateRequest) },
|
|
||||||
common.ADMIN_V1 + "/paychannel/list": func() interface{} { return new(backend.PayChannelListRequest) },
|
|
||||||
common.ADMIN_V1 + "/paychannel/delete": func() interface{} { return new(entities.IdRequest) },
|
|
||||||
// 应用
|
|
||||||
common.ADMIN_V1 + "/app/create": func() interface{} { return new(backend.AppCreateRequest) },
|
|
||||||
common.ADMIN_V1 + "/app/update": func() interface{} { return new(backend.AppUpdateRequest) },
|
|
||||||
common.ADMIN_V1 + "/app/list": func() interface{} { return new(backend.AppListRequest) },
|
|
||||||
common.ADMIN_V1 + "/app/delete": func() interface{} { return new(entities.IdRequest) },
|
|
||||||
common.ADMIN_V1 + "/app/decrypt": func() interface{} { return new(backend.GenerateDecryptKeyRequest) },
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package requestmapping
|
package requestmapping
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/constants/common"
|
|
||||||
"PaymentCenter/app/http/entities/front"
|
|
||||||
)
|
|
||||||
|
|
||||||
var FrontRequestMap = map[string]func() interface{}{
|
var FrontRequestMap = map[string]func() interface{}{
|
||||||
common.FRONT_API_V1 + "/notify/wx": func() interface{} { return new(front.WxRequest) },
|
//"/v1/login": func() interface{} {
|
||||||
common.FRONT_API_V1 + "/notify/ali": func() interface{} { return new(front.AliRequest) },
|
// return new(front.LoginRequest)
|
||||||
|
//},
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,21 +31,6 @@ func RegisterAdminRoute(router *gin.Engine) {
|
||||||
merchant.POST("/create", backend.MerchantCreate) // 商户创建
|
merchant.POST("/create", backend.MerchantCreate) // 商户创建
|
||||||
merchant.PUT("/update", backend.MerchantUpdate) // 商户更新
|
merchant.PUT("/update", backend.MerchantUpdate) // 商户更新
|
||||||
merchant.DELETE("/delete", backend.MerchantDelete) // 商户删除
|
merchant.DELETE("/delete", backend.MerchantDelete) // 商户删除
|
||||||
// 支付方式
|
|
||||||
pay := v1.Group("/paychannel")
|
|
||||||
pay.GET("/list", backend.PayChannelList) // 支付方式列表
|
|
||||||
pay.POST("/create", backend.PayChannelCreate) // 支付方式创建
|
|
||||||
pay.PUT("/update", backend.PayChannelUpdate) // 支付方式更新
|
|
||||||
pay.DELETE("/delete", backend.PayChannelDelete) // 支付方式删除
|
|
||||||
|
|
||||||
// 应用管理
|
|
||||||
app := v1.Group("/app")
|
|
||||||
app.GET("/list", backend.AppList) // 应用列表
|
|
||||||
app.POST("/create", backend.AppCreate) // 应用创建
|
|
||||||
app.PUT("/update", backend.AppUpdate) // 应用更新
|
|
||||||
app.DELETE("/delete", backend.AppDelete) // 应用删除
|
|
||||||
app.GET("/decrypt", backend.GenerateDecrypt) // 生成密钥对
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package routes
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/http/controllers"
|
"PaymentCenter/app/http/controllers"
|
||||||
"PaymentCenter/app/http/controllers/front"
|
|
||||||
"PaymentCenter/app/http/middlewares"
|
"PaymentCenter/app/http/middlewares"
|
||||||
"PaymentCenter/app/http/trace"
|
"PaymentCenter/app/http/trace"
|
||||||
"PaymentCenter/app/utils/metric"
|
"PaymentCenter/app/utils/metric"
|
||||||
|
@ -50,16 +49,6 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
v1 := router.Group("/v1", middlewares.ValidateRequest())
|
|
||||||
{
|
|
||||||
//回调处理
|
|
||||||
notify := v1.Group("/notify")
|
|
||||||
{
|
|
||||||
notify.POST("/wx", front.WxCallback)
|
|
||||||
notify.POST("/ali", front.AliCallback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
//router.GET("/hello", controllers.HelloHandler)
|
//router.GET("/hello", controllers.HelloHandler)
|
||||||
|
|
|
@ -13,7 +13,7 @@ var (
|
||||||
|
|
||||||
// 实体
|
// 实体
|
||||||
type App struct {
|
type App struct {
|
||||||
Id int64
|
Id int64 `xorm:"pk autoincr AUTO_RANDOM"`
|
||||||
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
||||||
AppName string `xorm:"'app_name' varchar(128)"`
|
AppName string `xorm:"'app_name' varchar(128)"`
|
||||||
AppRemark string `xorm:"'app_remark' varchar(255)"`
|
AppRemark string `xorm:"'app_remark' varchar(255)"`
|
||||||
|
@ -22,8 +22,6 @@ type App struct {
|
||||||
PublicKey string `xorm:"'public_key' varchar(1024)"`
|
PublicKey string `xorm:"'public_key' varchar(1024)"`
|
||||||
PrivateKey string `xorm:"'private_key' varchar(1024)"`
|
PrivateKey string `xorm:"'private_key' varchar(1024)"`
|
||||||
MerchantPublicKey string `xorm:"'merchant_public_key' varchar(1024)"`
|
MerchantPublicKey string `xorm:"'merchant_public_key' varchar(1024)"`
|
||||||
NotifyUrl string `xorm:"'notify_url' varchar(128)"`
|
|
||||||
WhiteIp string `xorm:"'white_ip' varchar(128)"`
|
|
||||||
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
CreateTime time.Time `xorm:"'create_time' datetime created"`
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||||
|
|
|
@ -16,11 +16,11 @@ type Orders struct {
|
||||||
Id int64
|
Id int64
|
||||||
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
||||||
PayId int64 `xorm:"'pay_id' bigint(20)"`
|
PayId int64 `xorm:"'pay_id' bigint(20)"`
|
||||||
AppId int64 `xorm:"'app_id' bigint(20)"`
|
|
||||||
MerchantOrderId string `xorm:"'merchant_order_id' varchar(128)"`
|
MerchantOrderId string `xorm:"'merchant_order_id' varchar(128)"`
|
||||||
Status int `xorm:"'status' int(11)"`
|
Status int `xorm:"'status' int(11)"`
|
||||||
OrderType int `xorm:"'order_type' int(11)"`
|
OrderType int `xorm:"'order_type' int(11)"`
|
||||||
Amount int `xorm:"'amount' int(11)"`
|
Amount int `xorm:"'amount' int(11)"`
|
||||||
|
NotifyUrl string `xorm:"'notify_url' varchar(255)"`
|
||||||
IpAddress string `xorm:"'ip_address' varchar(128)"`
|
IpAddress string `xorm:"'ip_address' varchar(128)"`
|
||||||
MerchantRequest string `xorm:"'merchant_request' varchar(2048)"`
|
MerchantRequest string `xorm:"'merchant_request' varchar(2048)"`
|
||||||
MerchantResponse string `xorm:"'merchant_response' varchar(255)"`
|
MerchantResponse string `xorm:"'merchant_response' varchar(255)"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ type PayChannel struct {
|
||||||
PayName string `xorm:"'pay_name' varchar(128)"`
|
PayName string `xorm:"'pay_name' varchar(128)"`
|
||||||
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
|
||||||
ChannelType int `xorm:"'channel_type' int(11)"`
|
ChannelType int `xorm:"'channel_type' int(11)"`
|
||||||
|
WhiteIp string `xorm:"'white_ip' varchar(1024)"`
|
||||||
AppId string `xorm:"'app_id' varchar(255)"`
|
AppId string `xorm:"'app_id' varchar(255)"`
|
||||||
ExtJson string `xorm:"'ext_json' JSON"`
|
ExtJson string `xorm:"'ext_json' JSON"`
|
||||||
ExpireTime time.Time `xorm:"'expire_time' datetime"`
|
ExpireTime time.Time `xorm:"'expire_time' datetime"`
|
||||||
|
|
|
@ -14,7 +14,7 @@ func SingleTalk(tag uint64, ch interface{}, msg []byte) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if !sendOk {
|
// if !sendOk {
|
||||||
// payCommon.PikaTool.Zadd(utils.GetRealKey(common2.USER_MSG)+data.Msg.To, data, time.Now().Unix())
|
// common.PikaTool.Zadd(utils.GetRealKey(common2.USER_MSG)+data.Msg.To, data, time.Now().Unix())
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package services
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/constants/errorcode"
|
|
||||||
"PaymentCenter/app/data"
|
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/http/entities/backend"
|
|
||||||
"PaymentCenter/app/models/appmodel"
|
|
||||||
"PaymentCenter/app/models/merchantmodel"
|
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
|
||||||
"xorm.io/builder"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, code int) {
|
|
||||||
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
if req.MerchantId > 0 {
|
|
||||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用repo
|
|
||||||
appList := make([]appmodel.App, 0)
|
|
||||||
count, err := repo.AppList(conn, req.PageRequest, &appList)
|
|
||||||
code = handErr(err)
|
|
||||||
return appList, count, code
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppCreate(App *appmodel.App) (code int) {
|
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
|
||||||
repo := data.NewAppRepo(db)
|
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": App.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = repo.AppInsertOne(App)
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppUpdate(App *appmodel.App) (code int) {
|
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
|
||||||
repo := data.NewAppRepo(db)
|
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": App.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼接查询条件
|
|
||||||
uconn := builder.NewCond()
|
|
||||||
uconn = uconn.And(builder.Eq{"Id": App.Id})
|
|
||||||
_, err = repo.AppUpdate(App, uconn, "app_remark")
|
|
||||||
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func AppDelete(req entities.IdRequest) (code int) {
|
|
||||||
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
|
|
||||||
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"Id": req.Id})
|
|
||||||
m := appmodel.App{Id: req.Id}
|
|
||||||
_, err := repo.AppDelete(&m, conn)
|
|
||||||
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
package services
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/constants/errorcode"
|
|
||||||
"PaymentCenter/app/data"
|
|
||||||
"PaymentCenter/app/http/entities"
|
|
||||||
"PaymentCenter/app/http/entities/backend"
|
|
||||||
"PaymentCenter/app/models/merchantmodel"
|
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
|
||||||
"xorm.io/builder"
|
|
||||||
)
|
|
||||||
|
|
||||||
func PayChannelList(req backend.PayChannelListRequest) (result []paychannelmodel.PayChannel, total int64, code int) {
|
|
||||||
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
if req.MerchantId > 0 {
|
|
||||||
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用repo
|
|
||||||
paychannelList := make([]paychannelmodel.PayChannel, 0)
|
|
||||||
count, err := repo.PayChannelList(conn, req.PageRequest, &paychannelList)
|
|
||||||
code = handErr(err)
|
|
||||||
return paychannelList, count, code
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelCreate(payChannel *paychannelmodel.PayChannel) (code int) {
|
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
|
||||||
repo := data.NewPayChannelRepo(db)
|
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": payChannel.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = repo.PayChannelInsertOne(payChannel)
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelUpdate(payChannel *paychannelmodel.PayChannel) (code int) {
|
|
||||||
db := paychannelmodel.GetInstance().GetDb()
|
|
||||||
repo := data.NewPayChannelRepo(db)
|
|
||||||
merchantRepo := data.NewMerchantRepo(db)
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"id": payChannel.MerchantId})
|
|
||||||
merchant := merchantmodel.Merchant{}
|
|
||||||
has, err := merchantRepo.MerchantDetail(&merchant, conn)
|
|
||||||
if err != nil {
|
|
||||||
return handErr(err)
|
|
||||||
}
|
|
||||||
if !has {
|
|
||||||
return errorcode.MerchantNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼接查询条件
|
|
||||||
uconn := builder.NewCond()
|
|
||||||
uconn = uconn.And(builder.Eq{"Id": payChannel.Id})
|
|
||||||
_, err = repo.PayChannelUpdate(payChannel, uconn, "white_ip")
|
|
||||||
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func PayChannelDelete(req entities.IdRequest) (code int) {
|
|
||||||
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
|
|
||||||
|
|
||||||
// 拼接查询条件
|
|
||||||
conn := builder.NewCond()
|
|
||||||
conn = conn.And(builder.Eq{"Id": req.Id})
|
|
||||||
m := paychannelmodel.PayChannel{Id: req.Id}
|
|
||||||
_, err := repo.PayChannelDelete(&m, conn)
|
|
||||||
|
|
||||||
code = handErr(err)
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/data"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"github.com/go-pay/gopay"
|
||||||
|
"github.com/go-pay/gopay/wechat/v3"
|
||||||
|
"github.com/go-pay/xlog"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ActivityGoodsCreateService(orderId int64) (err error) {
|
||||||
|
// 获取订单信息
|
||||||
|
orderInfo, err := data.GetOrderInfoById(orderId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if orderInfo.PayId == 0 {
|
||||||
|
return errors.New("缺少订单信息,无法进行支付")
|
||||||
|
}
|
||||||
|
// 获取支付渠道
|
||||||
|
payChannelInfo, err := data.GetPayChannelById(orderInfo.PayId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch payChannelInfo.ChannelType {
|
||||||
|
case common.PAYCHANNEL_WX_H5:
|
||||||
|
//todo 微信H5支付
|
||||||
|
wxH5PayInfo()
|
||||||
|
break
|
||||||
|
case common.PAYCHANNEL_ALI_H5:
|
||||||
|
//todo 支付宝H5支付
|
||||||
|
aLiH5PayInfo()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return errors.New("暂不支持该支付渠道,请后续再使用")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func wxH5PayInfo(c context.Context) {
|
||||||
|
// NewClientV3 初始化微信客户端 v3
|
||||||
|
// mchid:商户ID 或者服务商模式的 sp_mchid
|
||||||
|
// serialNo:商户证书的证书序列号
|
||||||
|
// apiV3Key:apiV3Key,商户平台获取
|
||||||
|
// privateKey:私钥 apiclient_key.pem 读取后的内容
|
||||||
|
client, err := wechat.NewClientV3(MchId, SerialNo, APIv3Key, PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置微信平台API证书和序列号(推荐开启自动验签,无需手动设置证书公钥等信息)
|
||||||
|
//client.SetPlatformCert([]byte(""), "")
|
||||||
|
|
||||||
|
// 启用自动同步返回验签,并定时更新微信平台API证书(开启自动验签时,无需单独设置微信平台API证书和序列号)
|
||||||
|
err = client.AutoVerifySign()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
||||||
|
client.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
||||||
|
|
||||||
|
// 打开Debug开关,输出日志,默认是关闭的
|
||||||
|
client.DebugSwitch = gopay.DebugOn
|
||||||
|
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
||||||
|
// 初始化 BodyMap
|
||||||
|
bm := make(gopay.BodyMap)
|
||||||
|
bm.Set("sp_appid", "sp_appid").
|
||||||
|
Set("sp_mchid", "sp_mchid").
|
||||||
|
Set("sub_mchid", "sub_mchid").
|
||||||
|
Set("description", "测试Jsapi支付商品").
|
||||||
|
Set("out_trade_no", tradeNo).
|
||||||
|
Set("time_expire", expire).
|
||||||
|
Set("notify_url", "https://www.fmm.ink").
|
||||||
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
|
bm.Set("total", 1).
|
||||||
|
Set("currency", "CNY")
|
||||||
|
}).
|
||||||
|
SetBodyMap("payer", func(bm gopay.BodyMap) {
|
||||||
|
bm.Set("sp_openid", "asdas")
|
||||||
|
})
|
||||||
|
|
||||||
|
wxRsp, err := client.V3TransactionH5(c, bm)
|
||||||
|
if err != nil {
|
||||||
|
xlog.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if wxRsp.Code == errorcode.Success {
|
||||||
|
xlog.Debugf("wxRsp: %#v", wxRsp.Response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
xlog.Errorf("wxRsp:%s", wxRsp.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func aLiH5PayInfo() {
|
||||||
|
|
||||||
|
}
|
|
@ -1,149 +0,0 @@
|
||||||
package paymentService
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/go-pay/gopay"
|
|
||||||
"github.com/go-pay/gopay/alipay"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
aliClient *alipay.Client
|
|
||||||
aliClientErr error
|
|
||||||
aliOnce sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
// AliInitClient 使用提供的支付请求参数初始化支付宝客户端
|
|
||||||
func AliInitClient(aliConfig AliPay) {
|
|
||||||
aliOnce.Do(func() {
|
|
||||||
// 初始化支付宝客户端
|
|
||||||
// appid:应用ID
|
|
||||||
// privateKey:应用私钥,支持PKCS1和PKCS8
|
|
||||||
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。
|
|
||||||
aliClient, aliClientErr = alipay.NewClient(aliConfig.AppId, aliConfig.PrivateKey, true)
|
|
||||||
})
|
|
||||||
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
|
||||||
aliClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
|
||||||
|
|
||||||
// 打开Debug开关,输出日志,默认关闭
|
|
||||||
aliClient.DebugSwitch = gopay.DebugOn
|
|
||||||
|
|
||||||
// 设置支付宝请求 公共参数
|
|
||||||
// 注意:具体设置哪些参数,根据不同的方法而不同,此处列举出所有设置参数
|
|
||||||
aliClient.SetLocation(alipay.LocationShanghai). // 设置时区,不设置或出错均为默认服务器时间
|
|
||||||
SetCharset(alipay.UTF8). // 设置字符编码,不设置默认 utf-8
|
|
||||||
SetSignType(alipay.RSA2) // 设置签名类型,不设置默认 RSA2
|
|
||||||
|
|
||||||
// 自动同步验签(只支持证书模式)
|
|
||||||
// 传入 alipayPublicCert.crt 内容
|
|
||||||
aliClient.AutoVerifySign(aliConfig.AlipayPublicCert)
|
|
||||||
|
|
||||||
// 证书内容
|
|
||||||
aliClientErr = aliClient.SetCertSnByContent(aliConfig.AppPublicCert, aliConfig.AlipayRootCert, aliConfig.AlipayPublicCert)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAliClient 获取已经初始化的支付宝客户端
|
|
||||||
func GetAliClient() (*alipay.Client, error) {
|
|
||||||
if aliClient == nil {
|
|
||||||
return nil, errors.New("client not initialized")
|
|
||||||
}
|
|
||||||
if aliClientErr != nil {
|
|
||||||
return nil, aliClientErr
|
|
||||||
}
|
|
||||||
return aliClient, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ALiH5PayInfo 支付宝手机网站支付
|
|
||||||
func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, error) {
|
|
||||||
// 初始化支付宝客户端
|
|
||||||
AliInitClient(payOrderRequest.Ali)
|
|
||||||
|
|
||||||
// 获取支付宝客户端
|
|
||||||
aliClient, err := GetAliClient()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to get client:", err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
// 初始化 BodyMap
|
|
||||||
amount := float64(payOrderRequest.Amount) / 100.0
|
|
||||||
|
|
||||||
bm := make(gopay.BodyMap)
|
|
||||||
bm.Set("out_trade_no", payOrderRequest.OrderId).
|
|
||||||
Set("total_amount", amount).
|
|
||||||
Set("subject", payOrderRequest.Description).
|
|
||||||
Set("notify_url", payCommon.ALI_NOTIFY_URL)
|
|
||||||
|
|
||||||
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
|
||||||
if err != nil {
|
|
||||||
if bizErr, ok := alipay.IsBizError(err); ok {
|
|
||||||
return "", bizErr
|
|
||||||
}
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return aliRsp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ALiOrderQuery 查询支付宝订单
|
|
||||||
func ALiOrderQuery(ctx context.Context, aliConfig AliPay, OrderNo string) (PayOrderQueryInfo, error) {
|
|
||||||
// 初始化支付宝客户端
|
|
||||||
AliInitClient(aliConfig)
|
|
||||||
|
|
||||||
// 获取支付宝客户端
|
|
||||||
aliClient, err := GetAliClient()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to get client:", err)
|
|
||||||
return PayOrderQueryInfo{}, err
|
|
||||||
}
|
|
||||||
// 请求参数
|
|
||||||
bm := make(gopay.BodyMap)
|
|
||||||
bm.Set("out_trade_no", OrderNo)
|
|
||||||
|
|
||||||
// 查询订单
|
|
||||||
aliRsp, err := aliClient.TradeQuery(ctx, bm)
|
|
||||||
if err != nil {
|
|
||||||
if bizErr, ok := alipay.IsBizError(err); ok {
|
|
||||||
return PayOrderQueryInfo{}, bizErr
|
|
||||||
}
|
|
||||||
return PayOrderQueryInfo{}, err
|
|
||||||
}
|
|
||||||
// 同步返回验签
|
|
||||||
ok, err := alipay.VerifySyncSignWithCert(aliConfig.AlipayPublicCert, aliRsp.SignData, aliRsp.Sign)
|
|
||||||
if err != nil || !ok {
|
|
||||||
return PayOrderQueryInfo{}, errors.New(fmt.Sprintf("验签失败,失败原因:%s", err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 映射交易状态
|
|
||||||
tradeState := ""
|
|
||||||
tradeStateDesc := ""
|
|
||||||
switch aliRsp.Response.TradeStatus {
|
|
||||||
case "TRADE_SUCCESS":
|
|
||||||
tradeState = "SUCCESS"
|
|
||||||
tradeStateDesc = "交易支付成功"
|
|
||||||
case "REFUND":
|
|
||||||
tradeState = "REFUND"
|
|
||||||
case "WAIT_BUYER_PAY":
|
|
||||||
tradeState = "NOTPAY"
|
|
||||||
tradeStateDesc = "交易创建,等待买家付款"
|
|
||||||
case "TRADE_CLOSED":
|
|
||||||
tradeState = "CLOSED"
|
|
||||||
tradeStateDesc = "未付款交易超时关闭,或支付完成后全额退款"
|
|
||||||
}
|
|
||||||
|
|
||||||
amountTotal, _ := strconv.Atoi(aliRsp.Response.TotalAmount)
|
|
||||||
payerTotal, _ := strconv.Atoi(aliRsp.Response.BuyerPayAmount)
|
|
||||||
// 构建数据
|
|
||||||
return PayOrderQueryInfo{
|
|
||||||
AppId: aliConfig.AppId,
|
|
||||||
OutTradeNo: aliRsp.Response.OutTradeNo,
|
|
||||||
TransactionId: aliRsp.Response.TradeNo,
|
|
||||||
TradeState: tradeState,
|
|
||||||
TradeStateDesc: tradeStateDesc,
|
|
||||||
SuccessTime: aliRsp.Response.SendPayDate,
|
|
||||||
AmountTotal: int64(amountTotal * 100),
|
|
||||||
PayerTotal: int64(payerTotal * 100),
|
|
||||||
}, nil
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package payCommon
|
|
||||||
|
|
||||||
const (
|
|
||||||
// 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI
|
|
||||||
PAY_CHANNEL_UNKNOWN = 0
|
|
||||||
PAY_CHANNEL_WECHAT_JSAPI = 1
|
|
||||||
PAY_CHANNEL_WECHAT_H5 = 2
|
|
||||||
PAY_CHANNEL_WECHAT_APP = 3
|
|
||||||
PAY_CHANNEL_WECHAT_NATIVE = 4
|
|
||||||
PAY_CHANNEL_WECHAT_MINI = 5
|
|
||||||
PAY_CHANNEL_ALIPAY_WEB = 6
|
|
||||||
PAY_CHANNEL_ALIPAY_MINI = 7
|
|
||||||
PAY_CHANNEL_ALIPAY_JSAPI = 8
|
|
||||||
|
|
||||||
PAY_SUCCESS_CODE = 200 // 支付响应成功
|
|
||||||
PAY_ERROR_CODE = 500 // 支付响应失败
|
|
||||||
PAY_NOT_FOUND_CODE = 404 // 未找到支付渠道
|
|
||||||
|
|
||||||
WX_SUCCESS_CODE = 200 // 微信状态码返回成功
|
|
||||||
WX_NOTIFY_URL = "" // 微信支付回调地址
|
|
||||||
|
|
||||||
ALI_NOTIFY_URL = "" // 支付宝支付回调地址
|
|
||||||
|
|
||||||
ORDER_NO_TYPE_ORDER_NO = 2
|
|
||||||
|
|
||||||
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
|
|
||||||
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝
|
|
||||||
)
|
|
|
@ -1,130 +0,0 @@
|
||||||
package paymentService
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PayOrderRequest struct {
|
|
||||||
OrderId int64 `json:"order_id"` // 平台订单号
|
|
||||||
ChannelType int `json:"channel_type"` // 支付方式
|
|
||||||
Description string `json:"description"` // 商品描述
|
|
||||||
Amount int `json:"amount"` // 金额单位为分
|
|
||||||
PayerClientIp string `json:"payer_client_ip"` // 终端IP
|
|
||||||
Wx WxPay `json:"wx"`
|
|
||||||
Ali AliPay `json:"ali"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WxPay struct {
|
|
||||||
AppId string `json:"app_id"` // 应用ID
|
|
||||||
MchId string `json:"mch_id"` // 商户ID 或者服务商模式的 sp_mchid
|
|
||||||
SerialNo string `json:"serial_no"` // 商户证书的证书序列号
|
|
||||||
ApiV3Key string `json:"api_v_3_key"` // apiV3Key,商户平台获取
|
|
||||||
PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容
|
|
||||||
}
|
|
||||||
|
|
||||||
type AliPay struct {
|
|
||||||
AppId string `json:"app_id"` // 应用ID
|
|
||||||
PrivateKey string `json:"private_key"` // 应用私钥
|
|
||||||
AppPublicCert []byte `json:"app_public_cert"` // 应用公钥
|
|
||||||
AlipayRootCert []byte `json:"alipay_root_cert"` // 支付宝根证书
|
|
||||||
AlipayPublicCert []byte `json:"alipay_public_cert"` // 支付宝公钥
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayOrderResponse struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
ErrorMsg string `json:"error_msg"`
|
|
||||||
Result string `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PaymentService 统一发起支付
|
|
||||||
func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrderResponse PayOrderResponse) {
|
|
||||||
switch payOrderRequest.ChannelType {
|
|
||||||
case payCommon.PAY_CHANNEL_WECHAT_H5:
|
|
||||||
// 微信H5支付
|
|
||||||
info, err := WxH5PayInfo(c, payOrderRequest)
|
|
||||||
if err != nil {
|
|
||||||
return PayOrderResponse{
|
|
||||||
Code: payCommon.PAY_ERROR_CODE,
|
|
||||||
ErrorMsg: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PayOrderResponse{
|
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
|
||||||
ErrorMsg: "",
|
|
||||||
Result: info,
|
|
||||||
}
|
|
||||||
case payCommon.PAY_CHANNEL_ALIPAY_WEB:
|
|
||||||
// 支付宝H5支付
|
|
||||||
info, err := ALiH5PayInfo(c, payOrderRequest)
|
|
||||||
if err != nil {
|
|
||||||
return PayOrderResponse{
|
|
||||||
Code: payCommon.PAY_ERROR_CODE,
|
|
||||||
ErrorMsg: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PayOrderResponse{
|
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
|
||||||
ErrorMsg: "",
|
|
||||||
Result: info,
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return PayOrderResponse{
|
|
||||||
Code: payCommon.PAY_NOT_FOUND_CODE,
|
|
||||||
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayOrderQueryRequest struct {
|
|
||||||
OrderId int64 `json:"order_id"` // 商户订单号
|
|
||||||
PayChannel int `json:"pay_channel"` // 支付渠道类型 1:wx,2:zfb
|
|
||||||
Wx WxPay `json:"wx"`
|
|
||||||
Ali AliPay `json:"ali"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayOrderQueryResponse struct {
|
|
||||||
Code int `json:"code"`
|
|
||||||
ErrorMsg string `json:"error_msg"`
|
|
||||||
Result PayOrderQueryInfo `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PayOrderQueryInfo struct {
|
|
||||||
AppId string `json:"app_id"` // 应用ID
|
|
||||||
OutTradeNo string `json:"out_trade_no"` // 商家订单号
|
|
||||||
TransactionId string `json:"transaction_id"` // 第三方订单号
|
|
||||||
TradeState string `json:"trade_state"` // 交易状态 SUCCESS:成功、REFUND:转入退款、NOTPAY:未支付、CLOSED:已关闭
|
|
||||||
TradeStateDesc string `json:"trade_state_desc"` // 交易描述
|
|
||||||
SuccessTime string `json:"success_time"` // 交易完成时间
|
|
||||||
AmountTotal int64 `json:"amount_total"` // 订单总金额,单位:分
|
|
||||||
PayerTotal int64 `json:"payer_total"` // 支付总金额,单位:分
|
|
||||||
}
|
|
||||||
|
|
||||||
// PayOrderQuery 查询订单状态
|
|
||||||
func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest) PayOrderQueryResponse {
|
|
||||||
var err error
|
|
||||||
var info PayOrderQueryInfo
|
|
||||||
switch payOrderQueryRequest.PayChannel {
|
|
||||||
case payCommon.PAY_CHANNLE_TYPE_WECHAT:
|
|
||||||
// 微信H5支付
|
|
||||||
info, err = WxOrderQuery(c, payOrderQueryRequest.Wx, strconv.FormatInt(payOrderQueryRequest.OrderId, 10))
|
|
||||||
case payCommon.PAY_CHANNLE_TYPE_ZFB:
|
|
||||||
info, err = ALiOrderQuery(c, payOrderQueryRequest.Ali, strconv.FormatInt(payOrderQueryRequest.OrderId, 10))
|
|
||||||
default:
|
|
||||||
return PayOrderQueryResponse{
|
|
||||||
Code: payCommon.PAY_ERROR_CODE,
|
|
||||||
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return PayOrderQueryResponse{
|
|
||||||
Code: payCommon.PAY_ERROR_CODE,
|
|
||||||
ErrorMsg: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return PayOrderQueryResponse{
|
|
||||||
Code: payCommon.PAY_SUCCESS_CODE,
|
|
||||||
Result: info,
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
|
@ -1,169 +0,0 @@
|
||||||
package paymentService
|
|
||||||
|
|
||||||
import (
|
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/go-pay/gopay"
|
|
||||||
"github.com/go-pay/gopay/wechat/v3"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
wxClient *wechat.ClientV3
|
|
||||||
clientErr error
|
|
||||||
once sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
// InitClient 使用提供的支付请求参数初始化微信客户端
|
|
||||||
func InitClient(wxConfig WxPay) {
|
|
||||||
once.Do(func() {
|
|
||||||
// NewClientV3 初始化微信客户端 v3
|
|
||||||
// mchid:商户ID 或者服务商模式的 sp_mchid
|
|
||||||
// serialNo:商户证书的证书序列号
|
|
||||||
// apiV3Key:apiV3Key,商户平台获取
|
|
||||||
// privateKey:私钥 apiclient_key.pem 读取后的内容
|
|
||||||
wxClient, clientErr = wechat.NewClientV3(
|
|
||||||
wxConfig.MchId,
|
|
||||||
wxConfig.SerialNo,
|
|
||||||
wxConfig.ApiV3Key,
|
|
||||||
wxConfig.PrivateKey,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
// 启用自动同步返回验签,并定时更新微信平台API证书(开启自动验签时,无需单独设置微信平台API证书和序列号)
|
|
||||||
clientErr = wxClient.AutoVerifySign()
|
|
||||||
|
|
||||||
// 自定义配置http请求接收返回结果body大小,默认 10MB
|
|
||||||
wxClient.SetBodySize(10) // 没有特殊需求,可忽略此配置
|
|
||||||
|
|
||||||
// 打开Debug开关,输出日志,默认是关闭的
|
|
||||||
wxClient.DebugSwitch = gopay.DebugOn
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetClient 获取已经初始化的微信客户端
|
|
||||||
func GetClient() (*wechat.ClientV3, error) {
|
|
||||||
if wxClient == nil {
|
|
||||||
return nil, errors.New("client not initialized")
|
|
||||||
}
|
|
||||||
if clientErr != nil {
|
|
||||||
return nil, clientErr
|
|
||||||
}
|
|
||||||
return wxClient, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WxH5PayInfo 微信H5支付
|
|
||||||
func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, error) {
|
|
||||||
// 初始化微信客户端
|
|
||||||
InitClient(payOrderRequest.Wx)
|
|
||||||
|
|
||||||
// 获取微信客户端
|
|
||||||
wxClient, err := GetClient()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to get client:", err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
|
||||||
// 初始化 BodyMap
|
|
||||||
bm := make(gopay.BodyMap)
|
|
||||||
bm.Set("appid", payOrderRequest.Wx.AppId).
|
|
||||||
Set("mchid", payOrderRequest.Wx.MchId).
|
|
||||||
Set("description", payOrderRequest.Description).
|
|
||||||
Set("out_trade_no", payOrderRequest.OrderId).
|
|
||||||
Set("time_expire", expire).
|
|
||||||
Set("notify_url", payCommon.WX_NOTIFY_URL).
|
|
||||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
|
||||||
bm.Set("total", payOrderRequest.Amount).
|
|
||||||
Set("currency", "CNY")
|
|
||||||
}).
|
|
||||||
SetBodyMap("scene_info", func(bm gopay.BodyMap) {
|
|
||||||
bm.Set("payer_client_ip", payOrderRequest.PayerClientIp).
|
|
||||||
SetBodyMap("h5_info", func(bm gopay.BodyMap) {
|
|
||||||
bm.Set("type", "common")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
wxRsp, err := wxClient.V3TransactionH5(c, bm)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if wxRsp.Code != wechat.Success || wxRsp.Response.H5Url == "" {
|
|
||||||
return "", errors.New(fmt.Sprintf("发起支付失败,失败状态码:%d, 失败原因:%s", wxRsp.Code, wxRsp.Error))
|
|
||||||
}
|
|
||||||
return wxRsp.Response.H5Url, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//func WxPayCallBack(notifyReq *wechat.V3NotifyReq) error {
|
|
||||||
// // 获取附加数据中的信息
|
|
||||||
// appId := notifyReq.Resource.AssociatedData
|
|
||||||
//
|
|
||||||
// payOrderRequest := PayOrderRequest{}
|
|
||||||
// // 初始化微信客户端
|
|
||||||
// InitClient(payOrderRequest)
|
|
||||||
//
|
|
||||||
// // 获取微信客户端
|
|
||||||
// wxClient, err := GetClient()
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Println("Failed to get client:", err)
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 获取微信平台证书
|
|
||||||
// certMap := wxClient.WxPublicKeyMap()
|
|
||||||
// // 验证异步通知的签名
|
|
||||||
// err = notifyReq.VerifySignByPKMap(certMap)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// objPtr := ""
|
|
||||||
// // 通用通知解密(推荐此方法)
|
|
||||||
// result := notifyReq.DecryptCipherTextToStruct(apiV3Key, objPtr)
|
|
||||||
//}
|
|
||||||
|
|
||||||
// WxOrderQuery 查询微信订单
|
|
||||||
func WxOrderQuery(ctx context.Context, wxConfig WxPay, orderNo string) (PayOrderQueryInfo, error) {
|
|
||||||
// 初始化微信客户端
|
|
||||||
InitClient(wxConfig)
|
|
||||||
|
|
||||||
// 获取微信客户端
|
|
||||||
wxClient, err := GetClient()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to get client:", err)
|
|
||||||
return PayOrderQueryInfo{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
wxRsp, err := wxClient.V3TransactionQueryOrder(ctx, payCommon.ORDER_NO_TYPE_ORDER_NO, orderNo)
|
|
||||||
if err != nil {
|
|
||||||
return PayOrderQueryInfo{}, err
|
|
||||||
}
|
|
||||||
if wxRsp.Code != wechat.Success {
|
|
||||||
return PayOrderQueryInfo{}, errors.New(fmt.Sprintf("查询订单接口错误,错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 映射交易状态
|
|
||||||
tradeState := ""
|
|
||||||
switch wxRsp.Response.TradeState {
|
|
||||||
case "SUCCESS":
|
|
||||||
tradeState = "SUCCESS"
|
|
||||||
case "REFUND":
|
|
||||||
tradeState = "REFUND"
|
|
||||||
case "NOTPAY":
|
|
||||||
tradeState = "NOTPAY"
|
|
||||||
case "CLOSED":
|
|
||||||
tradeState = "CLOSED"
|
|
||||||
}
|
|
||||||
amountTotal := wxRsp.Response.Amount.Total
|
|
||||||
payerTotal := wxRsp.Response.Amount.PayerTotal
|
|
||||||
|
|
||||||
return PayOrderQueryInfo{
|
|
||||||
AppId: wxRsp.Response.Appid,
|
|
||||||
OutTradeNo: wxRsp.Response.OutTradeNo,
|
|
||||||
TransactionId: wxRsp.Response.TransactionId,
|
|
||||||
TradeState: tradeState,
|
|
||||||
TradeStateDesc: wxRsp.Response.TradeStateDesc,
|
|
||||||
SuccessTime: wxRsp.Response.SuccessTime,
|
|
||||||
AmountTotal: int64(amountTotal),
|
|
||||||
PayerTotal: int64(payerTotal),
|
|
||||||
}, nil
|
|
||||||
}
|
|
|
@ -23,8 +23,8 @@ type CMqManager struct {
|
||||||
|
|
||||||
func (this *CMqManager) InitMq() {
|
func (this *CMqManager) InitMq() {
|
||||||
this.mqs = make(map[string]Imq)
|
this.mqs = make(map[string]Imq)
|
||||||
//this.mqs[payCommon.MQ_RABBIT] = RabbitMq{}
|
//this.mqs[common.MQ_RABBIT] = RabbitMq{}
|
||||||
//this.mqs[payCommon.MQ_NSQ] = NsqMq{}
|
//this.mqs[common.MQ_NSQ] = NsqMq{}
|
||||||
this.mqs[common3.MQ_NATS] = mq.NatsMq{}
|
this.mqs[common3.MQ_NATS] = mq.NatsMq{}
|
||||||
this.mqs[common3.MQ_KFK] = mq.KafkaMq{}
|
this.mqs[common3.MQ_KFK] = mq.KafkaMq{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*事件触发
|
*事件触发
|
||||||
event.EventManger.TrigerEvent(payCommon.Event_USER_LOG_IN, param)
|
event.EventManger.TrigerEvent(common.Event_USER_LOG_IN, param)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var EventManger *EventManagerFactory
|
var EventManger *EventManagerFactory
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -6,7 +6,6 @@ require (
|
||||||
gitee.com/chengdu_blue_brothers/openapi-go-sdk v0.0.2
|
gitee.com/chengdu_blue_brothers/openapi-go-sdk v0.0.2
|
||||||
github.com/BurntSushi/toml v0.4.1
|
github.com/BurntSushi/toml v0.4.1
|
||||||
github.com/Shopify/sarama v1.19.0
|
github.com/Shopify/sarama v1.19.0
|
||||||
github.com/ahmetb/go-linq/v3 v3.2.0
|
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||||
github.com/forgoer/openssl v1.6.0
|
github.com/forgoer/openssl v1.6.0
|
||||||
github.com/gin-gonic/gin v1.7.7
|
github.com/gin-gonic/gin v1.7.7
|
||||||
|
@ -31,14 +30,13 @@ require (
|
||||||
google.golang.org/grpc v1.56.3
|
google.golang.org/grpc v1.56.3
|
||||||
google.golang.org/protobuf v1.30.0
|
google.golang.org/protobuf v1.30.0
|
||||||
gopkg.in/go-playground/validator.v9 v9.31.0
|
gopkg.in/go-playground/validator.v9 v9.31.0
|
||||||
xorm.io/builder v0.3.9
|
|
||||||
xorm.io/xorm v1.2.5
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
github.com/PuerkitoBio/purell v1.1.1 // indirect
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||||
|
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
|
||||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
||||||
github.com/alibabacloud-go/tea v1.1.17 // indirect
|
github.com/alibabacloud-go/tea v1.1.17 // indirect
|
||||||
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
|
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
|
||||||
|
@ -120,5 +118,7 @@ require (
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
stathat.com/c/consistent v1.0.0 // indirect
|
stathat.com/c/consistent v1.0.0 // indirect
|
||||||
|
xorm.io/builder v0.3.9 // indirect
|
||||||
xorm.io/core v0.7.3 // indirect
|
xorm.io/core v0.7.3 // indirect
|
||||||
|
xorm.io/xorm v1.2.5 // indirect
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue