// 功能描述:充值限额、渠道配置就绪状态及已发布充值协议;版本:1.0.0。 package common import ( "os" "git.apinb.com/bsm-sdk/core/infra" "git.apinb.com/heqiapp/platforms/backend/api/internal/config" "git.apinb.com/heqiapp/platforms/backend/api/internal/impl" "git.apinb.com/heqiapp/platforms/backend/api/internal/models" "github.com/gin-gonic/gin" "gorm.io/gorm" ) // rechargeFileReady 仅检查渠道配置文件是否存在,不读取或返回私钥内容。 func rechargeFileReady(path string) bool { if path == "" { return false } info, err := os.Stat(path) return err == nil && !info.IsDir() } // GetRechargeOptions 不提供Mock支付,不将配置存在等同于渠道支付一定成功。 func GetRechargeOptions(client string) gin.HandlerFunc { return func(ctx *gin.Context) { if _, ok := currentOwner(ctx, client); !ok { return } ali, wx := config.Spec.Payment.Alipay, config.Spec.Payment.Wechat alipayReady := ali.Enabled && ali.AppID != "" && ali.NotifyURL != "" && rechargeFileReady(ali.PrivateKeyPath) && rechargeFileReady(ali.AppPublicCertPath) && rechargeFileReady(ali.AlipayPublicCertPath) && rechargeFileReady(ali.AlipayRootCertPath) wechatReady := wx.Enabled && wx.MerchantID != "" && wx.MerchantCertificateSerial != "" && len(wx.APIv3Key) == 32 && wx.AppAppID != "" && wx.NotifyURL != "" && rechargeFileReady(wx.MerchantPrivateKeyPath) response := gin.H{"min_amount": 1, "max_amount": config.Spec.Global.ManualRechargeMaxAmount, "channels": []gin.H{{"channel": "wechat", "app": wechatReady, "wap": false}, {"channel": "alipay", "app": alipayReady, "wap": alipayReady}}} var agreement models.CmsContent err := impl.DBService.Where("content_type = ? AND title = ? AND publish_status = ? AND status = ?", "agreement", "充值协议", "published", StatusEnable).Order("version_no desc, id desc").First(&agreement).Error if err != nil && err != gorm.ErrRecordNotFound { infra.Response.Error(ctx, err) return } if err == nil && agreement.Body != "" { response["agreement"] = gin.H{"identity": agreement.Identity, "version": agreement.VersionNo, "title": agreement.Title, "body": agreement.Body} } infra.Response.Success(ctx, response) } }