parent
fb24d33479
commit
7a20e95ee1
@ -0,0 +1,16 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var app App
|
||||
|
||||
func TestIp(t *testing.T) {
|
||||
t.Log(net.ParseIP("61.241.55.180").To4())
|
||||
t.Log(net.ParseIP("240e:3b4:38e4:3295:7093:af6c:e545:f2e9").To16())
|
||||
t.Log(app.V4db.Find("61.241.55.180"))
|
||||
t.Log(app.V6db.Find("240e:3b4:38e4:3295:7093:af6c:e545:f2e9"))
|
||||
t.Log(app.V4Region.MemorySearch("61.241.55.180"))
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"gopkg.in/dtapps/go-library.v3/utils/gotime"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WechatAccessTokenDbModel struct {
|
||||
ID int64 `json:"id"`
|
||||
AppID string `json:"app_id"`
|
||||
AppSecret string `json:"app_secret"`
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ExpiresTime string `json:"expires_time"`
|
||||
CreateTime time.Time `gorm:"autoCreateTime" json:"-"`
|
||||
}
|
||||
|
||||
func (m *WechatAccessTokenDbModel) TableName() string {
|
||||
return "wechat_access_token"
|
||||
}
|
||||
|
||||
func (app *App) wechatAccessTokenModelTake() (result WechatAccessTokenDbModel) {
|
||||
app.Db.Where("app_id = ?", app.AppId).Where("expires_time > ?", gotime.Current().Format()).Take(&result)
|
||||
return result
|
||||
}
|
||||
|
||||
func (app *App) GetAccessTokenDb() string {
|
||||
wat := app.wechatAccessTokenModelTake()
|
||||
if wat.AccessToken != "" {
|
||||
return wat.AccessToken
|
||||
} else {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
if token.AccessToken == "" {
|
||||
return ""
|
||||
} else {
|
||||
// 创建
|
||||
app.Db.Create(&WechatAccessTokenDbModel{
|
||||
AppID: app.AppId,
|
||||
AppSecret: app.AppSecret,
|
||||
AccessToken: token.AccessToken,
|
||||
ExpiresIn: token.ExpiresIn,
|
||||
ExpiresTime: gotime.Current().AfterSeconds(7000).Format(),
|
||||
})
|
||||
return token.AccessToken
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/dtapps/go-library.v3/utils/goredis"
|
||||
)
|
||||
|
||||
func (app *App) GetAccessTokenRDb() string {
|
||||
cacheName := fmt.Sprintf("wechat_access_token:%v", app.AppId)
|
||||
redis := goredis.App{
|
||||
Rdb: app.RDb,
|
||||
}
|
||||
newCache := redis.NewSimpleStringCache(redis.NewStringOperation(), 7000)
|
||||
newCache.DBGetter = func() string {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
return token.AccessToken
|
||||
}
|
||||
return newCache.GetCache(cacheName)
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package wechatmp
|
||||
|
||||
import (
|
||||
"gopkg.in/dtapps/go-library.v3/utils/gotime"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WechatAccessTokenDbModel struct {
|
||||
ID int64 `json:"id"`
|
||||
AppID string `json:"app_id"`
|
||||
AppSecret string `json:"app_secret"`
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ExpiresTime string `json:"expires_time"`
|
||||
CreateTime time.Time `gorm:"autoCreateTime" json:"-"`
|
||||
}
|
||||
|
||||
func (m *WechatAccessTokenDbModel) TableName() string {
|
||||
return "wechat_access_token"
|
||||
}
|
||||
|
||||
func (app *App) wechatAccessTokenModelTake() (result WechatAccessTokenDbModel) {
|
||||
app.Db.Where("app_id = ?", app.AppId).Where("expires_time > ?", gotime.Current().Format()).Take(&result)
|
||||
return result
|
||||
}
|
||||
|
||||
func (app *App) GetAccessTokenDb() string {
|
||||
wat := app.wechatAccessTokenModelTake()
|
||||
if wat.AccessToken != "" {
|
||||
return wat.AccessToken
|
||||
} else {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
if token.AccessToken == "" {
|
||||
return ""
|
||||
} else {
|
||||
// 创建
|
||||
app.Db.Create(&WechatAccessTokenDbModel{
|
||||
AppID: app.AppId,
|
||||
AppSecret: app.AppSecret,
|
||||
AccessToken: token.AccessToken,
|
||||
ExpiresIn: token.ExpiresIn,
|
||||
ExpiresTime: gotime.Current().AfterSeconds(7000).Format(),
|
||||
})
|
||||
return token.AccessToken
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package wechatmp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/dtapps/go-library.v3/utils/goredis"
|
||||
)
|
||||
|
||||
func (app *App) GetAccessTokenRDb() string {
|
||||
cacheName := fmt.Sprintf("wechat_access_token:%v", app.AppId)
|
||||
redis := goredis.App{
|
||||
Rdb: app.RDb,
|
||||
}
|
||||
newCache := redis.NewSimpleStringCache(redis.NewStringOperation(), 7000)
|
||||
newCache.DBGetter = func() string {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
return token.AccessToken
|
||||
}
|
||||
return newCache.GetCache(cacheName)
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"gopkg.in/dtapps/go-library.v3/utils/gotime"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WechatAccessTokenDbModel struct {
|
||||
ID int64 `json:"id"`
|
||||
AppID string `json:"app_id"`
|
||||
AppSecret string `json:"app_secret"`
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ExpiresTime string `json:"expires_time"`
|
||||
CreateTime time.Time `gorm:"autoCreateTime" json:"-"`
|
||||
}
|
||||
|
||||
func (m *WechatAccessTokenDbModel) TableName() string {
|
||||
return "wechat_access_token"
|
||||
}
|
||||
|
||||
func (app *App) wechatAccessTokenModelTake() (result WechatAccessTokenDbModel) {
|
||||
app.Db.Where("app_id = ?", app.AppId).Where("expires_time > ?", gotime.Current().Format()).Take(&result)
|
||||
return result
|
||||
}
|
||||
|
||||
func (app *App) GetAccessTokenDb() string {
|
||||
wat := app.wechatAccessTokenModelTake()
|
||||
if wat.AccessToken != "" {
|
||||
return wat.AccessToken
|
||||
} else {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
if token.AccessToken == "" {
|
||||
return ""
|
||||
} else {
|
||||
// 创建
|
||||
app.Db.Create(&WechatAccessTokenDbModel{
|
||||
AppID: app.AppId,
|
||||
AppSecret: app.AppSecret,
|
||||
AccessToken: token.AccessToken,
|
||||
ExpiresIn: token.ExpiresIn,
|
||||
ExpiresTime: gotime.Current().AfterSeconds(7000).Format(),
|
||||
})
|
||||
return token.AccessToken
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/dtapps/go-library.v3/utils/goredis"
|
||||
)
|
||||
|
||||
func (app *App) GetAccessTokenRDb() string {
|
||||
cacheName := fmt.Sprintf("wechat_access_token:%v", app.AppId)
|
||||
redis := goredis.App{
|
||||
Rdb: app.RDb,
|
||||
}
|
||||
newCache := redis.NewSimpleStringCache(redis.NewStringOperation(), 7000)
|
||||
newCache.DBGetter = func() string {
|
||||
token, _ := app.AuthGetAccessToken()
|
||||
return token.AccessToken
|
||||
}
|
||||
return newCache.GetCache(cacheName)
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package wechatunion
|
||||
|
||||
import (
|
||||
"gopkg.in/dtapps/go-library.v3/utils/gotime"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WechatAccessTokenDbModel struct {
|
||||
ID int64 `json:"id"`
|
||||
AppID string `json:"app_id"`
|
||||
AppSecret string `json:"app_secret"`
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ExpiresTime string `json:"expires_time"`
|
||||
CreateTime time.Time `gorm:"autoCreateTime" json:"-"`
|
||||
}
|
||||
|
||||
func (m *WechatAccessTokenDbModel) TableName() string {
|
||||
return "wechat_access_token"
|
||||
}
|
||||
|
||||
func (app *App) wechatAccessTokenModelTake() (result WechatAccessTokenDbModel) {
|
||||
app.Db.Where("app_id = ?", app.AppId).Where("expires_time > ?", gotime.Current().Format()).Take(&result)
|
||||
return result
|
||||
}
|
||||
|
||||
func (app *App) GetAccessTokenDb() string {
|
||||
wat := app.wechatAccessTokenModelTake()
|
||||
if wat.AccessToken != "" {
|
||||
return wat.AccessToken
|
||||
} else {
|
||||
token := app.AuthGetAccessToken()
|
||||
if token.Result.AccessToken == "" {
|
||||
return ""
|
||||
} else {
|
||||
// 创建
|
||||
app.Db.Create(&WechatAccessTokenDbModel{
|
||||
AppID: app.AppId,
|
||||
AppSecret: app.AppSecret,
|
||||
AccessToken: token.Result.AccessToken,
|
||||
ExpiresIn: token.Result.ExpiresIn,
|
||||
ExpiresTime: gotime.Current().AfterSeconds(7000).Format(),
|
||||
})
|
||||
return token.Result.AccessToken
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package wechatunion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/dtapps/go-library.v3/utils/goredis"
|
||||
)
|
||||
|
||||
func (app *App) GetAccessTokenRDb() string {
|
||||
cacheName := fmt.Sprintf("wechat_access_token:%v", app.AppId)
|
||||
redis := goredis.App{
|
||||
Rdb: app.RDb,
|
||||
}
|
||||
newCache := redis.NewSimpleStringCache(redis.NewStringOperation(), 7000)
|
||||
newCache.DBGetter = func() string {
|
||||
token := app.AuthGetAccessToken()
|
||||
return token.Result.AccessToken
|
||||
}
|
||||
return newCache.GetCache(cacheName)
|
||||
}
|
Loading…
Reference in new issue