Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package jiahua
|
||||
|
||||
import "time"
|
||||
|
||||
// PayTypeParam 查询支付通道请求参数
|
||||
type PayTypeParam struct {
|
||||
Moneys []int64 `json:"moneys"`
|
||||
DevType string `json:"devType"`
|
||||
PlatformID string `json:"platformID"`
|
||||
}
|
||||
|
||||
// RchgType 支付通道信息
|
||||
type RchgType struct {
|
||||
Money int64 `json:"money"`
|
||||
Alipay bool `json:"alipay"`
|
||||
Wechat bool `json:"wechat"`
|
||||
Union bool `json:"union"`
|
||||
}
|
||||
|
||||
// PayCenterMsg 查询支付通道响应
|
||||
type PayCenterMsg struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []RchgType `json:"data"`
|
||||
}
|
||||
|
||||
// PayCenterRchg 下单请求参数
|
||||
type PayCenterRchg struct {
|
||||
TransNo string `json:"transNo"`
|
||||
PlatformID string `json:"platformID"`
|
||||
UID string `json:"uid"`
|
||||
DevID string `json:"devID"`
|
||||
UserIP string `json:"userIP"`
|
||||
Name string `json:"name"`
|
||||
DevType string `json:"devType"`
|
||||
Money int64 `json:"money"`
|
||||
Channel string `json:"channel"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
NotifyUrl string `json:"notifyUrl"`
|
||||
PType string `json:"pType"`
|
||||
PayMethod string `json:"payMethod"`
|
||||
}
|
||||
|
||||
// PayCenterRchgMsg 下单响应
|
||||
type PayCenterRchgMsg struct {
|
||||
Err string `json:"err"`
|
||||
PayUrl string `json:"payUrl"`
|
||||
OID string `json:"oid"`
|
||||
Mode string `json:"mode"`
|
||||
CID string `json:"cid"`
|
||||
Rate string `json:"rate"`
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package jiahua
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"videoweb/app/appg"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
const (
|
||||
notifyURLSuffix = "/api/web/third/paycenter/bill/callback"
|
||||
)
|
||||
|
||||
// GetPayChannelByMoney 向嘉华支付中心查询指定金额(分)支持的支付方式
|
||||
func GetPayChannelByMoney(ctx context.Context, moneys []int64, devType string) ([]RchgType, *srvdef.SrvErr) {
|
||||
if devType != "android" {
|
||||
devType = "ios"
|
||||
}
|
||||
param := PayTypeParam{
|
||||
Moneys: moneys,
|
||||
DevType: devType,
|
||||
PlatformID: pubdef.AppNameZhifu,
|
||||
}
|
||||
reqBody, err := json.Marshal(param)
|
||||
if err != nil {
|
||||
return nil, srvdef.New(srvdef.Err, "", err.Error())
|
||||
}
|
||||
resp := &PayCenterMsg{}
|
||||
url := appg.Conf.TransactionUrl + "/api/recharge/payType"
|
||||
code, err := utils.POSTJsonWithJResp(resp, url, nil, reqBody)
|
||||
if err != nil {
|
||||
log.Error("jiahua:GetPayChannelByMoney failed", log.Any("url", url), log.E(err))
|
||||
return nil, srvdef.New(srvdef.Err, "查询支付通道失败", err.Error())
|
||||
}
|
||||
if code != http.StatusOK || resp.Code != 200 {
|
||||
log.Error("jiahua:GetPayChannelByMoney bad resp", log.Any("code", code), log.Any("resp.Code", resp.Code))
|
||||
return nil, srvdef.New(srvdef.Err, "查询支付通道失败", "")
|
||||
}
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
// SubmitOrder 向嘉华支付中心提交下单
|
||||
// 返回 SubmitVipOrderInfo(含 PayUrl、Oid 等),供调用方存入本地订单。
|
||||
func SubmitOrder(ctx context.Context,
|
||||
userId int64, userName string,
|
||||
tradeNo string, amount int64,
|
||||
payMode string, sysType string, devType string, ip string,
|
||||
) (*pubdef.SubmitVipOrderInfo, *srvdef.SrvErr) {
|
||||
|
||||
reqParam := &PayCenterRchg{
|
||||
TransNo: tradeNo,
|
||||
PlatformID: pubdef.AppNameZhifu,
|
||||
UID: strconv.FormatInt(userId, 10),
|
||||
Name: userName,
|
||||
UserIP: ip,
|
||||
DevType: sysType,
|
||||
Money: amount,
|
||||
Channel: "self",
|
||||
CreatedAt: time.Now(),
|
||||
PayMethod: payMode,
|
||||
PType: payMode,
|
||||
NotifyUrl: appg.Conf.LocalWebUrl + notifyURLSuffix,
|
||||
}
|
||||
|
||||
reqBody, err := json.Marshal(reqParam)
|
||||
if err != nil {
|
||||
return nil, srvdef.New(srvdef.Err, "", err.Error())
|
||||
}
|
||||
|
||||
resp := &PayCenterRchgMsg{}
|
||||
url := appg.Conf.TransactionUrl + "/api/recharge/recharge"
|
||||
code, err := utils.POSTJsonWithJResp(resp, url, nil, reqBody)
|
||||
if err != nil {
|
||||
log.Error("jiahua:SubmitOrder POSTJsonWithJResp failed", log.Any("url", url), log.E(err))
|
||||
return nil, srvdef.New(srvdef.Err, "调用支付中心失败", err.Error())
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("jiahua:SubmitOrder bad http code", log.Any("code", code))
|
||||
return nil, srvdef.New(srvdef.Err, "调用支付中心失败", "")
|
||||
}
|
||||
if resp.Err != "" {
|
||||
log.Error("jiahua:SubmitOrder resp error", log.Any("err", resp.Err), log.Any("tradeNo", tradeNo))
|
||||
return nil, srvdef.New(srvdef.Err, "支付中心下单失败", resp.Err)
|
||||
}
|
||||
|
||||
return &pubdef.SubmitVipOrderInfo{
|
||||
TradeNo: tradeNo,
|
||||
Oid: resp.OID,
|
||||
PayUrl: resp.PayUrl,
|
||||
PayUrlMode: resp.Mode,
|
||||
PayChannel: resp.CID,
|
||||
PayRate: resp.Rate,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user