Compare commits

...

3 Commits

Author SHA1 Message Date
ayflying
ee32c8b83d 更新支持配置代理地址配置 2025-07-11 14:07:56 +08:00
ayflying
12a193fdee 增加oppo支付回调库 2025-07-09 11:01:38 +08:00
ayflying
ca55880beb 小米支付的回调结构体放入库 2025-07-09 10:58:27 +08:00
4 changed files with 156 additions and 4 deletions

View File

@@ -124,11 +124,11 @@ var (
FileUrl: url[v.S3],
})
if err != nil {
Proxy := g.Cfg().MustGet(ctx, "update_proxy", "http://192.168.50.170:10808").String()
g.Log().Debugf(ctx, "切换代理进行上传:err=%v", err)
get, err = client.Proxy("http://192.168.50.114:10808").
Post(ctx, address+"/callback/update", &UpdateReq{
FileUrl: url[v.S3],
})
get, err = client.Proxy(Proxy).Post(ctx, address+"/callback/update", &UpdateReq{
FileUrl: url[v.S3],
})
}
if err != nil {
g.Log().Error(ctx, err)

13
package/pay/oppo/model.go Normal file
View File

@@ -0,0 +1,13 @@
package oppo
// OPPO支付回调参数结构体
type PayCallback struct {
NotifyId string `json:"notifyId" dc:"回调通知单号以GC开头必填示例:GC20230314657000"`
PartnerOrder string `json:"partnerOrder" dc:"开发者订单号,必填,示例:123456"`
ProductName string `json:"productName" dc:"商品名称,必填,示例:10元宝"`
ProductDesc string `json:"productDesc" dc:"商品描述,必填,示例:10元宝等于1元"`
Price int64 `json:"price" dc:"商品价格,单位为分,需要游戏服务端做验证,必填,示例:100"`
Count int `json:"count" dc:"商品数量一般为1必填示例:1"`
Attach string `json:"attach" dc:"请求支付时上传的附加参数,可能为空,选填"`
Sign string `json:"sign" dc:"OPPO服务端签名需要游戏服务端做验证必填"`
}

119
package/pay/oppo/oppo.go Normal file
View File

@@ -0,0 +1,119 @@
package oppo
import (
"context"
"crypto"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"net/http"
"strings"
)
// 跟充值平台通信的加密key
//const PUBLIC_KEY = `dfsdfs`
type OppoType struct {
PublicKey string `json:"public_key"`
}
func New(PublicKey string) *OppoType {
return &OppoType{
PublicKey: PublicKey,
}
}
func (p *OppoType) Verify(ctx context.Context, data map[string]string) error {
// 解析请求参数
for k, v := range data {
if v == "" || v == "0" {
delete(data, k)
}
}
//data["notifyId"] = getParam(r, "notifyId")
//data["partnerOrder"] = getParam(r, "partnerOrder")
//data["productName"] = getParam(r, "productName")
//data["productDesc"] = getParam(r, "productDesc")
//data["price"] = getParam(r, "price")
//data["count"] = getParam(r, "count")
//data["attach"] = getParam(r, "attach")
//data["sign"] = getParam(r, "sign")
// 验证签名
result, err := p.rsaVerify(data)
if err != nil {
//http.Error(w, "Verification error: "+err.Error(), http.StatusInternalServerError)
g.Log().Errorf(ctx, "Verification error: %v", err.Error())
return err
}
if result {
// TODO::验证成功,处理后续逻辑
//fmt.Fprint(w, "Verification successful")
//g.Log().Errorf(ctx, "Verification error: %v", err.Error())
} else {
// TODO::验证失败,处理后续逻辑
//http.Error(w, "Verification failed", http.StatusBadRequest)
g.Log().Error(ctx, "Verification failed")
err = gerror.New("Verification failed")
}
return nil
}
func (p *OppoType) getParam(r *http.Request, paramName string) string {
r.ParseForm()
if value := r.FormValue(paramName); value != "" {
return strings.TrimSpace(value)
}
return ""
}
func (p *OppoType) rsaVerify(contents map[string]string) (bool, error) {
// 构建待签名字符串
strContents := fmt.Sprintf("notifyId=%s&partnerOrder=%s&productName=%s&productDesc=%s&price=%s&count=%s&attach=%s",
contents["notifyId"], contents["partnerOrder"], contents["productName"],
contents["productDesc"], contents["price"], contents["count"], contents["attach"])
// 解析公钥
publicKey := p.PublicKey
pemData := []byte("-----BEGIN PUBLIC KEY-----\n" +
strings.ReplaceAll(publicKey, " ", "\n") +
"\n-----END PUBLIC KEY-----")
block, _ := pem.Decode(pemData)
if block == nil {
return false, fmt.Errorf("failed to decode PEM block")
}
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return false, err
}
pubKey, ok := pubInterface.(*rsa.PublicKey)
if !ok {
return false, fmt.Errorf("public key is not an RSA public key")
}
// 解码签名
signature, err := base64.StdEncoding.DecodeString(contents["sign"])
if err != nil {
return false, err
}
// 计算内容的哈希值
hash := sha1.New()
hash.Write([]byte(strContents))
hashed := hash.Sum(nil)
// 验证签名
err = rsa.VerifyPKCS1v15(pubKey, crypto.SHA1, hashed, signature)
return err == nil, err
}

View File

@@ -0,0 +1,20 @@
package xiaomi
import "github.com/gogf/gf/v2/os/gtime"
type PayCallback struct {
AppID string `json:"appId" dc:"游戏ID" required:"true"`
CPOrderID string `json:"cpOrderId" dc:"开发商订单ID" required:"true"`
CPUserInfo string `json:"cpUserInfo" dc:"开发商透传信息" required:"false"`
OrderConsumeType int `json:"orderConsumeType" dc:"订单类型10普通订单 11直充直消订单" required:"false"`
OrderID string `json:"orderId" dc:"游戏平台订单ID" required:"true"`
OrderStatus string `json:"orderStatus" dc:"订单状态TRADE_SUCCESS代表成功" required:"true"`
PayFee int `json:"payFee" dc:"支付金额单位为分即0.01米币。请务必使用payFee字段值与游戏发起订单金额做校验确保订单金额一致性" required:"true"`
PayTime *gtime.Time `json:"payTime" dc:"支付时间格式yyyy-MM-dd HH:mm:ss" required:"true"`
ProductCode string `json:"productCode" dc:"商品代码" required:"true"`
ProductCount int `json:"productCount" dc:"商品数量" required:"true"`
ProductName string `json:"productName" dc:"商品名称" required:"true"`
UID string `json:"uid" dc:"用户ID" required:"true"`
PartnerGiftConsume int64 `json:"partnerGiftConsume" dc:"使用游戏券金额如果订单使用游戏券则有long型如果有则参与签名" required:"false"`
Signature string `json:"signature" dc:"签名,签名方法见后面说明" required:"true"`
}