mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-08 07:03:42 +08:00
移除不必要的功能
This commit is contained in:
@@ -24,31 +24,23 @@ type AmountRequest struct {
|
||||
TopUpCode string `json:"top_up_code"`
|
||||
}
|
||||
|
||||
//var client, _ = epay.NewClientWithUrl(&epay.Config{
|
||||
// PartnerID: "1096",
|
||||
// Key: "n08V9LpE8JffA3NPP893689u8p39NV9J",
|
||||
//}, "https://api.lempay.org")
|
||||
|
||||
var client, _ = epay.NewClientWithUrl(&epay.Config{
|
||||
PartnerID: "1064",
|
||||
Key: "nqrrZ5RjR86mKP8rKkyrOY5Pg8NmYfKR",
|
||||
}, "https://pay.yunjuw.cn")
|
||||
|
||||
func GetAmount(id int, count float64, topUpCode string) float64 {
|
||||
amount := count * 1.5
|
||||
if topUpCode != "" {
|
||||
if topUpCode == "nekoapi" {
|
||||
if id == 89 {
|
||||
amount = count * 0.8
|
||||
} else if id == 105 || id == 107 {
|
||||
amount = count * 1.2
|
||||
} else if id == 1 {
|
||||
amount = count * 1
|
||||
} else if id == 98 {
|
||||
amount = count * 1.1
|
||||
}
|
||||
}
|
||||
func GetEpayClient() *epay.Client {
|
||||
if common.PayAddress == "" || common.EpayId == "" || common.EpayKey == "" {
|
||||
return nil
|
||||
}
|
||||
withUrl, err := epay.NewClientWithUrl(&epay.Config{
|
||||
PartnerID: common.EpayId,
|
||||
Key: common.EpayKey,
|
||||
}, common.PayAddress)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return withUrl
|
||||
}
|
||||
|
||||
func GetAmount(count float64) float64 {
|
||||
// 别问为什么用float64,问就是这么点钱没必要
|
||||
amount := count * float64(common.Price)
|
||||
return amount
|
||||
}
|
||||
|
||||
@@ -60,38 +52,24 @@ func RequestEpay(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
id := c.GetInt("id")
|
||||
amount := GetAmount(id, float64(req.Amount), req.TopUpCode)
|
||||
if id != 1 {
|
||||
if req.Amount < 10 {
|
||||
c.JSON(200, gin.H{"message": "最小充值10元", "data": amount, "count": 10})
|
||||
return
|
||||
}
|
||||
}
|
||||
amount := GetAmount(float64(req.Amount))
|
||||
|
||||
if req.PaymentMethod == "zfb" {
|
||||
if amount > 2000 {
|
||||
c.JSON(200, gin.H{"message": "支付宝最大充值2000元", "data": amount, "count": 2000})
|
||||
return
|
||||
}
|
||||
req.PaymentMethod = "alipay"
|
||||
}
|
||||
if req.PaymentMethod == "wx" {
|
||||
if amount > 2000 {
|
||||
c.JSON(200, gin.H{"message": "微信最大充值2000元", "data": amount, "count": 2000})
|
||||
return
|
||||
}
|
||||
req.PaymentMethod = "wxpay"
|
||||
}
|
||||
|
||||
returnUrl, _ := url.Parse("https://nekoapi.com/log")
|
||||
notifyUrl, _ := url.Parse("https://nekoapi.com/api/user/epay/notify")
|
||||
returnUrl, _ := url.Parse(common.ServerAddress + "/log")
|
||||
notifyUrl, _ := url.Parse(common.ServerAddress + "/api/user/epay/notify")
|
||||
tradeNo := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
payMoney := amount
|
||||
//if payMoney < 400 {
|
||||
// payMoney = amount * 0.99
|
||||
// if amount-payMoney > 2 {
|
||||
// payMoney = amount - 2
|
||||
// }
|
||||
//}
|
||||
client := GetEpayClient()
|
||||
if client == nil {
|
||||
c.JSON(200, gin.H{"message": "error", "data": "当前管理员未配置支付信息"})
|
||||
return
|
||||
}
|
||||
uri, params, err := client.Purchase(&epay.PurchaseArgs{
|
||||
Type: epay.PurchaseType(req.PaymentMethod),
|
||||
ServiceTradeNo: "A" + tradeNo,
|
||||
@@ -126,6 +104,14 @@ func EpayNotify(c *gin.Context) {
|
||||
r[t] = c.Request.URL.Query().Get(t)
|
||||
return r
|
||||
}, map[string]string{})
|
||||
client := GetEpayClient()
|
||||
if client == nil {
|
||||
log.Println("易支付回调失败 未找到配置信息")
|
||||
_, err := c.Writer.Write([]byte("fail"))
|
||||
if err != nil {
|
||||
log.Println("易支付回调写入失败")
|
||||
}
|
||||
}
|
||||
verifyInfo, err := client.Verify(params)
|
||||
if err == nil && verifyInfo.VerifyStatus {
|
||||
_, err := c.Writer.Write([]byte("success"))
|
||||
@@ -168,20 +154,9 @@ func RequestAmount(c *gin.Context) {
|
||||
var req AmountRequest
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
c.JSON(200, gin.H{"message": err.Error(), "data": 10})
|
||||
c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
|
||||
return
|
||||
}
|
||||
id := c.GetInt("id")
|
||||
if id != 1 {
|
||||
if req.Amount < 10 {
|
||||
c.JSON(200, gin.H{"message": "最小充值10刀", "data": GetAmount(id, 10, req.TopUpCode), "count": 10})
|
||||
return
|
||||
}
|
||||
//if req.Amount > 1500 {
|
||||
// c.JSON(200, gin.H{"message": "最大充值1000刀", "data": GetAmount(id, 1000, req.TopUpCode), "count": 1500})
|
||||
// return
|
||||
//}
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{"message": "success", "data": GetAmount(id, float64(req.Amount), req.TopUpCode)})
|
||||
c.JSON(200, gin.H{"message": "success", "data": GetAmount(float64(req.Amount))})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user