hotime/example/app/init.go

63 lines
1.6 KiB
Go
Raw Normal View History

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