Browse Source

update

master
shenjiachi 1 day ago
parent
commit
adec9cd469
8 changed files with 84 additions and 15 deletions
  1. +51
    -2
      app/hdl/hdl_wallet.go
  2. +0
    -4
      app/md/md.wallet.go
  3. +5
    -5
      app/router/router.go
  4. +24
    -0
      app/utils/rsa.go
  5. +1
    -1
      docs/docs.go
  6. +1
    -1
      docs/swagger.json
  7. +1
    -1
      docs/swagger.yaml
  8. +1
    -1
      go.mod

+ 51
- 2
app/hdl/hdl_wallet.go View File

@@ -11,6 +11,7 @@ import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
@@ -19,6 +20,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-pay/gopay"
alipay2 "github.com/go-pay/gopay/alipay"
"github.com/jinzhu/copier"
"time"
)
@@ -400,7 +402,7 @@ func GetWithdrawCondition(c *gin.Context) {
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Success 200 {string} "Url"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/wallet/withdraw/launchBindAlipay [POST]
// @Router /api/v1/wallet/withdraw/launchBindAlipay [GET]
func LaunchBindAlipayAccount(c *gin.Context) {
client, err := alipay.InitAlipay(nil)
if err != nil {
@@ -410,7 +412,54 @@ func LaunchBindAlipayAccount(c *gin.Context) {
appId := client.AppId
scope := "auth_user"

resUrl := fmt.Sprintf("https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=%s&scope=%s&state=init", appId, scope)
redisConn := cache.GetPool().Get()
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
sysCfgs, err := sysCfgDb.SysCfgGetAll()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if sysCfgs == nil {
e.OutErr(c, e.ERR_CFG_CACHE, nil)
return
}

cfgMap := make(map[string]string, len(*sysCfgs))
for _, cfg := range *sysCfgs {
cfgMap[cfg.Key] = cfg.Val
}
targetId := utils.UUIDHexString()

alipayPrivateKey := cfgMap[enum2.AlipayPrivateKey]
pid := cfgMap[enum2.AlipayPid]
bm := make(gopay.BodyMap)
bm.Set("apiname", "com.alipay.account.auth")
bm.Set("app_id", appId)
bm.Set("app_name", "mc")
bm.Set("auth_type", "AUTHACCOUNT")
bm.Set("biz_type", "openservice")
bm.Set("pid", pid)
bm.Set("product_id", "APP_FAST_LOGIN")
bm.Set("scope", scope)
bm.Set("sign_type", "RSA2")
bm.Set("method", "alipay.open.auth.sdk.code.get")
bm.Set("target_id", targetId)
privateKey, err := utils.StringToPrivateKey(alipayPrivateKey)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
sign, err := alipay2.GetRsaSign(bm, alipay2.RSA2, privateKey)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

resUrl := fmt.Sprintf("apiname=com.alipay.account.auth&app_id=%s&app_name=mc&"+
"auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get"+
"&pid=%s&product_id=APP_FAST_LOGIN&scosspe=%s&sign_type=RSA2&"+
"target_id=%s&sign=%s", appId, pid, scope, targetId, sign)

e.OutSuc(c, resUrl, nil)
}



+ 0
- 4
app/md/md.wallet.go View File

@@ -40,10 +40,6 @@ type GetWithdrawConditionResp struct {
NotWithdrawReason string `json:"not_withdraw_reason"` // 不能提现原因
}

type LaunchBindAlipayAccountReq struct {
RedirectUri string `json:"redirect_uri"` // 回调页面,是经过转义的 URL 链接(url 必须以 HTTP 或者 HTTPS 开头)
}

type BindAlipayAccountReq struct {
AuthCode string `json:"auth_code"` // 支付宝回调的临时授权码
}


+ 5
- 5
app/router/router.go View File

@@ -135,11 +135,11 @@ func route(r *gin.RouterGroup) {
rWallet.GET("/amountFlow", hdl.GetAmountFlow) // 余额流水
rWithdraw := rWallet.Group("/withdraw")
{
rWithdraw.GET("/index", hdl.WithdrawGetAmount) // 查询余额
rWithdraw.POST("/apply", hdl.WithdrawApply) // 发起提现申请
rWithdraw.GET("/condition", hdl.GetWithdrawCondition) // 获取提现条件
rWithdraw.POST("/launchBindAlipay", hdl.LaunchBindAlipayAccount) // 支付宝发起绑定请求获得 url
rWithdraw.POST("/bindAlipay", hdl.BindAlipayAccount) // 绑定支付宝
rWithdraw.GET("/index", hdl.WithdrawGetAmount) // 查询余额
rWithdraw.POST("/apply", hdl.WithdrawApply) // 发起提现申请
rWithdraw.GET("/condition", hdl.GetWithdrawCondition) // 获取提现条件
rWithdraw.GET("/launchBindAlipay", hdl.LaunchBindAlipayAccount) // 支付宝发起绑定请求获得 url
rWithdraw.POST("/bindAlipay", hdl.BindAlipayAccount) // 绑定支付宝
rWithdraw.POST("/bindWxPay", hdl.BindWxPayAccount)
}
}


+ 24
- 0
app/utils/rsa.go View File

@@ -5,6 +5,7 @@ import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"errors"
"fmt"
@@ -168,3 +169,26 @@ func OpensslPemGetPublic(pathOrString string) (interface{}, error) {
fmt.Printf("Got a %T, with remaining data: %q", pub, rest)
return pub, nil
}

// StringToPrivateKey 字符串变为私钥
func StringToPrivateKey(base64Str string) (*rsa.PrivateKey, error) {
// Base64解码以获取DER数据
derData, err := base64.StdEncoding.DecodeString(base64Str)
if err != nil {
return nil, fmt.Errorf("base64 decode failed: %v", err)
}

// 解析DER数据以获取私钥
privateKey, err := x509.ParsePKCS8PrivateKey(derData)
if err != nil {
return nil, fmt.Errorf("failed to parse private key: %v", err)
}

// 类型断言以确保privateKey是*rsa.PrivateKey类型
rsaPrivateKey, ok := privateKey.(*rsa.PrivateKey)
if !ok {
return nil, fmt.Errorf("private key is not of type *rsa.PrivateKey")
}

return rsaPrivateKey, nil
}

+ 1
- 1
docs/docs.go View File

@@ -2952,7 +2952,7 @@ const docTemplate = `{
}
},
"/api/v1/wallet/withdraw/launchBindAlipay": {
"post": {
"get": {
"description": "发起绑定支付宝获得URL",
"consumes": [
"application/json"


+ 1
- 1
docs/swagger.json View File

@@ -2946,7 +2946,7 @@
}
},
"/api/v1/wallet/withdraw/launchBindAlipay": {
"post": {
"get": {
"description": "发起绑定支付宝获得URL",
"consumes": [
"application/json"


+ 1
- 1
docs/swagger.yaml View File

@@ -3360,7 +3360,7 @@ paths:
tags:
- 钱包
/api/v1/wallet/withdraw/launchBindAlipay:
post:
get:
consumes:
- application/json
description: 发起绑定支付宝获得URL


+ 1
- 1
go.mod View File

@@ -33,7 +33,7 @@ require (

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241203101237-e13f870d5c93
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241202080915-050246e21702
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241203133321-2e47add298ab
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible


Loading…
Cancel
Save