支付和广告调试
This commit is contained in:
+31
-12
@@ -14,11 +14,23 @@ import (
|
||||
)
|
||||
|
||||
type PayTypeParam struct {
|
||||
Moneys []int64 `json:"moneys"`
|
||||
DevType string `json:"devType"`
|
||||
ProductType int `json:"productType"` //产品类型 0站群 1棋牌
|
||||
UserLevel int `json:"userLevel"` //限定用户层级 (0默认无等级 1充值成功过的1等级)
|
||||
PlatformID string `json:"platformID"` //平台
|
||||
Moneys []int64 `json:"moneys"`
|
||||
DevType string `json:"devType"`
|
||||
ProductType int `json:"productType"` //产品类型 0站群 1棋牌
|
||||
UserLevel int `json:"userLevel"` //限定用户层级 (0默认无等级 1充值成功过的1等级)
|
||||
PlatformID string `json:"platformID"` //平台
|
||||
DistrictCode string `json:"districtCode"` //用户渠道码 支付中心据此绑定可用支付渠道
|
||||
}
|
||||
|
||||
// BillPlatformID 账单中心平台标识
|
||||
const BillPlatformID = "逼哩逼哩"
|
||||
|
||||
// billDevType 账单中心设备类型,非android按ios处理
|
||||
func billDevType(devType string) string {
|
||||
if devType != "android" {
|
||||
return "ios"
|
||||
}
|
||||
return devType
|
||||
}
|
||||
|
||||
type RchgType struct {
|
||||
@@ -40,13 +52,19 @@ type StdMsg struct {
|
||||
|
||||
// GetPayType 从支付中心获取充值金额对应的充值方式
|
||||
func GetPayType(ctx context.Context, moneys []int64, devType string, productType, userLevel int) ([]RchgType, error) {
|
||||
return GetPayTypeByDistrict(ctx, moneys, devType, productType, userLevel, "")
|
||||
}
|
||||
|
||||
// GetPayTypeByDistrict 从支付中心获取充值金额对应的充值方式(按用户渠道码匹配)
|
||||
func GetPayTypeByDistrict(ctx context.Context, moneys []int64, devType string, productType, userLevel int, districtCode string) ([]RchgType, error) {
|
||||
var errlog string
|
||||
p := PayTypeParam{
|
||||
moneys,
|
||||
devType,
|
||||
productType,
|
||||
userLevel,
|
||||
"91PORN",
|
||||
Moneys: moneys,
|
||||
DevType: billDevType(devType),
|
||||
ProductType: productType,
|
||||
UserLevel: userLevel,
|
||||
PlatformID: BillPlatformID,
|
||||
DistrictCode: districtCode,
|
||||
}
|
||||
res := StdMsg{}
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&res, p.GetURL(), nil, p.GetBody())
|
||||
@@ -143,14 +161,15 @@ func (this *Rchg) ToPayNew(ctx context.Context) (res RchgMsg, err error) {
|
||||
|
||||
// GetURL 获取请求地址
|
||||
func (this *Rchg) fill() {
|
||||
this.PlatformID = "91PORN"
|
||||
this.PlatformID = BillPlatformID
|
||||
if this.ProductType == 0 {
|
||||
this.TransNo = RChgIDAssemble(this.TransNo)
|
||||
}
|
||||
if this.ProductType == 1 {
|
||||
this.TransNo = RChgWLIDAssemble(this.TransNo)
|
||||
}
|
||||
this.NotifyUrl = appg.Conf.URL.LocalWebUrl + RCHG_NOTIFY_URL + "bill"
|
||||
// 回调路由 /3rd/defray/callback/rchg/:name 挂在 app 服务上
|
||||
this.NotifyUrl = appg.Conf.PayCenter.CallbackUrl + RCHG_NOTIFY_URL + "bill"
|
||||
this.PType = this.PayMethod
|
||||
}
|
||||
|
||||
|
||||
+37
-54
@@ -26,14 +26,11 @@ import (
|
||||
|
||||
var payTypeCacheGroup singleflight.Group
|
||||
|
||||
// GainPayTypeReq 按金额查询支付通道(账单中心 /api/recharge/payType)
|
||||
type GainPayTypeReq struct {
|
||||
Time string `json:"time" bson:"time"` // 时间戳,最大长度50,必填
|
||||
Sign string `json:"sign" bson:"sign"` // 签名,最大长度100,必填
|
||||
MercID string `json:"mercId" bson:"mercId"` // 商户ID,最大长度50,必填
|
||||
Money []string `json:"money" bson:"money"` // 金额数组,必填
|
||||
Mode string `json:"mode,omitempty"` // 支付模式,兼容商户版本迭代,传sdk表示支持sdk模式,可选
|
||||
Payload string `json:"payload,omitempty"` // 备用参数:1-不匹配赔付渠道 2-空单 3-兑换划转,可选
|
||||
|
||||
Money []string // 金额数组(元),必填
|
||||
DevType string // 设备类型 android/ios,非android按ios处理
|
||||
DistrictCode string // 用户渠道码,支付中心据此绑定可用支付渠道
|
||||
}
|
||||
|
||||
type AllPayType struct {
|
||||
@@ -59,7 +56,7 @@ func (in *GainPayTypeReq) GetPayTypeFromCache() (bc []AllPayType, err error) {
|
||||
// 金额排序
|
||||
sort.Strings(in.Money)
|
||||
|
||||
redisKey := fmt.Sprintf("paycenter-channels:%s", strings.Join(in.Money, "-"))
|
||||
redisKey := fmt.Sprintf("paycenter-channels:%s:%s:%s", billDevType(in.DevType), in.DistrictCode, strings.Join(in.Money, "-"))
|
||||
value, err, _ := payTypeCacheGroup.Do(redisKey, func() (interface{}, error) {
|
||||
str, cacheErr := appg.Redis.Get(redisKey)
|
||||
if cacheErr != nil {
|
||||
@@ -114,47 +111,46 @@ func decodeCachedPayTypes(raw string) ([]AllPayType, error) {
|
||||
return nil, fmt.Errorf("json decode: %v; msgpack decode: %v", jsonErr, msgpackErr)
|
||||
}
|
||||
|
||||
// GetPayType 从支付中心获取充值金额对应的充值方式
|
||||
// GetPayType 从账单中心获取充值金额对应的充值方式
|
||||
func (in *GainPayTypeReq) GetPayType() ([]AllPayType, error) {
|
||||
res := GainPayTypeResp{}
|
||||
code, err := httputil.DefaultClientPostJsonWithResp(&res, in.GetURL(), nil, in.GetBody())
|
||||
moneys := make([]int64, 0, len(in.Money))
|
||||
for _, m := range in.Money {
|
||||
moneys = append(moneys, YuanToFen(m))
|
||||
}
|
||||
rchgTypes, err := GetPayTypeByDistrict(context.Background(), moneys, in.DevType, 0, 0, in.DistrictCode)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("param:%+v,get pay type in bill center failed err:%v", in, err))
|
||||
return nil, errors.New(fmt.Sprintf("bill GetPayType requset fail \nerror:%+v\n\ndata:%+v;", err, in))
|
||||
return nil, err
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error(fmt.Sprintf("code:%v,get pay type response status exception", code))
|
||||
return nil, errors.New(fmt.Sprintf("bill GetPayType response status exception;\nstatus %+v;", code))
|
||||
payTypes := make([]AllPayType, 0, len(rchgTypes))
|
||||
for _, r := range rchgTypes {
|
||||
payTypes = append(payTypes, r.ToAllPayType())
|
||||
}
|
||||
if res.Code != 200 {
|
||||
log.Error(fmt.Sprintf("bill GetPayType be rejected;\n param:%+v, err:%+v:", in, res))
|
||||
return nil, errors.New("bill GetPayType be rejected")
|
||||
}
|
||||
bytes, err := json.Marshal(res.Msg)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("bill payUrl urlDecode fail error:%+v;", err))
|
||||
return nil, errors.New("getPayType json Marshal error")
|
||||
}
|
||||
var payTypes []AllPayType
|
||||
if err = json.Unmarshal(bytes, &payTypes); err != nil {
|
||||
log.Error(fmt.Sprintf("bill payUrl urlDecode fail error:%+v;", err))
|
||||
return nil, errors.New("bill payUrl urlDecode fail error")
|
||||
}
|
||||
log.Debug("bill GetPayType success", log.Any("payTypeCount", len(payTypes)))
|
||||
return payTypes, nil
|
||||
}
|
||||
|
||||
// GetBody 获取请求body
|
||||
func (in *GainPayTypeReq) GetBody() []byte {
|
||||
in.MercID = appg.Conf.PayCenter.MercID
|
||||
in.Time = Generate13DigitString()
|
||||
in.Sign = in.GenerateSign()
|
||||
data, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("bill GetBody json.Marshal is fail error:%+v/data:%+v", err, in))
|
||||
return nil
|
||||
// ToAllPayType 转换为按金额分组的支付类型列表
|
||||
func (r RchgType) ToAllPayType() AllPayType {
|
||||
res := AllPayType{
|
||||
Money: fmt.Sprintf("%d.%02d", r.Money/100, r.Money%100),
|
||||
Types: make([]mercPayTypeInfo, 0),
|
||||
}
|
||||
return data
|
||||
enabled := []struct {
|
||||
ok bool
|
||||
t string
|
||||
}{
|
||||
{r.Alipay, Alipay},
|
||||
{r.Wechat, Wechat},
|
||||
{r.Union, "union"},
|
||||
{r.QuickUnion, "quickUnion"},
|
||||
{r.USDT, "usdt"},
|
||||
{r.DaiChong, "daichong"},
|
||||
}
|
||||
for _, e := range enabled {
|
||||
if e.ok {
|
||||
res.Types = append(res.Types, mercPayTypeInfo{Name: e.t, Type: e.t})
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func Generate13DigitString() string {
|
||||
@@ -169,19 +165,6 @@ func generateMD5(text string) string {
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
// GenerateSign 生成加密
|
||||
func (in *GainPayTypeReq) GenerateSign() string {
|
||||
// 默认签名方式1: md5(value+value)
|
||||
signStr := in.MercID + strings.Join(in.Money, "") + appg.Conf.PayCenter.MercSecret
|
||||
sign := generateMD5(signStr)
|
||||
return sign
|
||||
}
|
||||
|
||||
// GetURL 获取请求地址
|
||||
func (in *GainPayTypeReq) GetURL() string {
|
||||
return appg.Conf.PayCenter.ApiUrl + "/api/shark/getPayType"
|
||||
}
|
||||
|
||||
type Recharge struct {
|
||||
Time string `json:"time" bson:"time"` // 时间戳,最大长度50,必填
|
||||
Sign string `json:"sign" bson:"sign"` // 签名,最大长度100,必填
|
||||
|
||||
Reference in New Issue
Block a user