yop
This commit is contained in:
parent
675a6e42fb
commit
f34bf3670e
|
@ -32,6 +32,8 @@ const (
|
|||
PayTypeWxpayNative = "wxpay_native" // 微信 native
|
||||
PayTypeWxpayJsapi = "wxpay_jsapi" // 微信 jsapi
|
||||
PayTypeWxpayH5 = "wxpay_h5" // 微信支付 h5
|
||||
PayTypeYeepayAlipayH5 = "yeepay_alipay_h5" // 易宝 微信h5支付
|
||||
PayTypeYeepayWxpayH5 = "yeepay_wxpay_h5" // 易宝 微信h5支付
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -69,6 +71,8 @@ type CreateOrderData struct {
|
|||
WxpayNativeParamStr string `json:"wxpay_native_param_str"` // 微信支付 native支付参数
|
||||
WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 jsapi支付参数
|
||||
WxpayH5ParamStr string `json:"wxpay_h5_param_str"` // 微信支付 h5支付参数
|
||||
YeepayAlipayH5ParamStr string `json:"yeepay_alipay_h5_param_str"` // 易宝支付 支付宝-h5支付参数
|
||||
YeepayWxpayH5ParamStr string `json:"yeepay_wxpay_h5_param_str"` // 易宝支付 微信支付-h5支付参数
|
||||
}
|
||||
|
||||
// 预解锁联系方式
|
||||
|
@ -154,6 +158,8 @@ type H5DirectUnlockWechatData struct {
|
|||
WxpayNativeParamStr string `json:"wxpay_native_param_str"` // 微信支付 native支付参数
|
||||
WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 native
|
||||
WxpayH5ParamStr string `json:"wxpay_h5_param_str"` // 微信支付 h5支付参数
|
||||
YeepayAlipayH5ParamStr string `json:"yeepay_alipay_h5_param_str"` // 易宝支付 支付宝-h5支付参数
|
||||
YeepayWxpayH5ParamStr string `json:"yeepay_wxpay_h5_param_str"` // 易宝支付 微信支付-h5支付参数
|
||||
}
|
||||
|
||||
// 支付宝回调参数
|
||||
|
|
|
@ -168,6 +168,8 @@ type ZoneCreateOrderData struct {
|
|||
WxpayNativeParamStr string `json:"wxpay_native_param_str"` // 微信支付 native支付参数
|
||||
WxpayJsapiParamObj wxpaycli.JsapiPayResp `json:"wxpay_jsapi_param_obj"` // 微信支付 jsapi支付参数
|
||||
WxpayH5ParamStr string `json:"wxpay_h5_param_str"` // 微信支付 h5支付参数
|
||||
YeepayAlipayH5ParamStr string `json:"yeepay_alipay_h5_param_str"` // 易宝支付 支付宝-h5支付参数
|
||||
YeepayWxpayH5ParamStr string `json:"yeepay_wxpay_h5_param_str"` // 易宝支付 微信支付-h5支付参数
|
||||
}
|
||||
|
||||
type ZoneCreateOrderResp struct {
|
||||
|
|
|
@ -22,4 +22,5 @@ type ConfigSt struct {
|
|||
DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人
|
||||
VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核
|
||||
ElasticSearch *configcenter.ElasticSearchConfig `json:"elastic_search" yaml:"elastic_search"` // es
|
||||
Yeepay *configcenter.YeepayClientConfig `json:"yeepay" yaml:"yeepay"`
|
||||
}
|
||||
|
|
|
@ -293,6 +293,7 @@ func Init(r *gin.Engine) {
|
|||
extVasPayGroup := r.Group("/ext/vas")
|
||||
extVasPayGroup.POST("alipay_callback", AlipayCallback)
|
||||
extVasPayGroup.POST("wxpay_callback", WxpayCallback)
|
||||
extVasPayGroup.POST("yeepay_callback", YeepayCallback)
|
||||
|
||||
opVasPayGroup := r.Group("/op/vas", PrepareOp())
|
||||
opVasPayGroup.POST("create_order", middleware.JSONParamValidator(vasproto.OpCreateOrderReq{}), OpCreateOrder)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"service/bizcommon/util"
|
||||
"service/library/logger"
|
||||
"service/library/payclients/yeepaycli"
|
||||
)
|
||||
|
||||
func YeepayCallback(ctx *gin.Context) {
|
||||
//req, _ := ctx.GetRawData()
|
||||
//logger.Info("_AlipayCallback req: %v", string(req))
|
||||
err := yeepaycli.GetDefaultYeepayClient().ParseNotify(ctx.Request)
|
||||
if err != nil {
|
||||
logger.Error("ParseNotify fail, req: %v, err: %v", util.ToJson(""), err)
|
||||
return
|
||||
}
|
||||
|
||||
//ctx.String(200, "success")
|
||||
}
|
|
@ -21,6 +21,7 @@ import (
|
|||
"service/library/logger"
|
||||
"service/library/payclients/alipaycli"
|
||||
"service/library/payclients/wxpaycli"
|
||||
"service/library/payclients/yeepaycli"
|
||||
"time"
|
||||
|
||||
"github.com/go-pay/gopay/alipay"
|
||||
|
@ -134,6 +135,8 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
|
|||
wxpayNativeParamStr string
|
||||
wxpayJsapiParamObj wxpaycli.JsapiPayResp
|
||||
wxpayH5ParamStr string
|
||||
yeepayAlipayH5ParamStr string
|
||||
yeepayWxpayH5ParamStr string
|
||||
)
|
||||
|
||||
defer func() {
|
||||
|
@ -296,6 +299,50 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
|
|||
return
|
||||
}
|
||||
req.Oid3 = wxpayCli.AppId
|
||||
case vasproto.PayTypeYeepayAlipayH5:
|
||||
var aggPayResp *yeepaycli.AggPayResp
|
||||
yeepayCli := yeepaycli.GetDefaultYeepayClient()
|
||||
aggPayParam := &yeepaycli.AggPayParam{
|
||||
Description: product.Subject,
|
||||
OutTradeNo: orderId,
|
||||
TotalAmount: product.RealPrice,
|
||||
PayWay: yeepaycli.YeepayWayH5,
|
||||
PayChannel: yeepaycli.YeepayChannelAlipay,
|
||||
Ip: ctx.ClientIP(),
|
||||
}
|
||||
// 给个默认ip
|
||||
if len(aggPayParam.Ip) <= 0 {
|
||||
aggPayParam.Ip = "112.124.18.6"
|
||||
}
|
||||
aggPayResp, err = yeepayCli.AggPay(ctx, aggPayParam)
|
||||
if err != nil {
|
||||
logger.Error("YeepayAlipayH5 fail, req: %v, aggPayParam: %v, err: %v", util.ToJson(req), util.ToJson(aggPayParam), err)
|
||||
return
|
||||
}
|
||||
yeepayAlipayH5ParamStr = aggPayResp.PrePayTn
|
||||
req.Oid3 = yeepayCli.AppId
|
||||
case vasproto.PayTypeYeepayWxpayH5:
|
||||
var aggPayResp *yeepaycli.AggPayResp
|
||||
yeepayCli := yeepaycli.GetDefaultYeepayClient()
|
||||
aggPayParam := &yeepaycli.AggPayParam{
|
||||
Description: product.Subject,
|
||||
OutTradeNo: orderId,
|
||||
TotalAmount: product.RealPrice,
|
||||
PayWay: yeepaycli.YeepayWayH5,
|
||||
PayChannel: yeepaycli.YeepayChannelWxpay,
|
||||
Ip: ctx.ClientIP(),
|
||||
}
|
||||
// 给个默认ip
|
||||
if len(aggPayParam.Ip) <= 0 {
|
||||
aggPayParam.Ip = "112.124.18.6"
|
||||
}
|
||||
aggPayResp, err = yeepayCli.AggPay(ctx, aggPayParam)
|
||||
if err != nil {
|
||||
logger.Error("YeepayWxpayH5 fail, req: %v, aggPayParam: %v, err: %v", util.ToJson(req), util.ToJson(aggPayParam), err)
|
||||
return
|
||||
}
|
||||
yeepayWxpayH5ParamStr = aggPayResp.PrePayTn
|
||||
req.Oid3 = yeepayCli.AppId
|
||||
}
|
||||
|
||||
// 添加订单
|
||||
|
@ -340,6 +387,8 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
|
|||
WxpayNativeParamStr: wxpayNativeParamStr,
|
||||
WxpayJsapiParamObj: wxpayJsapiParamObj,
|
||||
WxpayH5ParamStr: wxpayH5ParamStr,
|
||||
YeepayAlipayH5ParamStr: yeepayAlipayH5ParamStr,
|
||||
YeepayWxpayH5ParamStr: yeepayWxpayH5ParamStr,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1119,6 +1168,8 @@ func (v *Vas) H5DirectUnlockWechat(ctx *gin.Context, req *vasproto.H5DirectUnloc
|
|||
WxpayNativeParamStr: cData.WxpayNativeParamStr,
|
||||
WxpayJsapiParamObj: cData.WxpayJsapiParamObj,
|
||||
WxpayH5ParamStr: cData.WxpayH5ParamStr,
|
||||
YeepayAlipayH5ParamStr: cData.YeepayAlipayH5ParamStr,
|
||||
YeepayWxpayH5ParamStr: cData.YeepayWxpayH5ParamStr,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -265,6 +265,8 @@ func (v *Vas) ZoneCreateOrder(ctx *gin.Context, req *vasproto.ZoneCreateOrderReq
|
|||
WxpayNativeParamStr: createOrderData.WxpayNativeParamStr,
|
||||
WxpayJsapiParamObj: createOrderData.WxpayJsapiParamObj,
|
||||
WxpayH5ParamStr: createOrderData.WxpayH5ParamStr,
|
||||
YeepayAlipayH5ParamStr: createOrderData.YeepayAlipayH5ParamStr,
|
||||
YeepayWxpayH5ParamStr: createOrderData.YeepayWxpayH5ParamStr,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import (
|
|||
"service/library/mycrypto"
|
||||
"service/library/payclients/alipaycli"
|
||||
"service/library/payclients/wxpaycli"
|
||||
"service/library/payclients/yeepaycli"
|
||||
"service/library/redis"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -170,6 +171,8 @@ func (s *Service) Init(c any) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
yeepaycli.Init(cfg.Yeepay)
|
||||
|
||||
_DefaultToken = logic.NewToken(store, cfg.Crypto)
|
||||
_DefaultVeriCode = logic.NewVeriCode(store, cfg.Dysmsapi)
|
||||
_DefaultVeriCodeSendTimes = logic.NewVeriCodeSendTimes(store)
|
||||
|
|
|
@ -2,10 +2,11 @@ package yeepaycli
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/yop-platform/yop-go-sdk/yop/client"
|
||||
"github.com/yop-platform/yop-go-sdk/yop/constants"
|
||||
"github.com/yop-platform/yop-go-sdk/yop/request"
|
||||
"github.com/yop-platform/yop-go-sdk/yop/response"
|
||||
yoputils "github.com/yop-platform/yop-go-sdk/yop/utils"
|
||||
"net/http"
|
||||
"service/bizcommon/util"
|
||||
"service/library/configcenter"
|
||||
|
@ -13,6 +14,15 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
YeepayWayH5 = "H5_PAY" // h5支付
|
||||
)
|
||||
|
||||
const (
|
||||
YeepayChannelWxpay = "WECHAT" // 易宝支付微信
|
||||
YeepayChannelAlipay = "ALIPAY" // 易宝支付支付宝
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultOrderTimeoutSeconds = 900 // 默认订单超时时间,单位: s
|
||||
)
|
||||
|
@ -50,8 +60,40 @@ func Init(cfg *configcenter.YeepayClientConfig) {
|
|||
}
|
||||
|
||||
// 验签
|
||||
func (c *YeepayClient) ParseNotify() {
|
||||
type YeepayNotify struct {
|
||||
ChannelOrderId string `json:"channelOrderId"`
|
||||
OrderId string `json:"orderId"`
|
||||
BankOrderId string `json:"bankOrderId"`
|
||||
PaySuccessDate string `json:"paySuccessDate"`
|
||||
Channel string `json:"channel"`
|
||||
PayWay string `json:"payWay"`
|
||||
UniqueOrderNo string `json:"uniqueOrderNo"`
|
||||
OrderAmount string `json:"orderAmount"`
|
||||
PayAmount string `json:"payAmount"`
|
||||
PayerInfo string `json:"payerInfo"`
|
||||
RealPayAmount string `json:"realPayAmount"`
|
||||
ParentMerchantNo string `json:"parentMerchantNo"`
|
||||
MerchantNo string `json:"merchantNo"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (c *YeepayClient) ParseNotify(req *http.Request) error {
|
||||
if err := req.ParseForm(); err != nil {
|
||||
logger.Error("Yeepay ParseForm fail, err: %v", err)
|
||||
return err
|
||||
}
|
||||
var (
|
||||
response = req.Form.Get("response")
|
||||
appKey = req.Form.Get("customerIdentification")
|
||||
)
|
||||
logger.Info("YeepayCallback notify, response: %v, appKey: %v", response, appKey)
|
||||
content, err := yoputils.DecryptCallback(request.YOP_PLATFORM_PUBLIC_KEY, c.PrivateKey, response)
|
||||
if err != nil {
|
||||
logger.Error("Yeepay DecryptCallback fail, form: %v, err: %v", req.Form.Encode(), err)
|
||||
return err
|
||||
}
|
||||
logger.Info("Yeepay ParseNotify, %v", util.ToJson(content))
|
||||
return nil
|
||||
}
|
||||
|
||||
// 易宝支付 聚合支付
|
||||
|
@ -65,7 +107,16 @@ type AggPayParam struct {
|
|||
Ip string
|
||||
}
|
||||
|
||||
func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *response.YopResponse, err error) {
|
||||
type AggPayResp struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
OrderId string `json:"orderId"`
|
||||
UniqueOrderNo string `json:"uniqueOrderNo"`
|
||||
BankOrderId string `json:"bankOrderId"`
|
||||
PrePayTn string `json:"prePayTn"`
|
||||
}
|
||||
|
||||
func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *AggPayResp, err error) {
|
||||
req := request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/aggpay/tutelage/pre-pay")
|
||||
req.AppId = c.AppId
|
||||
req.IsvPriKey = request.IsvPriKey{Value: c.PrivateKey, CertType: request.RSA2048}
|
||||
|
@ -81,10 +132,14 @@ func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *re
|
|||
req.AddParam("scene", "ONLINE")
|
||||
req.AddParam("userIp", param.Ip)
|
||||
|
||||
resp, err = c.client.Request(req)
|
||||
respMeta, err := c.client.Request(req)
|
||||
if err != nil {
|
||||
logger.Error("yeepay AggPay fail, param: %v, respMeta: %v, err: %v", util.ToJson(req.Params), util.ToJson(respMeta), err)
|
||||
return
|
||||
}
|
||||
resp = new(AggPayResp)
|
||||
b, _ := json.Marshal(respMeta.Result)
|
||||
_ = json.Unmarshal(b, resp)
|
||||
logger.Info("yeepay AggPay param: %v, resp: %v", util.ToJson(req.Params), util.ToJson(resp))
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"channelOrderId": "332022021622001422971445123456",
|
||||
"orderId": "DQD620CUD57Q8A3123456",
|
||||
"bankOrderId": "ST5207953516123456",
|
||||
"paySuccessDate": "2022-02-16 20:26:05",
|
||||
"channel": "ALIPAY",
|
||||
"payWay": "MINI_PROGRAM",
|
||||
"uniqueOrderNo": "1013202202160000003222123456",
|
||||
"orderAmount": "2.00",
|
||||
"payAmount": "2.00",
|
||||
"payerInfo": "{\"bankCardNo\":\"\",\"bankId\":\"ALIPAY\",\"buyerLogonId\":\"136****1013\",\"mobilePhoneNo\":\"\",\"userID\":\"2088502619123456\"}",
|
||||
"realPayAmount": "2.00",
|
||||
"parentMerchantNo": "10085123456",
|
||||
"merchantNo": "10085123456",
|
||||
"status": "SUCCESS"
|
||||
}
|
Loading…
Reference in New Issue