iedc-go/example/app/init.go
2022-04-29 03:08:32 +08:00

65 lines
1.6 KiB
Go

package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/ddsms"
"github.com/silenceper/wechat/v2"
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/miniprogram"
"github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/silenceper/wechat/v2/officialaccount"
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
"time"
)
// Project 管理端项目
var Project = Proj{
"lxcx": Lxcx,
"wechat": Wechat,
"websocket": WebsocketCtr,
}
var weixin *wechat.Wechat //微信登录实例
var miniProgram *miniprogram.MiniProgram
var h5Program *officialaccount.OfficialAccount
func InitApp(app *Application) {
weixin = wechat.NewWechat()
memory := cache.NewMemory()
memoryMini := cache.NewMemory()
cfg := &config.Config{
AppID: app.Config.GetString("wechatMiniAppID"),
AppSecret: app.Config.GetString("wechatMiniAppSecret"),
//Token: "xxx",
//EncodingAESKey: "xxxx",
Cache: memoryMini,
}
h5cfg := &h5config.Config{
AppID: app.Config.GetString("wechatAppID"),
AppSecret: app.Config.GetString("wechatAppSecret"),
//Token: "xxx",
//EncodingAESKey: "xxxx",
Cache: memory,
}
miniProgram = weixin.GetMiniProgram(cfg)
h5Program = weixin.GetOfficialAccount(h5cfg)
ddsms.DDY.Init(app.Config.GetString("smsKey"))
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}