Ai
4 Star 9 Fork 6

Gitee 极速下载/allpay

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/runthinker/allpay
克隆/下载
datainit.go 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
heyuehua 提交于 2018-12-17 16:03 +08:00 . create
package model
import (
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"os"
"encoding/json"
"log"
"github.com/runthinker/allpay/wxpay"
)
type (
WxConfig struct {
Apikey string `json:"apikey"`
Appid string `json:"appid"`
MpSecret string `json:"mp_secret"`
MchId string `json:"mch_id"`
Certfilepath string `json:"certfilepath"`
NotifyUrl string `json:"notify_url"`
SandBoxSignkey string `json:"sand_box_signkey"`
}
AliConfig struct {
MchPrivatekey string `json:"mch_privatekey"`
AliPublickey string `json:"ali_publickey"`
AppId string `json:"app_id"`
ProviderId string `json:"provider_id"`
NotifyUrl string `json:"notify_url"`
}
DbConfig struct {
Dbpath string `json:"dbpath"`
Sqldebug bool `json:"sqldebug"`
}
AllPayConfig struct {
WxPay WxConfig
AliPay AliConfig
Db DbConfig
}
)
var gdb *gorm.DB
var ApConfig *AllPayConfig
func init() {
ApConfig = &AllPayConfig{
WxConfig{
Apikey: "",
Appid: "",
MpSecret: "",
MchId: "",
Certfilepath: "",
NotifyUrl: "http://test.xxxx.com/payapi/notify/wxpay",
},
AliConfig{
MchPrivatekey: ``,
AliPublickey: ``,
AppId: "",
ProviderId: "",
NotifyUrl: "http://test.xxxx.com/payapi/notify/alipay",
},
DbConfig{"root:123456@/allpay?charset=utf8&parseTime=True&loc=Local",true},
}
file,err := os.Open("config.json")
defer file.Close()
if err == nil {
err = json.NewDecoder(file).Decode(&ApConfig)
if err != nil {
log.Fatalln(err.Error())
}
}
if signkey := wxpay.GetSandBoxSignKey(ApConfig.WxPay.MchId,ApConfig.WxPay.Apikey); signkey != "" {
ApConfig.WxPay.SandBoxSignkey = signkey
log.Println("SandboxSignkey:", ApConfig.WxPay.SandBoxSignkey)
}
gdb, err = gorm.Open("mysql",ApConfig.Db.Dbpath)
if err != nil {
log.Fatalf("Fail to create engine: %v\n", err)
}
if ApConfig.Db.Sqldebug {
gdb.LogMode(true)
}
gdb.SingularTable(true)
gdb.DB().SetMaxIdleConns(20)
gdb.DB().SetMaxIdleConns(2)
if err := gdb.DB().Ping();err != nil {
log.Fatalln(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/allpay.git
git@gitee.com:mirrors/allpay.git
mirrors
allpay
allpay
1bfa26d3e71c

搜索帮助