feat: alipay config and Initial
This commit is contained in:
+13
-2
@@ -28,5 +28,16 @@ jwt:
|
||||
# 邮件服务
|
||||
mail:
|
||||
smtp: smtp.qq.com
|
||||
secret: zxbxswmaccpfdaes
|
||||
sender: 1933757688@qq.com
|
||||
secret: dhsepilzlvoaceij
|
||||
sender: 1655064994@qq.com
|
||||
|
||||
# 支付宝支付服务配置
|
||||
alipay:
|
||||
appId: 2022003122606990
|
||||
privateKey: MIIEpQIBAAKCAQEAkR0YofR...2sDd6uIy9rkpk8azj/rLmetW5r+tqTZgxcPWKeSz4=
|
||||
appPublicCert: /home/ubuntu/crm/cert/appPublicCert.crt
|
||||
alipayRootCert: /home/ubuntu/crm/cert/alipayRootCert.crt
|
||||
alipayPublicCert: /home/ubuntu/crm/cert/alipayPublicCert.crt
|
||||
returnURL: http://127.0.0.1:8000/api/subscribe/callback
|
||||
notifyURL: http://127.0.0.1:8000/api/subscribe/notify
|
||||
paySuccessURL: http://127.0.0.1:8060/#/subscribe
|
||||
|
||||
@@ -7,6 +7,7 @@ type Config struct {
|
||||
Redis Redis `mapstructure:"redis"`
|
||||
Jwt Jwt `mapstructure:"jwt"`
|
||||
Mail Mail `mapstructure:"mail"`
|
||||
Alipay Alipay `mapstructure:"alipay"`
|
||||
}
|
||||
|
||||
// 服务启动端口号配置
|
||||
@@ -46,3 +47,15 @@ type Mail struct {
|
||||
Secret string `mapstructure:"secret"`
|
||||
Sender string `mapstructure:"sender"`
|
||||
}
|
||||
|
||||
// 支付宝支付服务配置
|
||||
type Alipay struct {
|
||||
AppId string `mapstructure:"appId"`
|
||||
PrivateKey string `mapstructure:"privateKey"`
|
||||
AppPublicCert string `mapstructure:"appPublicCert"`
|
||||
AlipayRootCert string `mapstructure:"alipayRootCert"`
|
||||
AlipayPublicCert string `mapstructure:"alipayPublicCert"`
|
||||
ReturnURL string `mapstructure:"returnURL"`
|
||||
NotifyURL string `mapstructure:"notifyURL"`
|
||||
PaySuccessURL string `mapstructure:"paySuccessURL"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"crm/config"
|
||||
|
||||
"github.com/go-redis/redis/v9"
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -11,4 +12,5 @@ var (
|
||||
Config config.Config
|
||||
Db *gorm.DB
|
||||
Rdb *redis.Client
|
||||
Alipay *alipay.Client
|
||||
)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"crm/global"
|
||||
"log"
|
||||
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
)
|
||||
|
||||
func Alipay() {
|
||||
var err error
|
||||
appId := global.Config.Alipay.AppId
|
||||
privateKey := global.Config.Alipay.PrivateKey
|
||||
global.Alipay, err = alipay.New(appId, privateKey, false);
|
||||
if err != nil {
|
||||
log.Println("初始化支付宝支付服务失败", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 加载支付宝证书
|
||||
if err = global.Alipay.LoadAppPublicCertFromFile(global.Config.Alipay.AppPublicCert); err != nil {
|
||||
log.Println("加载证书发生错误", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = global.Alipay.LoadAliPayRootCertFromFile(global.Config.Alipay.AlipayRootCert); err != nil {
|
||||
log.Println("加载证书发生错误", err)
|
||||
return
|
||||
}
|
||||
if err = global.Alipay.LoadAliPayPublicCertFromFile(global.Config.Alipay.AlipayPublicCert); err != nil {
|
||||
log.Println("加载证书发生错误", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,6 @@ func Run() {
|
||||
LoadConfig()
|
||||
Mysql()
|
||||
Redis()
|
||||
Alipay()
|
||||
Router()
|
||||
}
|
||||
Reference in New Issue
Block a user